Search in sources :

Example 6 with FoundCommandResult

use of fr.xephi.authme.command.FoundCommandResult in project AuthMeReloaded by AuthMe.

the class HelpCommandTest method shouldHandleMissingBaseCommand.

@Test
public void shouldHandleMissingBaseCommand() {
    // given
    List<String> arguments = asList("some", "command");
    CommandSender sender = mock(CommandSender.class);
    FoundCommandResult foundCommandResult = new FoundCommandResult(null, null, null, 0.0, MISSING_BASE_COMMAND);
    given(commandMapper.mapPartsToCommand(sender, arguments)).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, arguments);
    // then
    verify(sender).sendMessage(argThat(containsString("Could not get base command")));
    verifyZeroInteractions(helpProvider);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with FoundCommandResult

use of fr.xephi.authme.command.FoundCommandResult in project AuthMeReloaded by AuthMe.

the class HelpCommandTest method shouldHandleWrongCommandWithSuggestion.

@Test
public void shouldHandleWrongCommandWithSuggestion() {
    // given
    List<String> arguments = asList("authme", "ragister", "test");
    CommandSender sender = mock(CommandSender.class);
    CommandDescription description = newCommandDescription("authme", "register");
    FoundCommandResult foundCommandResult = new FoundCommandResult(description, asList("authme", "ragister"), singletonList("test"), 0.1, UNKNOWN_LABEL);
    given(commandMapper.mapPartsToCommand(sender, arguments)).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, arguments);
    // then
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(sender).sendMessage(captor.capture());
    assertThat(removeColors(captor.getValue()), containsString("Assuming /authme register"));
    verify(helpProvider).outputHelp(sender, foundCommandResult, HelpProvider.ALL_OPTIONS);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with FoundCommandResult

use of fr.xephi.authme.command.FoundCommandResult in project AuthMeReloaded by AuthMe.

the class HelpProviderTest method shouldShowCommandSyntaxWithCorrectLabels.

/**
     * Since command parts may be mapped to a command description with labels that don't completely correspond to it,
     * (e.g. suggest "register command" for /authme ragister), we need to check the labels and construct a correct list
     */
@Test
public void shouldShowCommandSyntaxWithCorrectLabels() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme", "register");
    FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "ragister"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_COMMAND);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(2));
    assertThat(lines.get(0), containsString("Header"));
    assertThat(lines.get(1), containsString("Command: /authme register <password> <confirmation>"));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with FoundCommandResult

use of fr.xephi.authme.command.FoundCommandResult in project AuthMeReloaded by AuthMe.

the class HelpProviderTest method shouldShowSpecifyIfArgumentIsOptional.

@Test
public void shouldShowSpecifyIfArgumentIsOptional() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "email");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("email"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_ARGUMENTS);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(3));
    assertThat(lines.get(2), containsString("player: 'player' argument description (Optional)"));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with FoundCommandResult

use of fr.xephi.authme.command.FoundCommandResult in project AuthMeReloaded by AuthMe.

the class HelpProviderTest method shouldNotShowAnythingIfCommandHasNoArguments.

/** Verifies that the "Arguments:" line is not shown if the command has no arguments. */
@Test
public void shouldNotShowAnythingIfCommandHasNoArguments() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_ARGUMENTS);
    // then
    List<String> lines = getLines(sender);
    // only has the help banner
    assertThat(lines, hasSize(1));
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)26 Test (org.junit.Test)24 Matchers.containsString (org.hamcrest.Matchers.containsString)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 CommandDescription (fr.xephi.authme.command.CommandDescription)20 CommandSender (org.bukkit.command.CommandSender)6 FoundResultStatus (fr.xephi.authme.command.FoundResultStatus)1