Add test to verify the format of command labels

- Fix test class throwing NPE when run isolation -> attempts to get Logger from Wrapper
This commit is contained in:
ljacqu 2015-11-30 21:18:58 +01:00
parent 485b6934e6
commit 44eef346b9

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.WrapperMock;
import org.junit.BeforeClass;
import org.junit.Test;
@ -10,6 +11,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@ -20,7 +22,7 @@ import static org.junit.Assert.fail;
/**
* Test for {@link CommandInitializer} to guarantee the integrity of the defined commands.
*/
public class CommandManagerTest {
public class CommandInitializerTest {
/**
* Defines the maximum allowed depths for nesting CommandDescription instances.
@ -32,6 +34,7 @@ public class CommandManagerTest {
@BeforeClass
public static void initializeCommandManager() {
WrapperMock.createInstance();
commands = CommandInitializer.getBaseCommands();
}
@ -83,6 +86,27 @@ public class CommandManagerTest {
walkThroughCommands(commands, connectionTester);
}
@Test
public void shouldUseProperLowerCaseLabels() {
// given
final Pattern invalidPattern = Pattern.compile("\\s");
BiConsumer labelFormatTester = new BiConsumer() {
@Override
public void accept(CommandDescription command, int depth) {
for (String label : command.getLabels()) {
if (!label.equals(label.toLowerCase())) {
fail("Label '" + label + "' should be lowercase");
} else if (invalidPattern.matcher(label).matches()) {
fail("Label '" + label + "' has whitespace");
}
}
}
};
// when/then
walkThroughCommands(commands, labelFormatTester);
}
@Test
public void shouldNotDefineSameLabelTwice() {
// given