Skip to content

Commit ba7efbc

Browse files
kiviewKevinGilmore
authored andcommitted
Example for removing first element of array (BAEL-2029) (eugenp#4970)
* Example for removing first element of array (BAEL-2029) * Use AssertJ assertions * Move array test to collections module. * Remove redundant test
1 parent 65cd3b3 commit ba7efbc

2 files changed

Lines changed: 11 additions & 42 deletions

File tree

core-java-collections/src/test/java/com/baeldung/list/removefirst/RemoveFirstElementUnitTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.hamcrest.Matchers.*;
55

66
import java.util.ArrayList;
7+
import java.util.Arrays;
78
import java.util.LinkedList;
89
import java.util.List;
910

@@ -48,4 +49,14 @@ public void givenLinkedList_whenRemoveFirst_thenRemoved() {
4849
assertThat(linkedList, not(contains("cat")));
4950
}
5051

52+
@Test
53+
public void givenStringArray_whenRemovingFirstElement_thenArrayIsSmallerAndElementRemoved() {
54+
String[] stringArray = {"foo", "bar", "baz"};
55+
56+
String[] modifiedArray = Arrays.copyOfRange(stringArray, 1, stringArray.length);
57+
58+
assertThat(modifiedArray.length, is(2));
59+
assertThat(modifiedArray[0], is("bar"));
60+
}
61+
5162
}

core-java/src/test/java/com/baeldung/array/RemoveFirstElementUnitTest.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)