Repository: commons-lang Updated Branches: refs/heads/master 9901bf98e -> e51bd8920
SerializationUtilsTest expected exceptions Use the expected argument of the @Test annotation instead of boiler-plate implementing this behavior with a try-catch-fail construct in order to clean up the code and make it more obvious to the reader. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/1415c9a2 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/1415c9a2 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/1415c9a2 Branch: refs/heads/master Commit: 1415c9a2a6317dbdca6f1fbb530db1f558d9bef5 Parents: aff0fae Author: Allon Mureinik <amure...@redhat.com> Authored: Wed Apr 4 07:07:20 2018 +0300 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Wed Apr 4 09:32:22 2018 +0200 ---------------------------------------------------------------------- .../commons/lang3/SerializationUtilsTest.java | 88 +++++--------------- 1 file changed, 21 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1415c9a2/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java index cd20602..ff65cb4 100644 --- a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -116,16 +115,11 @@ public class SerializationUtilsTest { } } - @Test + @Test(expected = SerializationException.class) public void testSerializeStreamUnserializable() throws Exception { final ByteArrayOutputStream streamTest = new ByteArrayOutputStream(); - try { - iMap.put(new Object(), new Object()); - SerializationUtils.serialize(iMap, streamTest); - } catch (final SerializationException ex) { - return; - } - fail(); + iMap.put(new Object(), new Object()); + SerializationUtils.serialize(iMap, streamTest); } @Test @@ -147,24 +141,14 @@ public class SerializationUtilsTest { } } - @Test + @Test(expected = IllegalArgumentException.class) public void testSerializeStreamObjNull() throws Exception { - try { - SerializationUtils.serialize(iMap, null); - } catch (final IllegalArgumentException ex) { - return; - } - fail(); + SerializationUtils.serialize(iMap, null); } - @Test + @Test(expected = IllegalArgumentException.class) public void testSerializeStreamNullNull() throws Exception { - try { - SerializationUtils.serialize(null, null); - } catch (final IllegalArgumentException ex) { - return; - } - fail(); + SerializationUtils.serialize(null, null); } @Test @@ -230,24 +214,14 @@ public class SerializationUtilsTest { assertNull(test); } - @Test + @Test(expected = IllegalArgumentException.class) public void testDeserializeStreamNull() throws Exception { - try { - SerializationUtils.deserialize((InputStream) null); - } catch (final IllegalArgumentException ex) { - return; - } - fail(); + SerializationUtils.deserialize((InputStream) null); } - @Test + @Test(expected = SerializationException.class) public void testDeserializeStreamBadStream() throws Exception { - try { - SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0])); - } catch (final SerializationException ex) { - return; - } - fail(); + SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0])); } @Test @@ -293,15 +267,10 @@ public class SerializationUtilsTest { } } - @Test + @Test(expected = SerializationException.class) public void testSerializeBytesUnserializable() throws Exception { - try { - iMap.put(new Object(), new Object()); - SerializationUtils.serialize(iMap); - } catch (final SerializationException ex) { - return; - } - fail(); + iMap.put(new Object(), new Object()); + SerializationUtils.serialize(iMap); } @Test @@ -355,24 +324,14 @@ public class SerializationUtilsTest { assertNull(test); } - @Test + @Test(expected = IllegalArgumentException.class) public void testDeserializeBytesNull() throws Exception { - try { - SerializationUtils.deserialize((byte[]) null); - } catch (final IllegalArgumentException ex) { - return; - } - fail(); + SerializationUtils.deserialize((byte[]) null); } - @Test + @Test(expected = SerializationException.class) public void testDeserializeBytesBadStream() throws Exception { - try { - SerializationUtils.deserialize(new byte[0]); - } catch (final SerializationException ex) { - return; - } - fail(); + SerializationUtils.deserialize(new byte[0]); } //----------------------------------------------------------------------- @@ -397,15 +356,10 @@ public class SerializationUtilsTest { assertNull(test); } - @Test + @Test(expected = SerializationException.class) public void testCloneUnserializable() throws Exception { - try { - iMap.put(new Object(), new Object()); - SerializationUtils.clone(iMap); - } catch (final SerializationException ex) { - return; - } - fail(); + iMap.put(new Object(), new Object()); + SerializationUtils.clone(iMap); } @Test