#306 Add permission manager to command service
- Inject permission manager into command service explicitly via constructor - Change command mapper to only care about generating FoundCommandResult objects, and command handler to worry about dealing with it later on
This commit is contained in:
@@ -14,6 +14,7 @@ import static fr.xephi.authme.command.FoundResultStatus.SUCCESS;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyListOf;
|
||||
@@ -89,7 +90,9 @@ public class CommandHandlerTest {
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
verify(serviceMock).outputMappingError(eq(sender), any(FoundCommandResult.class));
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender).sendMessage(captor.capture());
|
||||
assertThat(captor.getValue(), containsString("don't have permission"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Before;
|
||||
@@ -43,7 +41,7 @@ public class CommandMapperTest {
|
||||
@Before
|
||||
public void setUpMocks() {
|
||||
permissionsManagerMock = mock(PermissionsManager.class);
|
||||
mapper = new CommandMapper(commands, mock(Messages.class), permissionsManagerMock, mock(HelpProvider.class));
|
||||
mapper = new CommandMapper(commands, permissionsManagerMock);
|
||||
}
|
||||
|
||||
// -----------
|
||||
|
||||
@@ -39,6 +39,7 @@ public class CommandServiceTest {
|
||||
private Messages messages;
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private CommandService commandService;
|
||||
private PermissionsManager permissionsManager;
|
||||
private NewSetting settings;
|
||||
|
||||
@Before
|
||||
@@ -48,8 +49,10 @@ public class CommandServiceTest {
|
||||
helpProvider = mock(HelpProvider.class);
|
||||
messages = mock(Messages.class);
|
||||
passwordSecurity = mock(PasswordSecurity.class);
|
||||
permissionsManager = mock(PermissionsManager.class);
|
||||
settings = mock(NewSetting.class);
|
||||
commandService = new CommandService(authMe, commandMapper, helpProvider, messages, passwordSecurity, settings);
|
||||
commandService = new CommandService(
|
||||
authMe, commandMapper, helpProvider, messages, passwordSecurity, permissionsManager, settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,19 +95,6 @@ public class CommandServiceTest {
|
||||
verify(commandMapper).mapPartsToCommand(sender, commandParts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOutputMappingError() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
FoundCommandResult result = mock(FoundCommandResult.class);
|
||||
|
||||
// when
|
||||
commandService.outputMappingError(sender, result);
|
||||
|
||||
// then
|
||||
verify(commandMapper).outputStandardError(sender, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldRunTaskInAsync() {
|
||||
@@ -174,16 +164,11 @@ public class CommandServiceTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnPermissionsManager() {
|
||||
// given
|
||||
PermissionsManager manager = mock(PermissionsManager.class);
|
||||
given(authMe.getPermissionsManager()).willReturn(manager);
|
||||
|
||||
// when
|
||||
// given / when
|
||||
PermissionsManager result = commandService.getPermissionsManager();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(manager));
|
||||
verify(authMe).getPermissionsManager();
|
||||
assertThat(result, equalTo(permissionsManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user