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));
}
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"));
}
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"));
}
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);
}
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"));
}
Aggregations