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.
This commit is contained in:
Allon Mureinik 2018-04-04 07:10:28 +03:00 committed by pascalschumacher
parent 1415c9a2a6
commit e51bd89201
1 changed files with 5 additions and 12 deletions

View File

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