Refactor Java8CollectionCleanupUnitTest
This commit is contained in:
parent
c89db35aaa
commit
c9bc20ecd3
|
@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
@ -16,7 +17,9 @@ public class Java8CollectionCleanupUnitTest {
|
|||
@Test
|
||||
public void givenListContainsNulls_whenFilteringParallel_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
final List<Integer> listWithoutNulls = list.parallelStream().filter(i -> i != null).collect(Collectors.toList());
|
||||
final List<Integer> listWithoutNulls = list.parallelStream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
|
@ -24,7 +27,9 @@ public class Java8CollectionCleanupUnitTest {
|
|||
@Test
|
||||
public void givenListContainsNulls_whenFilteringSerial_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
final List<Integer> listWithoutNulls = list.stream().filter(i -> i != null).collect(Collectors.toList());
|
||||
final List<Integer> listWithoutNulls = list.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
|
@ -32,7 +37,7 @@ public class Java8CollectionCleanupUnitTest {
|
|||
@Test
|
||||
public void givenListContainsNulls_whenRemovingNullsWithRemoveIf_thenCorrect() {
|
||||
final List<Integer> listWithoutNulls = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
listWithoutNulls.removeIf(p -> p == null);
|
||||
listWithoutNulls.removeIf(Objects::isNull);
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
|
@ -40,7 +45,9 @@ public class Java8CollectionCleanupUnitTest {
|
|||
@Test
|
||||
public void givenListContainsDuplicates_whenRemovingDuplicatesWithJava8_thenCorrect() {
|
||||
final List<Integer> listWithDuplicates = Lists.newArrayList(1, 1, 2, 2, 3, 3);
|
||||
final List<Integer> listWithoutDuplicates = listWithDuplicates.parallelStream().distinct().collect(Collectors.toList());
|
||||
final List<Integer> listWithoutDuplicates = listWithDuplicates.parallelStream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutDuplicates, hasSize(3));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue