SerializationUtilsTest identity assertions

Replaced calls to assertTrue with a != condition with calls to
assertNotSame calls.
This change retains the functionality, but will produce a more
detailed error message in case the assertion fails.
It also (arguably) makes the test code more straight-forward.
This commit is contained in:
Allon Mureinik 2018-04-04 06:58:09 +03:00 committed by pascalschumacher
parent 9901bf98e4
commit aff0fae2ec
1 changed files with 10 additions and 9 deletions

View File

@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -197,12 +198,12 @@ public void testDeserializeStream() throws Exception {
final Object test = SerializationUtils.deserialize(inTest); final Object test = SerializationUtils.deserialize(inTest);
assertNotNull(test); assertNotNull(test);
assertTrue(test instanceof HashMap<?, ?>); assertTrue(test instanceof HashMap<?, ?>);
assertTrue(test != iMap); assertNotSame(test, iMap);
final HashMap<?, ?> testMap = (HashMap<?, ?>) test; final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
assertEquals(iString, testMap.get("FOO")); assertEquals(iString, testMap.get("FOO"));
assertTrue(iString != testMap.get("FOO")); assertNotSame(iString, testMap.get("FOO"));
assertEquals(iInteger, testMap.get("BAR")); assertEquals(iInteger, testMap.get("BAR"));
assertTrue(iInteger != testMap.get("BAR")); assertNotSame(iInteger, testMap.get("BAR"));
assertEquals(iMap, testMap); assertEquals(iMap, testMap);
} }
@ -333,12 +334,12 @@ public void testDeserializeBytes() throws Exception {
final Object test = SerializationUtils.deserialize(streamReal.toByteArray()); final Object test = SerializationUtils.deserialize(streamReal.toByteArray());
assertNotNull(test); assertNotNull(test);
assertTrue(test instanceof HashMap<?, ?>); assertTrue(test instanceof HashMap<?, ?>);
assertTrue(test != iMap); assertNotSame(test, iMap);
final HashMap<?, ?> testMap = (HashMap<?, ?>) test; final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
assertEquals(iString, testMap.get("FOO")); assertEquals(iString, testMap.get("FOO"));
assertTrue(iString != testMap.get("FOO")); assertNotSame(iString, testMap.get("FOO"));
assertEquals(iInteger, testMap.get("BAR")); assertEquals(iInteger, testMap.get("BAR"));
assertTrue(iInteger != testMap.get("BAR")); assertNotSame(iInteger, testMap.get("BAR"));
assertEquals(iMap, testMap); assertEquals(iMap, testMap);
} }
@ -381,12 +382,12 @@ public void testClone() throws Exception {
final Object test = SerializationUtils.clone(iMap); final Object test = SerializationUtils.clone(iMap);
assertNotNull(test); assertNotNull(test);
assertTrue(test instanceof HashMap<?,?>); assertTrue(test instanceof HashMap<?,?>);
assertTrue(test != iMap); assertNotSame(test, iMap);
final HashMap<?, ?> testMap = (HashMap<?, ?>) test; final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
assertEquals(iString, testMap.get("FOO")); assertEquals(iString, testMap.get("FOO"));
assertTrue(iString != testMap.get("FOO")); assertNotSame(iString, testMap.get("FOO"));
assertEquals(iInteger, testMap.get("BAR")); assertEquals(iInteger, testMap.get("BAR"));
assertTrue(iInteger != testMap.get("BAR")); assertNotSame(iInteger, testMap.get("BAR"));
assertEquals(iMap, testMap); assertEquals(iMap, testMap);
} }