Testing - check return value of Set#add instead of separately checking Set#contains

This commit is contained in:
ljacqu 2016-07-03 11:47:37 +02:00
parent 2420a83ec3
commit 8f5817883e
6 changed files with 6 additions and 12 deletions

View File

@ -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);
}
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}
}

View File

@ -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());
}
}
}