minor cleanup

This commit is contained in:
Eugen Paraschiv 2018-08-30 20:36:27 +03:00
parent 5deb5311f8
commit 201d616c6b
4 changed files with 23 additions and 36 deletions

View File

@ -5,25 +5,22 @@
*/
package com.baeldung.nullsafecollectionstreams;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Stream;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Kwaje Anthony <kwajeanthony@gmail.com>
*/
public class NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest {
private final NullSafeCollectionStreamsUsingJava8OptionalContainer instance =
new NullSafeCollectionStreamsUsingJava8OptionalContainer();
private final NullSafeCollectionStreamsUsingJava8OptionalContainer instance = new NullSafeCollectionStreamsUsingJava8OptionalContainer();
@Test
public void whenCollectionIsNull_thenExpectAnEmptyStream() {
@ -49,5 +46,5 @@ public class NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest {
assertEquals(iter1.next(), iter2.next());
assert !iter1.hasNext() && !iter2.hasNext();
}
}

View File

@ -1,7 +1,6 @@
package com.baeldung.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.time.Clock;
import java.time.Instant;
@ -10,8 +9,6 @@ import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.junit.Test;
public class CurrentDateTimeUnitTest {

View File

@ -1,7 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>java-streams</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@ -15,17 +14,17 @@
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-core -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-core -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -1,15 +1,14 @@
package com.baeldung.stream;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class PrimitiveStreamsUnitTest {
@ -17,7 +16,7 @@ public class PrimitiveStreamsUnitTest {
@Test
public void givenAnArrayOfIntegersWhenMinIsCalledThenCorrectMinIsReturned() {
int[] integers = new int[] {20, 98, 12, 7, 35};
int[] integers = new int[] { 20, 98, 12, 7, 35 };
int min = streams.min(integers); // returns 7
assertEquals(7, min);
@ -66,19 +65,14 @@ public class PrimitiveStreamsUnitTest {
@Test
public void givenAnArrayWhenSumIsCalledThenTheCorrectSumIsReturned() {
int sum = Stream.of(33,45)
.mapToInt(i -> i)
.sum();
int sum = Stream.of(33, 45).mapToInt(i -> i).sum();
assertEquals(78, sum);
}
@Test
public void givenAnIntStreamThenGetTheEvenIntegers() {
List<Integer> evenInts = IntStream.rangeClosed(1, 10)
.filter(i -> i % 2 == 0)
.boxed()
.collect(Collectors.toList());
List<Integer> evenInts = IntStream.rangeClosed(1, 10).filter(i -> i % 2 == 0).boxed().collect(Collectors.toList());
List<Integer> expected = IntStream.of(2, 4, 6, 8, 10).boxed().collect(Collectors.toList());