adding alternative to remove nulls for list

This commit is contained in:
eugenp 2015-01-01 15:00:28 +02:00
parent b089214ba6
commit f4758569a7
1 changed files with 9 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -29,6 +30,14 @@ public class JavaCollectionCleanupUnitTest {
assertThat(list, hasSize(1));
}
@Test
public final void givenListContainsNulls_whenRemovingNullsWithPlainJavaAlternative_thenCorrect() {
final List<Integer> list = Lists.newArrayList(null, 1, null);
list.removeAll(Collections.singleton(null));
assertThat(list, hasSize(1));
}
@Test
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV1_thenCorrect() {
final List<Integer> list = Lists.newArrayList(null, 1, null);