From 2550e041126a01557dcaf9e7498d5f5dac8b357d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:44:49 +0100 Subject: [PATCH] Fixed player permission tests, improved test structure consistency --- .../permission/AdminPermissionTest.java | 20 +++++----- .../permission/PlayerPermissionTest.java | 39 +++++++++++++------ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java index 34de95a7b..c3a89b723 100644 --- a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java @@ -18,9 +18,9 @@ public class AdminPermissionTest { 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 + "'"); } } } @@ -31,9 +31,9 @@ public class AdminPermissionTest { String requiredBranch = ".admin."; // when/then - for (AdminPermission perm : AdminPermission.values()) { - if (!perm.getNode().contains(requiredBranch)) { - fail("The permission '" + perm + "' does not contain with the required branch '" + requiredBranch + "'"); + for (AdminPermission permission : AdminPermission.values()) { + if (!permission.getNode().contains(requiredBranch)) { + fail("The permission '" + permission + "' does not contain with the required branch '" + requiredBranch + "'"); } } } @@ -44,11 +44,11 @@ public class AdminPermissionTest { Set 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()); } } diff --git a/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java index 92b3c7d91..81893373f 100644 --- a/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java @@ -13,18 +13,33 @@ import static org.junit.Assert.fail; public class PlayerPermissionTest { @Test - public void shouldStartWithRegularAuthMePrefix() { + public void shouldStartWithAuthMePrefix() { // given String requiredPrefix = "authme."; - String adminPrefix = "authme.admin"; // when/then - for (PlayerPermission perm : PlayerPermission.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 + "'"); + 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 + "'"); } } } @@ -35,11 +50,11 @@ public class PlayerPermissionTest { Set nodes = new HashSet<>(); // when/then - for (PlayerPermission perm : PlayerPermission.values()) { - if (nodes.contains(perm.getNode())) { - fail("More than one enum value defines the node '" + perm.getNode() + "'"); + for (PlayerPermission permission : PlayerPermission.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()); } } }