|
3 | 3 | import org.junit.Before;
|
4 | 4 | import org.junit.Test;
|
5 | 5 |
|
6 |
| -import static org.junit.Assert.assertEquals; |
| 6 | +import static org.junit.Assert.assertArrayEquals; |
7 | 7 |
|
8 | 8 | public class AddElementToEndOfArrayUnitTest {
|
9 | 9 |
|
10 | 10 | AddElementToEndOfArray addElementToEndOfArray;
|
11 | 11 |
|
12 | 12 | @Before
|
13 |
| - public void init(){ |
| 13 | + public void init() { |
14 | 14 | addElementToEndOfArray = new AddElementToEndOfArray();
|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | @Test
|
18 |
| - public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded(){ |
19 |
| - Integer[] sourceArray = {1,2,3,4}; |
| 18 | + public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded() { |
| 19 | + Integer[] sourceArray = {1, 2, 3, 4}; |
20 | 20 | int elementToAdd = 5;
|
21 | 21 |
|
22 | 22 | Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd);
|
23 | 23 |
|
24 |
| - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); |
| 24 | + Integer[] expectedArray = {1, 2, 3, 4, 5}; |
| 25 | + assertArrayEquals(expectedArray, destArray); |
25 | 26 | }
|
26 | 27 |
|
27 | 28 | @Test
|
28 |
| - public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded(){ |
29 |
| - Integer[] sourceArray = {1,2,3,4}; |
| 29 | + public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded() { |
| 30 | + Integer[] sourceArray = {1, 2, 3, 4}; |
30 | 31 | int elementToAdd = 5;
|
31 | 32 |
|
32 | 33 | Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd);
|
33 | 34 |
|
34 |
| - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); |
| 35 | + Integer[] expectedArray = {1, 2, 3, 4, 5}; |
| 36 | + assertArrayEquals(expectedArray, destArray); |
35 | 37 | }
|
36 | 38 |
|
37 | 39 | @Test
|
38 |
| - public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded(){ |
39 |
| - Integer[] sourceArray = {1,2,3,4}; |
| 40 | + public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded() { |
| 41 | + Integer[] sourceArray = {1, 2, 3, 4}; |
40 | 42 | int elementToAdd = 5;
|
41 | 43 |
|
42 | 44 | Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd);
|
43 | 45 |
|
44 |
| - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); |
| 46 | + Integer[] expectedArray = {1, 2, 3, 4, 5}; |
| 47 | + assertArrayEquals(expectedArray, destArray); |
45 | 48 | }
|
46 | 49 | }
|
0 commit comments