Fixed code formatting and improved test cases
@@ -3,7 +3,7 @@ package com.baeldung.array;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
public class AddElementToEndOfArrayUnitTest {
@@ -21,7 +21,8 @@ public class AddElementToEndOfArrayUnitTest {
Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd);
- assertEquals(elementToAdd, destArray[destArray.length-1].intValue());
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
}
@Test
@@ -31,7 +32,8 @@ public class AddElementToEndOfArrayUnitTest {
Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd);
- assertEquals(elementToAdd, destArray[destArray.length-1].intValue());
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
}
@Test
@@ -41,6 +43,7 @@ public class AddElementToEndOfArrayUnitTest {
Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd);
- assertEquals(elementToAdd, destArray[destArray.length-1].intValue());
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
}
}
