diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml index 33585a5667..7968c26810 100644 --- a/core-java-8/pom.xml +++ b/core-java-8/pom.xml @@ -14,7 +14,7 @@ com.google.guava guava - 16.0.1 + 17.0 @@ -26,7 +26,7 @@ org.apache.commons commons-lang3 - 3.1 + 3.3.2 @@ -111,35 +111,34 @@ 5.1.27 - 2.3.0 + 2.4.0 1.7.5 1.0.11 - 5.0.1.Final + 5.1.1.Final - 15.0 - 3.1 + 17.0 + 3.3.2 1.3 4.11 1.9.5 - 4.3 - 4.3.1 + 4.3.2 + 4.3.4 - 2.1.0 + 2.3.2 3.1 2.4 - 2.16 + 2.17 2.6 - 1.4.5 diff --git a/core-java-8/src/test/java/org/baeldung/java8/Java8CollectionCleanupUnitTest.java b/core-java-8/src/test/java/org/baeldung/java8/Java8CollectionCleanupUnitTest.java new file mode 100644 index 0000000000..acca829b78 --- /dev/null +++ b/core-java-8/src/test/java/org/baeldung/java8/Java8CollectionCleanupUnitTest.java @@ -0,0 +1,41 @@ +package org.baeldung.java8; + +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Test; + +import com.google.common.collect.Lists; + +public class Java8CollectionCleanupUnitTest { + + // tests - + + @Test + public void givenListContainsNulls_whenFilteringParallel_thenCorrect() { + final List list = Lists.newArrayList(null, 1, 2, null, 3, null); + final List listWithoutNulls = list.parallelStream().filter(i -> i != null).collect(Collectors.toList()); + + assertThat(listWithoutNulls, hasSize(3)); + } + + @Test + public void givenListContainsNulls_whenFilteringSerial_thenCorrect() { + final List list = Lists.newArrayList(null, 1, 2, null, 3, null); + final List listWithoutNulls = list.stream().filter(i -> i != null).collect(Collectors.toList()); + + assertThat(listWithoutNulls, hasSize(3)); + } + + @Test + public void givenListContainsDuplicates_whenRemovingDuplicatesWithJava8_thenCorrect() { + final List listWithDuplicates = Lists.newArrayList(1, 1, 2, 2, 3, 3); + final List listWithoutDuplicates = listWithDuplicates.parallelStream().distinct().collect(Collectors.toList()); + + assertThat(listWithoutDuplicates, hasSize(3)); + } + +} diff --git a/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java b/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java index 5398198a7b..f6b89dd4c9 100644 --- a/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java +++ b/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java @@ -1,6 +1,5 @@ package org.baeldung.java8; -import static org.baeldung.java8.entity.Human.compareByNameThenAge; import static org.hamcrest.Matchers.equalTo; import java.util.Collections;