diff --git a/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllTest.java b/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllTest.java deleted file mode 100644 index 5b9fbc3415..0000000000 --- a/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.list.arraylist; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Unit tests demonstrating differences between ArrayList#clear() and ArrayList#removeAll() - */ -class ClearVsRemoveAllTest { - - /* - * Tests - */ - @Test - void givenArrayListWithElements_whenClear_thenListBecomesEmpty() { - ArrayList list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); - - list.clear(); - - assertTrue(list.isEmpty()); - } - - @Test - void givenTwoArrayListsWithCommonElements_whenRemoveAll_thenFirstListMissElementsFromSecondList() { - ArrayList firstList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); - ArrayList secondList = new ArrayList<>(Arrays.asList(3, 4, 5, 6, 7)); - - firstList.removeAll(secondList); - - assertEquals(Arrays.asList(1, 2), firstList); - } - -} diff --git a/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllUnitTest.java b/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllUnitTest.java new file mode 100644 index 0000000000..5e31a326b8 --- /dev/null +++ b/core-java-collections/src/test/java/com/baeldung/list/arraylist/ClearVsRemoveAllUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.list.arraylist; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Unit tests demonstrating differences between ArrayList#clear() and ArrayList#removeAll() + */ +class ClearVsRemoveAllUnitTest { + + /* + * Tests + */ + @Test + void givenArrayListWithElements_whenClear_thenListBecomesEmpty() { + Collection collection = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); + + collection.clear(); + + assertTrue(collection.isEmpty()); + } + + @Test + void givenTwoArrayListsWithCommonElements_whenRemoveAll_thenFirstListMissElementsFromSecondList() { + Collection firstCollection = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); + Collection secondCollection = new ArrayList<>(Arrays.asList(3, 4, 5, 6, 7)); + + firstCollection.removeAll(secondCollection); + + assertEquals(Arrays.asList(1, 2), firstCollection); + assertEquals(Arrays.asList(3, 4, 5, 6, 7), secondCollection); + } + +}