Skip to content

Commit bd8aa6a

Browse files
committed
BAEL-4717: Added ArrayList examples
1 parent 46ad624 commit bd8aa6a

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
 (0)