Merge pull request #150 from Isira-Seneviratne/Simplify_assertions_in_MapUtilsTest

Simplify several assertions in MapUtilsTest.
This commit is contained in:
Bruno P. Kinoshita 2020-04-19 11:41:32 +12:00 committed by GitHub
commit 5907d36b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 39 deletions

View File

@ -151,8 +151,8 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
final Set<String> outKeySet = new HashSet<>(out.keySet()); final Set<String> outKeySet = new HashSet<>(out.keySet());
final Set<String> outValSet = new HashSet<>(out.values()); final Set<String> outValSet = new HashSet<>(out.values());
assertTrue( inKeySet.equals( outValSet )); assertEquals(inKeySet, outValSet);
assertTrue( inValSet.equals( outKeySet )); assertEquals(inValSet, outKeySet);
assertEquals( "1", out.get("A")); assertEquals( "1", out.get("A"));
assertEquals( "2", out.get("B")); assertEquals( "2", out.get("B"));
@ -181,11 +181,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
{"GREEN", "#00FF00"}, {"GREEN", "#00FF00"},
{"BLUE", "#0000FF"} {"BLUE", "#0000FF"}
}); });
assertEquals(true, test.containsKey("RED")); assertTrue(test.containsKey("RED"));
assertEquals("#FF0000", test.get("RED")); assertEquals("#FF0000", test.get("RED"));
assertEquals(true, test.containsKey("GREEN")); assertTrue(test.containsKey("GREEN"));
assertEquals("#00FF00", test.get("GREEN")); assertEquals("#00FF00", test.get("GREEN"));
assertEquals(true, test.containsKey("BLUE")); assertTrue(test.containsKey("BLUE"));
assertEquals("#0000FF", test.get("BLUE")); assertEquals("#0000FF", test.get("BLUE"));
assertEquals(3, test.size()); assertEquals(3, test.size());
@ -222,11 +222,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
"GREEN", "#00FF00", "GREEN", "#00FF00",
"BLUE", "#0000FF" "BLUE", "#0000FF"
}); });
assertEquals(true, test.containsKey("RED")); assertTrue(test.containsKey("RED"));
assertEquals("#FF0000", test.get("RED")); assertEquals("#FF0000", test.get("RED"));
assertEquals(true, test.containsKey("GREEN")); assertTrue(test.containsKey("GREEN"));
assertEquals("#00FF00", test.get("GREEN")); assertEquals("#00FF00", test.get("GREEN"));
assertEquals(true, test.containsKey("BLUE")); assertTrue(test.containsKey("BLUE"));
assertEquals("#0000FF", test.get("BLUE")); assertEquals("#0000FF", test.get("BLUE"));
assertEquals(3, test.size()); assertEquals(3, test.size());
@ -236,11 +236,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
"BLUE", "#0000FF", "BLUE", "#0000FF",
"PURPLE" // ignored "PURPLE" // ignored
}); });
assertEquals(true, test.containsKey("RED")); assertTrue(test.containsKey("RED"));
assertEquals("#FF0000", test.get("RED")); assertEquals("#FF0000", test.get("RED"));
assertEquals(true, test.containsKey("GREEN")); assertTrue(test.containsKey("GREEN"));
assertEquals("#00FF00", test.get("GREEN")); assertEquals("#00FF00", test.get("GREEN"));
assertEquals(true, test.containsKey("BLUE")); assertTrue(test.containsKey("BLUE"));
assertEquals("#0000FF", test.get("BLUE")); assertEquals("#0000FF", test.get("BLUE"));
assertEquals(3, test.size()); assertEquals(3, test.size());
@ -253,11 +253,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
new DefaultMapEntry<>("GREEN", "#00FF00"), new DefaultMapEntry<>("GREEN", "#00FF00"),
new DefaultMapEntry<>("BLUE", "#0000FF") new DefaultMapEntry<>("BLUE", "#0000FF")
}); });
assertEquals(true, test.containsKey("RED")); assertTrue(test.containsKey("RED"));
assertEquals("#FF0000", test.get("RED")); assertEquals("#FF0000", test.get("RED"));
assertEquals(true, test.containsKey("GREEN")); assertTrue(test.containsKey("GREEN"));
assertEquals("#00FF00", test.get("GREEN")); assertEquals("#00FF00", test.get("GREEN"));
assertEquals(true, test.containsKey("BLUE")); assertTrue(test.containsKey("BLUE"));
assertEquals("#0000FF", test.get("BLUE")); assertEquals("#0000FF", test.get("BLUE"));
assertEquals(3, test.size()); assertEquals(3, test.size());
@ -267,11 +267,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
new DefaultKeyValue<>("GREEN", "#00FF00"), new DefaultKeyValue<>("GREEN", "#00FF00"),
new DefaultKeyValue<>("BLUE", "#0000FF") new DefaultKeyValue<>("BLUE", "#0000FF")
}); });
assertEquals(true, test.containsKey("RED")); assertTrue(test.containsKey("RED"));
assertEquals("#FF0000", test.get("RED")); assertEquals("#FF0000", test.get("RED"));
assertEquals(true, test.containsKey("GREEN")); assertTrue(test.containsKey("GREEN"));
assertEquals("#00FF00", test.get("GREEN")); assertEquals("#00FF00", test.get("GREEN"));
assertEquals(true, test.containsKey("BLUE")); assertTrue(test.containsKey("BLUE"));
assertEquals("#0000FF", test.get("BLUE")); assertEquals("#0000FF", test.get("BLUE"));
assertEquals(3, test.size()); assertEquals(3, test.size());
} }
@ -304,7 +304,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
final Map<String, Object> out = MapUtils.toMap(b); final Map<String, Object> out = MapUtils.toMap(b);
assertTrue( in.equals(out)); assertEquals(in, out);
} }
@Test @Test
@ -748,39 +748,39 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
@Test @Test
public void testIsEmptyWithEmptyMap() { public void testIsEmptyWithEmptyMap() {
final Map<Object, Object> map = new HashMap<>(); final Map<Object, Object> map = new HashMap<>();
assertEquals(true, MapUtils.isEmpty(map)); assertTrue(MapUtils.isEmpty(map));
} }
@Test @Test
public void testIsEmptyWithNonEmptyMap() { public void testIsEmptyWithNonEmptyMap() {
final Map<String, String> map = new HashMap<>(); final Map<String, String> map = new HashMap<>();
map.put("item", "value"); map.put("item", "value");
assertEquals(false, MapUtils.isEmpty(map)); assertFalse(MapUtils.isEmpty(map));
} }
@Test @Test
public void testIsEmptyWithNull() { public void testIsEmptyWithNull() {
final Map<Object, Object> map = null; final Map<Object, Object> map = null;
assertEquals(true, MapUtils.isEmpty(map)); assertTrue(MapUtils.isEmpty(map));
} }
@Test @Test
public void testIsNotEmptyWithEmptyMap() { public void testIsNotEmptyWithEmptyMap() {
final Map<Object, Object> map = new HashMap<>(); final Map<Object, Object> map = new HashMap<>();
assertEquals(false, MapUtils.isNotEmpty(map)); assertFalse(MapUtils.isNotEmpty(map));
} }
@Test @Test
public void testIsNotEmptyWithNonEmptyMap() { public void testIsNotEmptyWithNonEmptyMap() {
final Map<String, String> map = new HashMap<>(); final Map<String, String> map = new HashMap<>();
map.put("item", "value"); map.put("item", "value");
assertEquals(true, MapUtils.isNotEmpty(map)); assertTrue(MapUtils.isNotEmpty(map));
} }
@Test @Test
public void testIsNotEmptyWithNull() { public void testIsNotEmptyWithNull() {
final Map<Object, Object> map = null; final Map<Object, Object> map = null;
assertEquals(false, MapUtils.isNotEmpty(map)); assertFalse(MapUtils.isNotEmpty(map));
} }
@Test @Test
@ -801,9 +801,9 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals(list.size(), map.size()); assertEquals(list.size(), map.size());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
assertEquals(true, map.containsKey(Integer.valueOf(list.get(i)))); assertTrue(map.containsKey(Integer.valueOf(list.get(i))));
assertEquals(false, map.containsKey(list.get(i))); assertFalse(map.containsKey(list.get(i)));
assertEquals(true, map.containsValue(list.get(i))); assertTrue(map.containsValue(list.get(i)));
assertEquals(list.get(i), map.get(Integer.valueOf(list.get(i)))); assertEquals(list.get(i), map.get(Integer.valueOf(list.get(i))));
} }
@ -813,9 +813,9 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals(list.size(), map.size()); assertEquals(list.size(), map.size());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
assertEquals(true, map.containsKey(Integer.valueOf(list.get(i)))); assertTrue(map.containsKey(Integer.valueOf(list.get(i))));
assertEquals(false, map.containsKey(list.get(i))); assertFalse(map.containsKey(list.get(i)));
assertEquals(true, map.containsValue(Integer.valueOf(list.get(i)))); assertTrue(map.containsValue(Integer.valueOf(list.get(i))));
assertEquals(Integer.valueOf(list.get(i)), map.get(Integer.valueOf(list.get(i)))); assertEquals(Integer.valueOf(list.get(i)), map.get(Integer.valueOf(list.get(i))));
} }
} }
@ -854,8 +854,8 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals(list.size(), map.totalSize()); assertEquals(list.size(), map.totalSize());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
assertEquals(true, map.containsKey(list.get(i).key)); assertTrue(map.containsKey(list.get(i).key));
assertEquals(true, map.containsValue(list.get(i))); assertTrue(map.containsValue(list.get(i)));
} }
} }
@ -1209,7 +1209,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals("str", MapUtils.getString(in, "key", "defualt")); assertEquals("str", MapUtils.getString(in, "key", "defualt"));
assertEquals("str", MapUtils.getString(in, "key")); assertEquals("str", MapUtils.getString(in, "key"));
assertEquals(null, MapUtils.getString(null, "key")); assertNull(MapUtils.getString(null, "key"));
assertEquals("default", MapUtils.getString(in, "noKey", "default")); assertEquals("default", MapUtils.getString(in, "noKey", "default"));
assertEquals("default", MapUtils.getString(in, "noKey", key -> { assertEquals("default", MapUtils.getString(in, "noKey", key -> {
if ("noKey".equals(key)) { if ("noKey".equals(key)) {
@ -1229,7 +1229,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals("str", MapUtils.getObject(in, "key", "defualt")); assertEquals("str", MapUtils.getObject(in, "key", "defualt"));
assertEquals("str", MapUtils.getObject(in, "key")); assertEquals("str", MapUtils.getObject(in, "key"));
assertEquals(null, MapUtils.getObject(null, "key")); assertNull(MapUtils.getObject(null, "key"));
assertEquals("default", MapUtils.getObject(in, "noKey", "default")); assertEquals("default", MapUtils.getObject(in, "noKey", "default"));
assertEquals("default", MapUtils.getObject(null, "noKey", "default")); assertEquals("default", MapUtils.getObject(null, "noKey", "default"));
} }
@ -1251,7 +1251,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertTrue(MapUtils.getBooleanValue(in, "noKey", key -> { assertTrue(MapUtils.getBooleanValue(in, "noKey", key -> {
return true; return true;
})); }));
assertTrue(!MapUtils.getBooleanValue(in, "noKey")); assertFalse(MapUtils.getBooleanValue(in, "noKey"));
assertTrue(MapUtils.getBoolean(in, "key", true)); assertTrue(MapUtils.getBoolean(in, "key", true));
assertTrue(MapUtils.getBoolean(in, "noKey", true)); assertTrue(MapUtils.getBoolean(in, "noKey", true));
assertTrue(MapUtils.getBoolean(in, "noKey", key -> { assertTrue(MapUtils.getBoolean(in, "noKey", key -> {
@ -1266,7 +1266,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertFalse(MapUtils.getBooleanValue(in, "noKey", key -> { assertFalse(MapUtils.getBooleanValue(in, "noKey", key -> {
return null; return null;
})); }));
assertEquals(null, MapUtils.getBoolean(null, "noKey")); assertNull(MapUtils.getBoolean(null, "noKey"));
// Values are Numbers // Values are Numbers
assertFalse(MapUtils.getBoolean(in, "keyNumberFalse")); assertFalse(MapUtils.getBoolean(in, "keyNumberFalse"));
assertTrue(MapUtils.getBoolean(in, "keyNumberTrue")); assertTrue(MapUtils.getBoolean(in, "keyNumberTrue"));
@ -1291,9 +1291,9 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
final Map<?, ?> outValue = MapUtils.getMap(in, "key1", (Map<?, ?>) null); final Map<?, ?> outValue = MapUtils.getMap(in, "key1", (Map<?, ?>) null);
assertEquals("value1", outValue.get("key1")); assertEquals("value1", outValue.get("key1"));
assertEquals(null, outValue.get("key2")); assertNull(outValue.get("key2"));
assertEquals(null, MapUtils.getMap(in, "key2", (Map<?, ?>) null)); assertNull(MapUtils.getMap(in, "key2", (Map<?, ?>) null));
assertEquals(null, MapUtils.getMap(null, "key2", (Map<?, ?>) null)); assertNull(MapUtils.getMap(null, "key2", (Map<?, ?>) null));
} }
@Test @Test