#305 Adjust behavior of label handling; cleanup

- Fix bugs in behavior (wrong labels being shown for help)
- Change order of labels and arguments in FoundCommandResult constructors
- Move FoundResultStatus enum to its own class
- Create test class for HelpProvider
This commit is contained in:
ljacqu
2015-12-18 22:19:26 +01:00
parent d871939793
commit 01a294a334
9 changed files with 231 additions and 51 deletions
@@ -0,0 +1,65 @@
package fr.xephi.authme.command.help;
import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.ExecutableCommand;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
/**
* Test for {@link HelpProvider}.
*/
public class HelpProviderTest {
private static CommandDescription parent;
private static CommandDescription child;
@BeforeClass
public static void setUpCommands() {
parent = CommandDescription.builder()
.executableCommand(mock(ExecutableCommand.class))
.labels("base", "b")
.description("Parent")
.detailedDescription("Test base command.")
.build();
child = CommandDescription.builder()
.executableCommand(mock(ExecutableCommand.class))
.parent(parent)
.labels("child", "c")
.description("Child")
.detailedDescription("Child test command.")
.withArgument("Argument", "The argument", false)
.build();
}
@Test
public void shouldRetainCorrectLabels() {
// given
List<String> labels = Arrays.asList("b", "child");
// when
List<String> result = HelpProvider.filterCorrectLabels(child, labels);
// then
assertThat(result, contains("b", "child"));
}
@Test
public void shouldReplaceIncorrectLabels() {
// given
List<String> labels = Arrays.asList("base", "wrong");
// when
List<String> result = HelpProvider.filterCorrectLabels(child, labels);
// then
assertThat(result, contains("base", "child"));
}
}