[BAEL-2170] Renamed test and used Collection instead of ArrayList

This commit is contained in:
dupirefr 2018-09-10 20:27:21 +02:00
parent cc0749ce8a
commit a1194fdfbc
2 changed files with 40 additions and 38 deletions

View File

@ -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<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
list.clear();
assertTrue(list.isEmpty());
}
@Test
void givenTwoArrayListsWithCommonElements_whenRemoveAll_thenFirstListMissElementsFromSecondList() {
ArrayList<Integer> firstList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
ArrayList<Integer> secondList = new ArrayList<>(Arrays.asList(3, 4, 5, 6, 7));
firstList.removeAll(secondList);
assertEquals(Arrays.asList(1, 2), firstList);
}
}

View File

@ -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<Integer> collection = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
collection.clear();
assertTrue(collection.isEmpty());
}
@Test
void givenTwoArrayListsWithCommonElements_whenRemoveAll_thenFirstListMissElementsFromSecondList() {
Collection<Integer> firstCollection = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
Collection<Integer> 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);
}
}