File tree Expand file tree Collapse file tree
core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .collections .comparation ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import java .util .ArrayList ;
6+ import java .util .Arrays ;
7+ import java .util .List ;
8+
9+ import static org .assertj .core .api .Assertions .assertThat ;
10+
11+ public class ArrayListUnitTest {
12+
13+ @ Test
14+ void givenList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved () {
15+ List <String > list = new ArrayList <>();
16+ list .add ("Daniel" );
17+ list .add (1 , "Marko" );
18+ assertThat (list ).hasSize (2 );
19+ assertThat (list .get (1 )).isEqualTo ("Marko" );
20+ }
21+
22+ @ Test
23+ void givenList_whenItemRemovedViaIndex_thenListSizeIsReduced () {
24+ List <String > list = new ArrayList <>(Arrays .asList ("Daniel" , "Marko" ));
25+ list .remove (1 );
26+ assertThat (list ).hasSize (1 );
27+ }
28+
29+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .collections .comparation ;
2+
3+ import static org .assertj .core .api .Assertions .*;
4+ import org .junit .jupiter .api .Test ;
5+
6+ import java .util .*;
7+
8+ class ListVsMapUnitTest {
9+
10+ @ Test
11+ void givenList_whenIteratingTroughValues_thenEachValueIsPresent () {
12+ List <String > list = new ArrayList <>();
13+ list .add ("Daniel" );
14+ list .add ("Marko" );
15+ for (String name : list ) {
16+ assertThat (name ).isIn (list );
17+ }
18+ }
19+
20+ @ Test
21+ void givenMap_whenIteratingTroughValues_thenEachValueIsPresent () {
22+ Map <Integer , String > map = new HashMap <>();
23+ map .put (1 , "Daniel" );
24+ map .put (2 , "Marko" );
25+ for (String name : map .values ()) {
26+ assertThat (name ).isIn (map .values ());
27+ }
28+ }
29+
30+ }
You can’t perform that action at this time.
0 commit comments