Search in sources :

Example 16 with FoundCommandResult

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

the class SwitchAntiBotCommandTest method shouldShowHelpForUnknownState.

@Test
public void shouldShowHelpForUnknownState() {
    // given
    CommandSender sender = mock(CommandSender.class);
    FoundCommandResult foundCommandResult = mock(FoundCommandResult.class);
    given(commandMapper.mapPartsToCommand(sender, asList("authme", "antibot"))).willReturn(foundCommandResult);
    // when
    command.executeCommand(sender, Collections.singletonList("wrong"));
    // then
    verify(antiBot, never()).overrideAntiBotStatus(anyBoolean());
    verify(sender).sendMessage(argThat(containsString("Invalid")));
    verify(helpProvider).outputHelp(sender, foundCommandResult, HelpProvider.SHOW_ARGUMENTS);
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 17 with FoundCommandResult

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

the class HelpProviderTest method shouldNotShowAnythingIfHasNoAlternatives.

@Test
public void shouldNotShowAnythingIfHasNoAlternatives() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme", "login");
    FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "login"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_ALTERNATIVES);
    // then
    List<String> lines = getLines(sender);
    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)

Example 18 with FoundCommandResult

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

the class HelpProviderTest method shouldShowAndEvaluatePermissions.

@Test
public void shouldShowAndEvaluatePermissions() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "unregister");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
    given(sender.isOp()).willReturn(true);
    given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(true);
    given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(true);
    // when
    helpProvider.outputHelp(sender, result, SHOW_PERMISSIONS);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(5));
    assertThat(lines.get(1), containsString("Permissions:"));
    assertThat(lines.get(2), containsString(AdminPermission.UNREGISTER.getNode() + " (Has permission)"));
    assertThat(lines.get(3), containsString("Default: Op only (Has permission)"));
    assertThat(lines.get(4), containsString("Result: Has permission"));
}
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 19 with FoundCommandResult

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

the class HelpProviderTest method shouldNotReturnAnythingForAllDisabledSections.

@Test
public void shouldNotReturnAnythingForAllDisabledSections() {
    // given
    given(helpMessagesService.getMessage(HelpSection.COMMAND)).willReturn("");
    given(helpMessagesService.getMessage(HelpSection.ALTERNATIVES)).willReturn("");
    given(helpMessagesService.getMessage(HelpSection.PERMISSIONS)).willReturn("");
    CommandDescription command = getCommandWithLabel(commands, "authme", "register");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_COMMAND | SHOW_ALTERNATIVES | SHOW_PERMISSIONS);
    // then
    verify(sender, never()).sendMessage(anyString());
}
Also used : FoundCommandResult(fr.xephi.authme.command.FoundCommandResult) CommandDescription(fr.xephi.authme.command.CommandDescription) Test(org.junit.Test)

Example 20 with FoundCommandResult

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

the class HelpProviderTest method shouldShowLongDescription.

@Test
public void shouldShowLongDescription() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "authme", "login");
    FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "login"));
    // when
    helpProvider.outputHelp(sender, result, SHOW_COMMAND | SHOW_LONG_DESCRIPTION | SHOW_DESCRIPTION);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(5));
    assertThat(lines.get(0), containsString("Header"));
    assertThat(lines.get(1), containsString("Command: /authme login <password>"));
    assertThat(lines.get(2), containsString("Short description: login cmd"));
    assertThat(lines.get(3), equalTo("Detailed description:"));
    assertThat(lines.get(4), containsString("'login' test command"));
}
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