Move most API of CommandParts to util classes
Gradual transition to removing CommandParts altogether. - Move logic from CommandParts to utils classes
This commit is contained in:
@@ -254,12 +254,12 @@ public class CommandInitializerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute label that a command defines. Note: Assumes that only the passed command might have
|
||||
* Get the absolute binding that a command defines. Note: Assumes that only the passed command can have
|
||||
* multiple labels; only considering the first label for all of the command's parents.
|
||||
*
|
||||
* @param command The command to verify
|
||||
* @param command The command to process
|
||||
*
|
||||
* @return The full command binding
|
||||
* @return List of all bindings that lead to the command
|
||||
*/
|
||||
private static List<String> getAbsoluteLabels(CommandDescription command) {
|
||||
String parentPath = "";
|
||||
|
||||
@@ -3,6 +3,7 @@ package fr.xephi.authme.command;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -27,7 +28,7 @@ public class CommandPartsTest {
|
||||
@Test
|
||||
public void shouldPrintEmptyStringForNoArguments() {
|
||||
// given
|
||||
CommandParts parts = new CommandParts();
|
||||
CommandParts parts = new CommandParts(Collections.EMPTY_LIST);
|
||||
|
||||
// when
|
||||
String str = parts.toString();
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -40,7 +42,7 @@ public class CaptchaCommandTest {
|
||||
ExecutableCommand command = new CaptchaCommand();
|
||||
|
||||
// when
|
||||
boolean result = command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
boolean result = command.executeCommand(sender, new CommandParts(Collections.EMPTY_LIST), new CommandParts(Collections.EMPTY_LIST));
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
@@ -56,7 +58,7 @@ public class CaptchaCommandTest {
|
||||
ExecutableCommand command = new CaptchaCommand();
|
||||
|
||||
// when
|
||||
boolean result = command.executeCommand(player, new CommandParts(), new CommandParts());
|
||||
boolean result = command.executeCommand(player, new CommandParts(Collections.EMPTY_LIST), new CommandParts(Collections.EMPTY_LIST));
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
|
||||
+9
-8
@@ -18,6 +18,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ChangePasswordCommandTest {
|
||||
CommandParts arguments = mock(CommandParts.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), arguments);
|
||||
command.executeCommand(sender, newParts(), arguments);
|
||||
|
||||
// then
|
||||
verify(arguments, never()).get(anyInt());
|
||||
@@ -72,7 +73,7 @@ public class ChangePasswordCommandTest {
|
||||
ChangePasswordCommand command = new ChangePasswordCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts("pass"));
|
||||
command.executeCommand(sender, newParts(), new CommandParts("pass"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.NOT_LOGGED_IN);
|
||||
@@ -86,7 +87,7 @@ public class ChangePasswordCommandTest {
|
||||
ChangePasswordCommand command = new ChangePasswordCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("old123", "!pass"));
|
||||
command.executeCommand(sender, newParts(), newParts("old123", "!pass"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
@@ -101,7 +102,7 @@ public class ChangePasswordCommandTest {
|
||||
ChangePasswordCommand command = new ChangePasswordCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("old_", "Tester"));
|
||||
command.executeCommand(sender, newParts(), newParts("old_", "Tester"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
@@ -116,7 +117,7 @@ public class ChangePasswordCommandTest {
|
||||
Settings.passwordMaxLength = 3;
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("12", "test"));
|
||||
command.executeCommand(sender, newParts(), newParts("12", "test"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
@@ -131,7 +132,7 @@ public class ChangePasswordCommandTest {
|
||||
Settings.getPasswordMinLen = 7;
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("oldverylongpassword", "tester"));
|
||||
command.executeCommand(sender, newParts(), newParts("oldverylongpassword", "tester"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
@@ -146,7 +147,7 @@ public class ChangePasswordCommandTest {
|
||||
Settings.unsafePasswords = asList("test", "abc123");
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("oldpw", "abc123"));
|
||||
command.executeCommand(sender, newParts(), newParts("oldpw", "abc123"));
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
@@ -160,7 +161,7 @@ public class ChangePasswordCommandTest {
|
||||
ChangePasswordCommand command = new ChangePasswordCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), newParts("abc123", "abc123"));
|
||||
command.executeCommand(sender, newParts(), newParts("abc123", "abc123"));
|
||||
|
||||
// then
|
||||
verify(messagesMock, never()).send(eq(sender), any(MessageKey.class));
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -40,7 +41,7 @@ public class AddEmailCommandTest {
|
||||
AddEmailCommand command = new AddEmailCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
verify(authMeMock, never()).getManagement();
|
||||
@@ -53,11 +54,15 @@ public class AddEmailCommandTest {
|
||||
AddEmailCommand command = new AddEmailCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(),
|
||||
command.executeCommand(sender, newParts(),
|
||||
new CommandParts(Arrays.asList("mail@example", "other_example")));
|
||||
|
||||
// then
|
||||
verify(authMeMock).getManagement();
|
||||
verify(managementMock).performAddEmail(sender, "mail@example", "other_example");
|
||||
}
|
||||
|
||||
private static CommandParts newParts() {
|
||||
return new CommandParts(new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -40,7 +41,7 @@ public class ChangeEmailCommandTest {
|
||||
ChangeEmailCommand command = new ChangeEmailCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
verify(authMeMock, never()).getManagement();
|
||||
@@ -53,11 +54,15 @@ public class ChangeEmailCommandTest {
|
||||
ChangeEmailCommand command = new ChangeEmailCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(),
|
||||
command.executeCommand(sender, newParts(),
|
||||
new CommandParts(Arrays.asList("new.mail@example.org", "old_mail@example.org")));
|
||||
|
||||
// then
|
||||
verify(authMeMock).getManagement();
|
||||
verify(managementMock).performChangeEmail(sender, "new.mail@example.org", "old_mail@example.org");
|
||||
}
|
||||
|
||||
private static CommandParts newParts() {
|
||||
return new CommandParts(new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Test for {@link RecoverEmailCommand}.
|
||||
*/
|
||||
@@ -27,7 +29,7 @@ public class RecoverEmailCommandTest {
|
||||
RecoverEmailCommand command = new RecoverEmailCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, new CommandParts(Collections.EMPTY_LIST), new CommandParts(Collections.EMPTY_LIST));
|
||||
|
||||
// then
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -38,7 +40,7 @@ public class LoginCommandTest {
|
||||
LoginCommand command = new LoginCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
Mockito.verify(managementMock, never()).performLogin(any(Player.class), anyString(), anyBoolean());
|
||||
@@ -51,7 +53,7 @@ public class LoginCommandTest {
|
||||
LoginCommand command = new LoginCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts("password"));
|
||||
command.executeCommand(sender, newParts(), new CommandParts("password"));
|
||||
|
||||
// then
|
||||
Mockito.verify(managementMock).performLogin(eq(sender), eq("password"), eq(false));
|
||||
@@ -64,11 +66,15 @@ public class LoginCommandTest {
|
||||
LoginCommand command = new LoginCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
// TODO ljacqu 20151121: May make sense to handle null password in LoginCommand instead of forwarding the call
|
||||
String password = null;
|
||||
Mockito.verify(managementMock).performLogin(eq(sender), eq(password), eq(false));
|
||||
}
|
||||
|
||||
private static CommandParts newParts() {
|
||||
return new CommandParts(new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -40,7 +42,7 @@ public class LogoutCommandTest {
|
||||
LogoutCommand command = new LogoutCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, new CommandParts(new ArrayList<String>()), new CommandParts(new ArrayList<String>()));
|
||||
|
||||
// then
|
||||
Mockito.verify(managementMock, never()).performLogout(any(Player.class));
|
||||
@@ -53,7 +55,7 @@ public class LogoutCommandTest {
|
||||
LogoutCommand command = new LogoutCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts("password"));
|
||||
command.executeCommand(sender, new CommandParts(new ArrayList<String>()), new CommandParts("password"));
|
||||
|
||||
// then
|
||||
Mockito.verify(managementMock).performLogout(sender);
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -48,7 +50,7 @@ public class RegisterCommandTest {
|
||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(messageCaptor.capture());
|
||||
@@ -63,7 +65,7 @@ public class RegisterCommandTest {
|
||||
RegisterCommand command = new RegisterCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||
command.executeCommand(sender, newParts(), newParts());
|
||||
|
||||
// then
|
||||
verify(messagesMock).send(sender, MessageKey.USAGE_REGISTER);
|
||||
@@ -77,9 +79,13 @@ public class RegisterCommandTest {
|
||||
RegisterCommand command = new RegisterCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new CommandParts(), new CommandParts("password"));
|
||||
command.executeCommand(sender, newParts(), new CommandParts("password"));
|
||||
|
||||
// then
|
||||
verify(managementMock).performRegister(sender, "password", "");
|
||||
}
|
||||
|
||||
private static CommandParts newParts() {
|
||||
return new CommandParts(new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.bukkit.ChatColor.BOLD;
|
||||
import static org.bukkit.ChatColor.ITALIC;
|
||||
import static org.bukkit.ChatColor.WHITE;
|
||||
@@ -27,7 +29,7 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), "", false);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), "", false);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme register" + ITALIC + " [name]"));
|
||||
@@ -41,7 +43,7 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), null, false);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), null, false);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme register" + ITALIC + " <test>"));
|
||||
@@ -56,7 +58,7 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), "", false);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), "", false);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme register" + ITALIC + " [name]" + ITALIC + " <test>"));
|
||||
@@ -71,7 +73,7 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), "", true);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), "", true);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme "
|
||||
@@ -85,7 +87,7 @@ public class HelpSyntaxHelperTest {
|
||||
CommandDescription description = getDescriptionBuilder().build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), null, true);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), null, true);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme " + YELLOW + BOLD + "register" + YELLOW));
|
||||
@@ -99,12 +101,16 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
// when
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, new CommandParts(), "alt", false);
|
||||
String result = HelpSyntaxHelper.getCommandSyntax(description, newParts(), "alt", false);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(WHITE + "/authme alt" + ITALIC + " [name]"));
|
||||
}
|
||||
|
||||
private static CommandParts newParts() {
|
||||
// TODO ljacqu 20151204: Remove this method once CommandParts has been removed
|
||||
return new CommandParts(new ArrayList<String>());
|
||||
}
|
||||
|
||||
private static CommandDescription.CommandBuilder getDescriptionBuilder() {
|
||||
CommandDescription base = CommandDescription.builder()
|
||||
|
||||
Reference in New Issue
Block a user