Search in sources :

Example 6 with CommandDescription

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

the class HelpProviderTest method shouldRetainCorrectLabels.

@Test
public void shouldRetainCorrectLabels() {
    // given
    List<String> labels = Arrays.asList("authme", "reg");
    CommandDescription command = getCommandWithLabel(commands, "authme", "register");
    // when
    List<String> result = HelpProvider.filterCorrectLabels(command, labels);
    // then
    assertThat(result, equalTo(labels));
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with CommandDescription

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

the class HelpProviderTest method shouldDisableSectionsWithEmptyTranslations.

@Test
public void shouldDisableSectionsWithEmptyTranslations() {
    // given
    given(helpMessagesService.getMessage(HelpSection.DETAILED_DESCRIPTION)).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, ALL_OPTIONS);
    // then
    List<String> lines = getLines(sender);
    assertThat(lines, hasSize(6));
    assertThat(lines.get(0), equalTo("Header"));
    assertThat(lines.get(1), equalTo("Command: /authme register <password> <confirmation>"));
    assertThat(lines.get(2), equalTo("Short description: register cmd"));
    assertThat(lines.get(3), equalTo("Arguments:"));
    assertThat(lines.get(4), containsString("'password' argument description"));
    assertThat(lines.get(5), containsString("'confirmation' argument description"));
}
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 8 with CommandDescription

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

the class HelpProviderTest method shouldShowAndEvaluateForbiddenPermissions.

@Test
public void shouldShowAndEvaluateForbiddenPermissions() {
    // given
    CommandDescription command = getCommandWithLabel(commands, "unregister");
    FoundCommandResult result = newFoundResult(command, Collections.singletonList("unregister"));
    given(sender.isOp()).willReturn(false);
    given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(false);
    given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(false);
    // 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() + " (No permission)"));
    assertThat(lines.get(3), containsString("Default: Op only (No permission)"));
    assertThat(lines.get(4), containsString("Result: No 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 9 with CommandDescription

use of fr.xephi.authme.command.CommandDescription 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 10 with CommandDescription

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

the class HelpProviderTest method shouldReplaceIncorrectLabels.

@Test
public void shouldReplaceIncorrectLabels() {
    // given
    List<String> labels = Arrays.asList("authme", "wrong");
    CommandDescription command = getCommandWithLabel(commands, "authme", "register");
    // when
    List<String> result = HelpProvider.filterCorrectLabels(command, labels);
    // then
    assertThat(result, contains("authme", "register"));
}
Also used : CommandDescription(fr.xephi.authme.command.CommandDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

CommandDescription (fr.xephi.authme.command.CommandDescription)38 Test (org.junit.Test)30 Matchers.containsString (org.hamcrest.Matchers.containsString)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)20 CommandInitializer (fr.xephi.authme.command.CommandInitializer)4 CommandSender (org.bukkit.command.CommandSender)3 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 TestHelper (fr.xephi.authme.TestHelper)1 CommandArgumentDescription (fr.xephi.authme.command.CommandArgumentDescription)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 MemorySection (org.bukkit.configuration.MemorySection)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1