Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into commands-refactor

Conflicts:
	src/main/java/fr/xephi/authme/command/CommandUtils.java
	src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java
This commit is contained in:
ljacqu
2015-12-17 22:32:26 +01:00
38 changed files with 375 additions and 182 deletions
@@ -5,6 +5,7 @@ import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.WrapperMock;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import java.util.ArrayList;
@@ -269,6 +270,42 @@ public class CommandInitializerTest {
walkThroughCommands(commands, adminPermissionChecker);
}
/**
* Tests that multiple CommandDescription instances pointing to the same ExecutableCommand use the same
* count of arguments.
*/
@Test
@Ignore // TODO #306 ljacqu 20151214: Un-ignore this test and fix the offending command
public void shouldPointToSameExecutableCommandWithConsistentArgumentCount() {
// given
final Map<Class<? extends ExecutableCommand>, Integer> mandatoryArguments = new HashMap<>();
final Map<Class<? extends ExecutableCommand>, Integer> totalArguments = new HashMap<>();
BiConsumer argChecker = new BiConsumer() {
@Override
public void accept(CommandDescription command, int depth) {
testCollectionForCommand(command, CommandUtils.getMinNumberOfArguments(command), mandatoryArguments);
testCollectionForCommand(command, CommandUtils.getMaxNumberOfArguments(command), totalArguments);
}
private void testCollectionForCommand(CommandDescription command, int argCount,
Map<Class<? extends ExecutableCommand>, Integer> collection) {
final Class<? extends ExecutableCommand> clazz = command.getExecutableCommand().getClass();
Integer existingCount = collection.get(clazz);
if (existingCount != null) {
String commandDescription = "Command with label '" + command.getLabels().get(0) + "' and parent '"
+ (command.getParent() != null ? command.getLabels().get(0) : "null") + "' ";
assertThat(commandDescription + "should point to " + clazz + " with arguments consistent to others",
argCount, equalTo(existingCount));
} else {
collection.put(clazz, argCount);
}
}
};
// when / then
walkThroughCommands(commands, argChecker);
}
// ------------
// Helper methods