From 8f5817883ea3fcc5b4b02e8636f83652e9453b7c Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 3 Jul 2016 11:47:37 +0200 Subject: [PATCH] Testing - check return value of Set#add instead of separately checking Set#contains --- src/test/java/fr/xephi/authme/output/MessageKeyTest.java | 3 +-- .../java/fr/xephi/authme/permission/AdminPermissionTest.java | 3 +-- .../java/fr/xephi/authme/permission/PlayerPermissionTest.java | 3 +-- .../fr/xephi/authme/permission/PlayerStatePermissionTest.java | 3 +-- .../fr/xephi/authme/security/HashAlgorithmIntegrationTest.java | 3 +-- .../settings/properties/SettingsClassConsistencyTest.java | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/test/java/fr/xephi/authme/output/MessageKeyTest.java b/src/test/java/fr/xephi/authme/output/MessageKeyTest.java index 101306bf9..dda5eeb9d 100644 --- a/src/test/java/fr/xephi/authme/output/MessageKeyTest.java +++ b/src/test/java/fr/xephi/authme/output/MessageKeyTest.java @@ -22,12 +22,11 @@ public class MessageKeyTest { // when / then for (MessageKey messageKey : messageKeys) { String key = messageKey.getKey(); - if (keys.contains(key)) { + if (!keys.add(key)) { fail("Found key '" + messageKey.getKey() + "' twice!"); } else if (StringUtils.isEmpty(key)) { fail("Key for message key '" + messageKey + "' is empty"); } - keys.add(key); } } } diff --git a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java index 0c2c2b16c..3cfa0e271 100644 --- a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java @@ -33,10 +33,9 @@ public class AdminPermissionTest { // when/then for (AdminPermission permission : AdminPermission.values()) { - if (nodes.contains(permission.getNode())) { + if (!nodes.add(permission.getNode())) { fail("More than one enum value defines the node '" + permission.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 632a2cf3e..ad8f6fe9e 100644 --- a/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java @@ -33,10 +33,9 @@ public class PlayerPermissionTest { // when/then for (PlayerPermission permission : PlayerPermission.values()) { - if (nodes.contains(permission.getNode())) { + if (!nodes.add(permission.getNode())) { fail("More than one enum value defines the node '" + permission.getNode() + "'"); } - nodes.add(permission.getNode()); } } } diff --git a/src/test/java/fr/xephi/authme/permission/PlayerStatePermissionTest.java b/src/test/java/fr/xephi/authme/permission/PlayerStatePermissionTest.java index 94b6e246d..6c3e3d163 100644 --- a/src/test/java/fr/xephi/authme/permission/PlayerStatePermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/PlayerStatePermissionTest.java @@ -37,10 +37,9 @@ public class PlayerStatePermissionTest { // when/then for (PlayerStatePermission permission : PlayerStatePermission.values()) { - if (nodes.contains(permission.getNode())) { + if (!nodes.add(permission.getNode())) { fail("More than one enum value defines the node '" + permission.getNode() + "'"); } - nodes.add(permission.getNode()); } } diff --git a/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java b/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java index 79745a33f..9f875a001 100644 --- a/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java @@ -43,10 +43,9 @@ public class HashAlgorithmIntegrationTest { // when / then for (HashAlgorithm algorithm : HashAlgorithm.values()) { if (!HashAlgorithm.CUSTOM.equals(algorithm)) { - if (classes.contains(algorithm.getClazz())) { + if (!classes.add(algorithm.getClazz())) { fail("Found class '" + algorithm.getClazz() + "' twice!"); } - classes.add(algorithm.getClazz()); } } } diff --git a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java index 75c1a56a3..9e075200e 100644 --- a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java @@ -74,10 +74,9 @@ public class SettingsClassConsistencyTest { if (Property.class.isAssignableFrom(field.getType())) { Property property = (Property) ReflectionTestUtils.getFieldValue(clazz, null, field.getName()); - if (paths.contains(property.getPath())) { + if (!paths.add(property.getPath())) { fail("Path '" + property.getPath() + "' should be used by only one constant"); } - paths.add(property.getPath()); } } }