SerializatoinUtilsTest assertArraysEquals (closes #321) Utilize assertArraysEquals to compare arrays instead of boiler plate implementing it with a for loop.
This change both makes the test code cleaner and improves the output in case of an assertion failure by showing all the differences between the two arrays instead of stopping at the first. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/e51bd892 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/e51bd892 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/e51bd892 Branch: refs/heads/master Commit: e51bd89201477092c32c180e4f8d00569db17ac1 Parents: 1415c9a Author: Allon Mureinik <amure...@redhat.com> Authored: Wed Apr 4 07:10:28 2018 +0300 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Wed Apr 4 09:32:29 2018 +0200 ---------------------------------------------------------------------- .../commons/lang3/SerializationUtilsTest.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e51bd892/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 ff65cb4..000151d 100644 --- a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java @@ -16,6 +16,7 @@ */ package org.apache.commons.lang3; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -110,9 +111,7 @@ public class SerializationUtilsTest { final byte[] testBytes = streamTest.toByteArray(); final byte[] realBytes = streamReal.toByteArray(); assertEquals(testBytes.length, realBytes.length); - for (int i = 0; i < realBytes.length; i++) { - assertEquals(realBytes[i], testBytes[i]); - } + assertArrayEquals(realBytes, testBytes); } @Test(expected = SerializationException.class) @@ -136,9 +135,7 @@ public class SerializationUtilsTest { final byte[] testBytes = streamTest.toByteArray(); final byte[] realBytes = streamReal.toByteArray(); assertEquals(testBytes.length, realBytes.length); - for (int i = 0; i < realBytes.length; i++) { - assertEquals(realBytes[i], testBytes[i]); - } + assertArrayEquals(realBytes, testBytes); } @Test(expected = IllegalArgumentException.class) @@ -262,9 +259,7 @@ public class SerializationUtilsTest { final byte[] realBytes = streamReal.toByteArray(); assertEquals(testBytes.length, realBytes.length); - for (int i = 0; i < realBytes.length; i++) { - assertEquals(realBytes[i], testBytes[i]); - } + assertArrayEquals(realBytes, testBytes); } @Test(expected = SerializationException.class) @@ -285,9 +280,7 @@ public class SerializationUtilsTest { final byte[] realBytes = streamReal.toByteArray(); assertEquals(testBytes.length, realBytes.length); - for (int i = 0; i < realBytes.length; i++) { - assertEquals(realBytes[i], testBytes[i]); - } + assertArrayEquals(realBytes, testBytes); } //-----------------------------------------------------------------------