Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor

Conflicts:
	src/main/java/fr/xephi/authme/command/CommandDescription.java
	src/main/java/fr/xephi/authme/command/CommandInitializer.java
This commit is contained in:
ljacqu
2015-12-01 20:43:49 +01:00
21 changed files with 357 additions and 216 deletions
@@ -131,7 +131,7 @@ public class HelpSyntaxHelperTest {
}
private static CommandDescription.Builder getDescriptionBuilder() {
private static CommandDescription.CommandBuilder getDescriptionBuilder() {
CommandDescription base = CommandDescription.builder()
.labels("authme")
.description("Base command")
@@ -13,14 +13,27 @@ import static org.junit.Assert.fail;
public class AdminPermissionTest {
@Test
public void shouldStartWithAuthMeAdminPrefix() {
public void shouldStartWithAuthMePrefix() {
// given
String requiredPrefix = "authme.admin.";
String requiredPrefix = "authme.";
// when/then
for (AdminPermission perm : AdminPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'");
for (AdminPermission permission : AdminPermission.values()) {
if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
}
}
}
@Test
public void shouldContainAdminBranch() {
// given
String requiredBranch = ".admin.";
// when/then
for (AdminPermission permission : AdminPermission.values()) {
if (!permission.getNode().contains(requiredBranch)) {
fail("The permission '" + permission + "' does not contain with the required branch '" + requiredBranch + "'");
}
}
}
@@ -31,11 +44,11 @@ public class AdminPermissionTest {
Set<String> nodes = new HashSet<>();
// when/then
for (AdminPermission perm : AdminPermission.values()) {
if (nodes.contains(perm.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'");
for (AdminPermission permission : AdminPermission.values()) {
if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + permission.getNode() + "'");
}
nodes.add(perm.getNode());
nodes.add(permission.getNode());
}
}
@@ -0,0 +1,60 @@
package fr.xephi.authme.permission;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
/**
* Test for {@link PlayerPermission}.
*/
public class PlayerPermissionTest {
@Test
public void shouldStartWithAuthMePrefix() {
// given
String requiredPrefix = "authme.";
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
}
}
}
@Test
public void shouldContainPlayerBranch() {
// given
String playerBranch = ".player.";
String adminBranch = ".admin.";
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (permission.getNode().contains(adminBranch)) {
fail("The permission '" + permission + "' should not use a node with the admin-specific branch '"
+ adminBranch + "'");
} else if (!permission.getNode().contains(playerBranch)) {
fail("The permission '" + permission + "' should use a node with the player-specific branch '"
+ playerBranch + "'");
}
}
}
@Test
public void shouldHaveUniqueNodes() {
// given
Set<String> nodes = new HashSet<>();
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + permission.getNode() + "'");
}
nodes.add(permission.getNode());
}
}
}
@@ -1,45 +0,0 @@
package fr.xephi.authme.permission;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
/**
* Test for {@link UserPermission}.
*/
public class UserPermissionTest {
@Test
public void shouldStartWithRegularAuthMePrefix() {
// given
String requiredPrefix = "authme.";
String adminPrefix = "authme.admin";
// when/then
for (UserPermission perm : UserPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'");
} else if (perm.getNode().startsWith(adminPrefix)) {
fail("The permission '" + perm + "' should not use a node with the admin-specific prefix '"
+ adminPrefix + "'");
}
}
}
@Test
public void shouldHaveUniqueNodes() {
// given
Set<String> nodes = new HashSet<>();
// when/then
for (UserPermission perm : UserPermission.values()) {
if (nodes.contains(perm.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'");
}
nodes.add(perm.getNode());
}
}
}
@@ -3,7 +3,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.Settings;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@@ -54,7 +54,7 @@ public class UtilsTest {
public void shouldForceSurvivalGameMode() {
// given
Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(false);
given(permissionsManagerMock.hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)).willReturn(false);
// when
Utils.forceGM(player);
@@ -68,14 +68,14 @@ public class UtilsTest {
public void shouldNotForceGameModeForUserWithBypassPermission() {
// given
Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(true);
given(permissionsManagerMock.hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)).willReturn(true);
// when
Utils.forceGM(player);
// then
verify(authMeMock).getPermissionsManager();
verify(permissionsManagerMock).hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL);
verify(permissionsManagerMock).hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL);
verify(player, never()).setGameMode(any(GameMode.class));
}