#604 Fix HelpProvider tests

This commit is contained in:
ljacqu 2016-05-30 23:49:59 +02:00
parent 3ad00a45f9
commit 30b72bec4c
3 changed files with 13 additions and 19 deletions

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
@ -287,7 +286,7 @@ public class CommandDescription {
} }
/** /**
* Add a permission node that the a user must have to execute the command. * Add a permission node that a user must have to execute the command.
* *
* @param permission The PermissionNode to add * @param permission The PermissionNode to add
* @return The builder * @return The builder

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import fr.xephi.authme.command.executable.HelpCommand; import fr.xephi.authme.command.executable.HelpCommand;
import fr.xephi.authme.permission.DefaultPermission; import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.permission.PlayerPermission;
@ -43,8 +43,8 @@ public final class TestCommandsUtil {
.description("test").detailedDescription("Test.").withArgument("Query", "", false).build(); .description("test").detailedDescription("Test.").withArgument("Query", "", false).build();
// Register /unregister <player>, alias: /unreg // Register /unregister <player>, alias: /unreg
CommandDescription unregisterBase = createCommand(null, null, asList("unregister", "unreg"), CommandDescription unregisterBase = createCommand(AdminPermission.UNREGISTER, null,
newArgument("player", false)); asList("unregister", "unreg"), newArgument("player", false));
return newHashSet(authMeBase, emailBase, unregisterBase); return newHashSet(authMeBase, emailBase, unregisterBase);
} }

View File

@ -4,15 +4,14 @@ import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.FoundCommandResult; import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.FoundResultStatus; import fr.xephi.authme.command.FoundResultStatus;
import fr.xephi.authme.command.TestCommandsUtil; import fr.xephi.authme.command.TestCommandsUtil;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
@ -125,14 +124,12 @@ public class HelpProviderTest {
} }
@Test @Test
@Ignore
// TODO Gnat008 20160530: Update tests for new PermissionNode setup
public void shouldShowAndEvaluatePermissions() { public void shouldShowAndEvaluatePermissions() {
// given // given
CommandDescription command = getCommandWithLabel(commands, "authme", "login"); CommandDescription command = getCommandWithLabel(commands, "unregister");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme")); FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
given(sender.isOp()).willReturn(true); given(sender.isOp()).willReturn(true);
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(true); given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(true);
given(permissionsManager.hasPermission(sender, command)).willReturn(true); given(permissionsManager.hasPermission(sender, command)).willReturn(true);
// when // when
@ -142,20 +139,18 @@ public class HelpProviderTest {
assertThat(lines, hasSize(5)); assertThat(lines, hasSize(5));
assertThat(removeColors(lines.get(1)), containsString("Permissions:")); assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
assertThat(removeColors(lines.get(2)), assertThat(removeColors(lines.get(2)),
containsString(PlayerPermission.LOGIN.getNode() + " (You have permission)")); containsString(AdminPermission.UNREGISTER.getNode() + " (You have permission)"));
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (You have permission)")); assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (You have permission)"));
assertThat(removeColors(lines.get(4)), containsString("Result: You have permission")); assertThat(removeColors(lines.get(4)), containsString("Result: You have permission"));
} }
@Test @Test
@Ignore
// TODO Gnat008 20160530: Update tests for new PermissionNode setup
public void shouldShowAndEvaluateForbiddenPermissions() { public void shouldShowAndEvaluateForbiddenPermissions() {
// given // given
CommandDescription command = getCommandWithLabel(commands, "authme", "login"); CommandDescription command = getCommandWithLabel(commands, "unregister");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme")); FoundCommandResult result = newFoundResult(command, Collections.singletonList("unregister"));
given(sender.isOp()).willReturn(false); given(sender.isOp()).willReturn(false);
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(false); given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(false);
given(permissionsManager.hasPermission(sender, command)).willReturn(false); given(permissionsManager.hasPermission(sender, command)).willReturn(false);
// when // when
@ -165,7 +160,7 @@ public class HelpProviderTest {
assertThat(lines, hasSize(5)); assertThat(lines, hasSize(5));
assertThat(removeColors(lines.get(1)), containsString("Permissions:")); assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
assertThat(removeColors(lines.get(2)), assertThat(removeColors(lines.get(2)),
containsString(PlayerPermission.LOGIN.getNode() + " (No permission)")); containsString(AdminPermission.UNREGISTER.getNode() + " (No permission)"));
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (No permission)")); assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (No permission)"));
assertThat(removeColors(lines.get(4)), containsString("Result: No permission")); assertThat(removeColors(lines.get(4)), containsString("Result: No permission"));
} }