diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java index 935be19e74..4041ff1637 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ArrayListUnitTest { @Test - void givenList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { + void givenArrayList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { List list = new ArrayList<>(); list.add("Daniel"); list.add(1, "Marko"); @@ -20,10 +20,11 @@ public class ArrayListUnitTest { } @Test - void givenList_whenItemRemovedViaIndex_thenListSizeIsReduced() { + void givenArrayList_whenItemRemovedViaIndex_thenListSizeIsReduced() { List list = new ArrayList<>(Arrays.asList("Daniel", "Marko")); list.remove(1); assertThat(list).hasSize(1); + assertThat(list).doesNotContain("Marko"); } } diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java new file mode 100644 index 0000000000..3b595472e0 --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.collections.comparation; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HashMapUnitTest { + + @Test + void givenHashMap_whenItemAddedByKey_thenItCanBeRetrieved() { + Map map = new HashMap<>(); + map.put("123456", "Daniel"); + map.put("654321", "Marko"); + assertThat(map.get("654321")).isEqualTo("Marko"); + } + + @Test + void givenHashMap_whenItemRemovedByKey_thenMapSizeIsReduced() { + Map map = new HashMap<>(); + map.put("123456", "Daniel"); + map.put("654321", "Marko"); + map.remove("654321"); + assertThat(map).hasSize(1); + } + +} diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java new file mode 100644 index 0000000000..c2ab554c91 --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.collections.comparation; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class LinkedListUnitTest { + + @Test + void givenLinkedList_whenItemIsAppended_thenItCanBeRetrieved() { + LinkedList list = new LinkedList<>(); + list.addLast("Daniel"); + list.addFirst( "Marko"); + assertThat(list).hasSize(2); + assertThat(list.getLast()).isEqualTo("Daniel"); + } + + @Test + void givenLinkedList_whenItemIsRemoved_thenListSizeIsReduced() { + LinkedList list = new LinkedList<>(Arrays.asList("Daniel", "Marko", "David")); + list.removeFirst(); + list.removeLast(); + assertThat(list).hasSize(1); + assertThat(list).containsExactly("Marko"); + } + + @Test + void givenLinkedList_whenItemInserted_thenItCanBeRetrievedAndDeleted() { + LinkedList list = new LinkedList<>(); + list.push("Daniel"); + list.push("Marko"); + assertThat(list.poll()).isEqualTo("Marko"); + assertThat(list).hasSize(1); + } + +} diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java index 6507013fbf..dd6bf760fd 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java @@ -15,6 +15,7 @@ class ListVsMapUnitTest { for (String name : list) { assertThat(name).isIn(list); } + assertThat(list).containsExactly("Daniel", "Marko"); } @Test @@ -25,6 +26,7 @@ class ListVsMapUnitTest { for (String name : map.values()) { assertThat(name).isIn(map.values()); } + assertThat(map.values()).containsExactlyInAnyOrder("Daniel", "Marko"); } }