Fixed player permission tests, improved test structure consistency

This commit is contained in:
Tim Visée 2015-12-01 16:44:49 +01:00
parent 7ac39d80fd
commit 2550e04112
2 changed files with 37 additions and 22 deletions

View File

@ -18,9 +18,9 @@ public class AdminPermissionTest {
String requiredPrefix = "authme."; String requiredPrefix = "authme.";
// when/then // when/then
for (AdminPermission perm : AdminPermission.values()) { for (AdminPermission permission : AdminPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) { if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'"); fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
} }
} }
} }
@ -31,9 +31,9 @@ public class AdminPermissionTest {
String requiredBranch = ".admin."; String requiredBranch = ".admin.";
// when/then // when/then
for (AdminPermission perm : AdminPermission.values()) { for (AdminPermission permission : AdminPermission.values()) {
if (!perm.getNode().contains(requiredBranch)) { if (!permission.getNode().contains(requiredBranch)) {
fail("The permission '" + perm + "' does not contain with the required branch '" + requiredBranch + "'"); fail("The permission '" + permission + "' does not contain with the required branch '" + requiredBranch + "'");
} }
} }
} }
@ -44,11 +44,11 @@ public class AdminPermissionTest {
Set<String> nodes = new HashSet<>(); Set<String> nodes = new HashSet<>();
// when/then // when/then
for (AdminPermission perm : AdminPermission.values()) { for (AdminPermission permission : AdminPermission.values()) {
if (nodes.contains(perm.getNode())) { if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'"); fail("More than one enum value defines the node '" + permission.getNode() + "'");
} }
nodes.add(perm.getNode()); nodes.add(permission.getNode());
} }
} }

View File

@ -13,18 +13,33 @@ import static org.junit.Assert.fail;
public class PlayerPermissionTest { public class PlayerPermissionTest {
@Test @Test
public void shouldStartWithRegularAuthMePrefix() { public void shouldStartWithAuthMePrefix() {
// given // given
String requiredPrefix = "authme."; String requiredPrefix = "authme.";
String adminPrefix = "authme.admin";
// when/then // when/then
for (PlayerPermission perm : PlayerPermission.values()) { for (PlayerPermission permission : PlayerPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) { if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'"); fail("The permission '" + permission + "' 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 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<String> nodes = new HashSet<>(); Set<String> nodes = new HashSet<>();
// when/then // when/then
for (PlayerPermission perm : PlayerPermission.values()) { for (PlayerPermission permission : PlayerPermission.values()) {
if (nodes.contains(perm.getNode())) { if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'"); fail("More than one enum value defines the node '" + permission.getNode() + "'");
} }
nodes.add(perm.getNode()); nodes.add(permission.getNode());
} }
} }
} }