minor cleanup

This commit is contained in:
eugenp 2014-06-16 16:51:19 +03:00
parent e60010dd76
commit 89d3f72333
1 changed files with 22 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package org.baeldung.java.collections;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@ -12,10 +14,11 @@ import org.junit.Test;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public class JavaCollectionCleanupUnitTest { public class JavaCollectionCleanupUnitTest {
// removing nulls // tests - removing nulls
@Test @Test
public final void givenListContainsNulls_whenRemovingNullsWithPlainJava_thenCorrect() { public final void givenListContainsNulls_whenRemovingNullsWithPlainJava_thenCorrect() {
@ -50,4 +53,22 @@ public class JavaCollectionCleanupUnitTest {
assertThat(list, hasSize(3)); assertThat(list, hasSize(3));
} }
// tests - remove duplicates
@Test
public final void givenListContainsDuplicates_whenRemovingDuplicatesWithPlainJava_thenCorrect() {
final List<Integer> listWithDuplicates = Lists.newArrayList(0, 1, 2, 3, 0, 0);
final List<Integer> listWithoutDuplicates = new ArrayList<>(new HashSet<>(listWithDuplicates));
assertThat(listWithoutDuplicates, hasSize(4));
}
@Test
public final void givenListContainsDuplicates_whenRemovingDuplicatesWithGuava_thenCorrect() {
final List<Integer> listWithDuplicates = Lists.newArrayList(0, 1, 2, 3, 0, 0);
final List<Integer> listWithoutDuplicates = Lists.newArrayList(Sets.newHashSet(listWithDuplicates));
assertThat(listWithoutDuplicates, hasSize(4));
}
} }