#727 Remove CommandService from ExecutableCommand interface
(work in progress) - Inject CommandService like other classes instead of passing it as method parameter - Not solved: cyclic dependency CommandInitializer > ExecutableCommand > CommandService > CommandInitializer...
This commit is contained in:
@@ -47,7 +47,10 @@ public class CommandHandlerTest {
|
||||
private CommandHandler handler;
|
||||
|
||||
@Mock
|
||||
private CommandService serviceMock;
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandMapper commandMapper;
|
||||
|
||||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
@@ -66,17 +69,17 @@ public class CommandHandlerTest {
|
||||
ExecutableCommand executableCommand = mock(ExecutableCommand.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getExecutableCommand()).willReturn(executableCommand);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("Authme", "Login"), asList("myPass"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("Authme", "Login", "myPass"));
|
||||
|
||||
verify(executableCommand).executeCommand(eq(sender), captor.capture(), any(CommandService.class));
|
||||
verify(executableCommand).executeCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("myPass"));
|
||||
|
||||
// Ensure that no error message was issued to the command sender
|
||||
@@ -90,14 +93,14 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, NO_PERMISSION));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
verify(command, never()).getExecutableCommand();
|
||||
verify(sender).sendMessage(argThat(containsString("don't have permission")));
|
||||
@@ -110,7 +113,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(true);
|
||||
|
||||
@@ -118,7 +121,7 @@ public class CommandHandlerTest {
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@@ -134,7 +137,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(false);
|
||||
|
||||
@@ -142,7 +145,7 @@ public class CommandHandlerTest {
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@@ -158,14 +161,14 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, MISSING_BASE_COMMAND));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
verify(command, never()).getExecutableCommand();
|
||||
verify(sender).sendMessage(argThat(containsString("Failed to parse")));
|
||||
@@ -179,14 +182,14 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.01, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@@ -207,14 +210,14 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 1.0, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@@ -235,17 +238,17 @@ public class CommandHandlerTest {
|
||||
ExecutableCommand executableCommand = mock(ExecutableCommand.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getExecutableCommand()).willReturn(executableCommand);
|
||||
given(serviceMock.mapPartsToCommand(eq(sender), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(eq(sender), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("AuthMe", "LOGIN"), asList("testArg"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("AuthMe", "LOGIN", "testArg"));
|
||||
|
||||
verify(command.getExecutableCommand()).executeCommand(eq(sender), captor.capture(), eq(serviceMock));
|
||||
verify(command.getExecutableCommand()).executeCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("testArg"));
|
||||
|
||||
verify(sender, never()).sendMessage(anyString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -113,6 +114,12 @@ public class CommandUtilsTest {
|
||||
checkArgumentCount(command, 1, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandUtils.class);
|
||||
}
|
||||
|
||||
|
||||
private static void checkArgumentCount(CommandDescription command, int expectedMin, int expectedMax) {
|
||||
assertThat(CommandUtils.getMinNumberOfArguments(command), equalTo(expectedMin));
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), mock(CommandService.class));
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
@@ -42,7 +42,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
||||
// when
|
||||
command.executeCommand(player, arguments, service);
|
||||
command.executeCommand(player, arguments);
|
||||
|
||||
// then
|
||||
verify(player, times(1)).sendMessage("testarg2");
|
||||
@@ -55,7 +55,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandWithAlt command = new PlayerCommandWithAlt();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), mock(CommandService.class));
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender, times(1)).sendMessage(argThat(containsString("use /authme test <command> instead")));
|
||||
@@ -64,14 +64,14 @@ public class PlayerCommandTest {
|
||||
|
||||
private static class PlayerCommandImpl extends PlayerCommand {
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
player.sendMessage(arguments.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
private static class PlayerCommandWithAlt extends PlayerCommand {
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
throw new IllegalStateException("Should not be called");
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Arrays.asList("Toaster", "Pester"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -69,7 +69,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAuth("someuser")).willReturn(null);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -85,7 +85,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -101,7 +101,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -119,7 +119,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -134,7 +134,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -149,7 +149,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
@@ -24,10 +23,9 @@ public class AuthMeCommandTest {
|
||||
// given
|
||||
ExecutableCommand command = new AuthMeCommand();
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandService service = mock(CommandService.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String> emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
ArgumentCaptor<String> messagesCaptor = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
+5
-5
@@ -69,7 +69,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
new ValidationResult(MessageKey.PASSWORD_IS_USERNAME_ERROR));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("bobby", "Bobby"), service);
|
||||
command.executeCommand(sender, Arrays.asList("bobby", "Bobby"));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword("Bobby", "bobby");
|
||||
@@ -88,7 +88,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -113,7 +113,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -141,7 +141,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -168,7 +168,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(dataSource.updatePassword(auth)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -33,9 +32,6 @@ public class FirstSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToFirstSpawn() {
|
||||
// given
|
||||
@@ -44,7 +40,7 @@ public class FirstSpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).teleport(firstSpawn);
|
||||
@@ -58,7 +54,7 @@ public class FirstSpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).sendMessage(argThat(containsString("spawn has failed")));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.process.Management;
|
||||
@@ -43,9 +42,6 @@ public class ForceLoginCommandTest {
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectOfflinePlayer() {
|
||||
// given
|
||||
@@ -55,7 +51,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@@ -71,7 +67,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@@ -89,7 +85,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@@ -107,7 +103,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@@ -125,7 +121,7 @@ public class ForceLoginCommandTest {
|
||||
given(sender.getName()).willReturn(senderName);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(senderName);
|
||||
|
||||
@@ -31,9 +31,6 @@ public class GetEmailCommandTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@@ -42,9 +39,10 @@ public class GetEmailCommandTest {
|
||||
// given
|
||||
String user = "myTestUser";
|
||||
given(dataSource.getAuth(user)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(user), service);
|
||||
command.executeCommand(sender, Collections.singletonList(user));
|
||||
|
||||
// then
|
||||
verify(service).send(sender, MessageKey.UNKNOWN_USER);
|
||||
@@ -58,9 +56,10 @@ public class GetEmailCommandTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(email);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(user), service);
|
||||
command.executeCommand(sender, Collections.singletonList(user));
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString(email)));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,22 +30,18 @@ public class GetIpCommandTest {
|
||||
@InjectMocks
|
||||
private GetIpCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Test
|
||||
public void shouldGetIpOfPlayer() {
|
||||
// given
|
||||
given(bukkitService.getPlayerExact(anyString())).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("Testt"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("Testt"));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact("Testt");
|
||||
@@ -60,9 +55,10 @@ public class GetIpCommandTest {
|
||||
String ip = "123.34.56.88";
|
||||
Player player = mockPlayer(playerName, ip);
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
|
||||
@@ -29,6 +29,9 @@ import static org.mockito.Mockito.verify;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LastLoginCommandTest {
|
||||
|
||||
private static final long HOUR_IN_MSEC = 3600 * 1000;
|
||||
private static final long DAY_IN_MSEC = 24 * HOUR_IN_MSEC;
|
||||
|
||||
@InjectMocks
|
||||
private LastLoginCommand command;
|
||||
|
||||
@@ -38,20 +41,16 @@ public class LastLoginCommandTest {
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
private static final long HOUR_IN_MSEC = 3600 * 1000;
|
||||
private static final long DAY_IN_MSEC = 24 * HOUR_IN_MSEC;
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonExistentUser() {
|
||||
// given
|
||||
String player = "tester";
|
||||
given(dataSource.getAuth(player)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@@ -68,9 +67,10 @@ public class LastLoginCommandTest {
|
||||
given(auth.getLastLogin()).willReturn(lastLogin);
|
||||
given(auth.getIp()).willReturn("123.45.66.77");
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@@ -87,6 +87,7 @@ public class LastLoginCommandTest {
|
||||
public void shouldDisplayLastLoginOfCommandSender() {
|
||||
// given
|
||||
String name = "CommandSender";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
|
||||
long lastLogin = System.currentTimeMillis() -
|
||||
@@ -97,7 +98,7 @@ public class LastLoginCommandTest {
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(name);
|
||||
|
||||
+7
-6
@@ -35,8 +35,6 @@ public class PurgeLastPositionCommandTest {
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Test
|
||||
public void shouldPurgeLastPosOfUser() {
|
||||
@@ -44,9 +42,10 @@ public class PurgeLastPositionCommandTest {
|
||||
String player = "_Bobby";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@@ -64,7 +63,7 @@ public class PurgeLastPositionCommandTest {
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@@ -76,9 +75,10 @@ public class PurgeLastPositionCommandTest {
|
||||
public void shouldHandleNonExistentUser() {
|
||||
// given
|
||||
String name = "invalidPlayer";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(name), service);
|
||||
command.executeCommand(sender, Collections.singletonList(name));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(name);
|
||||
@@ -92,9 +92,10 @@ public class PurgeLastPositionCommandTest {
|
||||
PlayerAuth auth2 = mock(PlayerAuth.class);
|
||||
PlayerAuth auth3 = mock(PlayerAuth.class);
|
||||
given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3));
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("*"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("*"));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAllAuths();
|
||||
|
||||
+5
-5
@@ -71,7 +71,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword(password, user);
|
||||
@@ -89,7 +89,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -111,7 +111,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -136,7 +136,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@@ -163,7 +163,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
runSyncDelayedTask(bukkitService);
|
||||
|
||||
|
||||
@@ -50,6 +50,9 @@ public class ReloadCommandTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
@@ -66,17 +69,16 @@ public class ReloadCommandTest {
|
||||
public void shouldReload() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandService service = mock(CommandService.class);
|
||||
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
|
||||
given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
verify(initializer).performReloadOnServices();
|
||||
verify(service).send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
verify(commandService).send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +91,7 @@ public class ReloadCommandTest {
|
||||
given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
@@ -107,7 +109,7 @@ public class ReloadCommandTest {
|
||||
given(dataSource.getType()).willReturn(DataSourceType.SQLITE);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
|
||||
+2
-5
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -30,8 +29,6 @@ public class SetFirstSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldSetFirstSpawn() {
|
||||
@@ -42,7 +39,7 @@ public class SetFirstSpawnCommandTest {
|
||||
given(spawnLoader.setFirstSpawn(location)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setFirstSpawn(location);
|
||||
@@ -58,7 +55,7 @@ public class SetFirstSpawnCommandTest {
|
||||
given(spawnLoader.setFirstSpawn(location)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setFirstSpawn(location);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -30,8 +29,6 @@ public class SetSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldSetSpawn() {
|
||||
@@ -42,7 +39,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
@@ -58,7 +55,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -33,8 +32,6 @@ public class SpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToSpawn() {
|
||||
@@ -44,7 +41,7 @@ public class SpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).teleport(spawn);
|
||||
@@ -58,7 +55,7 @@ public class SpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).sendMessage(argThat(containsString("Spawn has failed")));
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("status: ACTIVE")));
|
||||
@@ -56,7 +56,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("on"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("on"));
|
||||
|
||||
// then
|
||||
verify(antiBot).overrideAntiBotStatus(true);
|
||||
@@ -69,7 +69,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("Off"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("Off"));
|
||||
|
||||
// then
|
||||
verify(antiBot).overrideAntiBotStatus(false);
|
||||
@@ -84,7 +84,7 @@ public class SwitchAntiBotCommandTest {
|
||||
given(service.mapPartsToCommand(sender, asList("authme", "antibot"))).willReturn(foundCommandResult);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("wrong"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("wrong"));
|
||||
|
||||
// then
|
||||
verify(antiBot, never()).overrideAntiBotStatus(anyBoolean());
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CaptchaCommandTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("123"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("123"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
@@ -59,7 +59,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.isCaptchaRequired(name)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("1234"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("1234"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.USAGE_LOGIN);
|
||||
@@ -78,7 +78,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.checkCode(name, captchaCode)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode), commandService);
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
|
||||
// then
|
||||
verify(captchaManager).isCaptchaRequired(name);
|
||||
@@ -102,7 +102,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.generateCode(name)).willReturn(newCode);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode), commandService);
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
|
||||
// then
|
||||
verify(captchaManager).isCaptchaRequired(name);
|
||||
|
||||
+4
-4
@@ -73,7 +73,7 @@ public class ChangePasswordCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
@@ -85,7 +85,7 @@ public class ChangePasswordCommandTest {
|
||||
CommandSender sender = initPlayerWithName("name", false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("pass", "pass"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("pass", "pass"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.NOT_LOGGED_IN);
|
||||
@@ -100,7 +100,7 @@ public class ChangePasswordCommandTest {
|
||||
.willReturn(new ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("tester", password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("tester", password));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword(password, "abc12");
|
||||
@@ -114,7 +114,7 @@ public class ChangePasswordCommandTest {
|
||||
given(validationService.validatePassword("abc123", "parker")).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("abc123", "abc123"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("abc123", "abc123"));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword("abc123", "parker");
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AddEmailCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@@ -55,7 +55,7 @@ public class AddEmailCommandTest {
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, email), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(email, email));
|
||||
|
||||
// then
|
||||
verify(management).performAddEmail(sender, email);
|
||||
@@ -69,7 +69,7 @@ public class AddEmailCommandTest {
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, "wrongConf"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(email, "wrongConf"));
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -30,9 +29,6 @@ public class ChangeEmailCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
@@ -40,7 +36,7 @@ public class ChangeEmailCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@@ -52,7 +48,7 @@ public class ChangeEmailCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("new.mail@example.org", "old_mail@example.org"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("new.mail@example.org", "old_mail@example.org"));
|
||||
|
||||
// then
|
||||
verify(management).performChangeEmail(sender, "new.mail@example.org", "old_mail@example.org");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -33,8 +32,6 @@ public class LoginCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
@@ -42,7 +39,7 @@ public class LoginCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@@ -55,7 +52,7 @@ public class LoginCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("password"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("password"));
|
||||
|
||||
// then
|
||||
verify(management).performLogin(eq(sender), eq("password"), eq(false));
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -33,13 +31,6 @@ public class LogoutCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Before
|
||||
public void initializeAuthMeMock() {
|
||||
commandService = mock(CommandService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
@@ -47,7 +38,7 @@ public class LogoutCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@@ -60,7 +51,7 @@ public class LogoutCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("password"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("password"));
|
||||
|
||||
// then
|
||||
verify(management).performLogout(sender);
|
||||
|
||||
+37
-25
@@ -49,8 +49,6 @@ public class RegisterCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private Player sender;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
@@ -70,7 +68,7 @@ public class RegisterCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
||||
@@ -81,21 +79,25 @@ public class RegisterCommandTest {
|
||||
public void shouldForwardToManagementForTwoFactor() {
|
||||
// given
|
||||
given(commandService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.TWO_FACTOR);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(management).performRegister(sender, "", "", true);
|
||||
verify(management).performRegister(player, "", "", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnErrorForEmptyArguments() {
|
||||
// given / when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -103,12 +105,13 @@ public class RegisterCommandTest {
|
||||
public void shouldReturnErrorForMissingConfirmation() {
|
||||
// given
|
||||
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("arrrr"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("arrrr"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -117,12 +120,13 @@ public class RegisterCommandTest {
|
||||
// given
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("test@example.org"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("test@example.org"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -132,12 +136,13 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("myMail@example.tld"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("no email address")));
|
||||
verify(player).sendMessage(argThat(containsString("no email address")));
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -150,13 +155,14 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, playerMail), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(commandService).send(sender, MessageKey.INVALID_EMAIL);
|
||||
verify(commandService).send(player, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -169,12 +175,13 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, "invalid"), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, "invalid"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -189,35 +196,40 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, playerMail), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(management).performRegister(eq(sender), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPasswordConfirmation() {
|
||||
// given
|
||||
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("myPass", "mypass"), commandService);
|
||||
command.executeCommand(player, Arrays.asList("myPass", "mypass"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
verify(commandService).send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformPasswordValidation() {
|
||||
// given / when
|
||||
command.executeCommand(sender, Collections.singletonList("myPass"), commandService);
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("myPass"));
|
||||
|
||||
// then
|
||||
verify(management).performRegister(sender, "myPass", "", true);
|
||||
verify(management).performRegister(player, "myPass", "", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.TestCommandsUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -66,4 +67,10 @@ public class CommandSyntaxHelperTest {
|
||||
assertThat(result, equalTo(ChatColor.WHITE + "/email" + ChatColor.YELLOW + " [player]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandSyntaxHelper.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user