File tree Expand file tree Collapse file tree
core-java/src/test/java/com/baeldung/array Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .array ;
2+
3+ import org .junit .Test ;
4+
5+ import java .util .ArrayList ;
6+ import java .util .Arrays ;
7+ import java .util .LinkedList ;
8+ import java .util .List ;
9+
10+ import static org .assertj .core .api .Assertions .assertThat ;
11+
12+ public class RemoveFirstElementUnitTest {
13+
14+ @ Test
15+ public void givenStringArray_whenRemovingFirstElement_thenArrayIsSmallerAndElementRemoved () {
16+ String [] stringArray = {"foo" , "bar" , "baz" };
17+
18+ String [] modifiedArray = Arrays .copyOfRange (stringArray , 1 , stringArray .length );
19+
20+ assertThat (modifiedArray .length ).isEqualTo (2 );
21+ assertThat (modifiedArray [0 ]).isEqualTo ("bar" );
22+ }
23+
24+ @ Test
25+ public void givenArrayList_whenRemovingFirstElement_thenListSmallerAndElementRemoved () {
26+ List <String > stringList = new ArrayList <>(Arrays .asList ("foo" , "bar" , "baz" ));
27+ stringList .remove (0 );
28+
29+ assertThat (stringList .size ()).isEqualTo (2 );
30+ assertThat (stringList .get (0 )).isEqualTo ("bar" );
31+ }
32+
33+ @ Test
34+ public void givenLinkedList_whenRemovingFirstElement_thenListSmallerAndElementRemoved () {
35+ List <String > stringList = new LinkedList <>(Arrays .asList ("foo" , "bar" , "baz" ));
36+ stringList .remove (0 );
37+
38+ assertThat (stringList .size ()).isEqualTo (2 );
39+ assertThat (stringList .get (0 )).isEqualTo ("bar" );
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments