java 8 new tests and quick maven upgrades

This commit is contained in:
eugenp 2014-06-12 20:42:20 +03:00
parent 0e97dc8605
commit 25a64f5d4f
3 changed files with 51 additions and 12 deletions

View File

@ -14,7 +14,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>16.0.1</version> <version>17.0</version>
</dependency> </dependency>
<dependency> <dependency>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.1</version> <version>3.3.2</version>
</dependency> </dependency>
<!-- web --> <!-- web -->
@ -111,35 +111,34 @@
<mysql-connector-java.version>5.1.27</mysql-connector-java.version> <mysql-connector-java.version>5.1.27</mysql-connector-java.version>
<!-- marshalling --> <!-- marshalling -->
<jackson.version>2.3.0</jackson.version> <jackson.version>2.4.0</jackson.version>
<!-- logging --> <!-- logging -->
<org.slf4j.version>1.7.5</org.slf4j.version> <org.slf4j.version>1.7.5</org.slf4j.version>
<logback.version>1.0.11</logback.version> <logback.version>1.0.11</logback.version>
<!-- various --> <!-- various -->
<hibernate-validator.version>5.0.1.Final</hibernate-validator.version> <hibernate-validator.version>5.1.1.Final</hibernate-validator.version>
<!-- util --> <!-- util -->
<guava.version>15.0</guava.version> <guava.version>17.0</guava.version>
<commons-lang3.version>3.1</commons-lang3.version> <commons-lang3.version>3.3.2</commons-lang3.version>
<!-- testing --> <!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version> <org.hamcrest.version>1.3</org.hamcrest.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<mockito.version>1.9.5</mockito.version> <mockito.version>1.9.5</mockito.version>
<httpcore.version>4.3</httpcore.version> <httpcore.version>4.3.2</httpcore.version>
<httpclient.version>4.3.1</httpclient.version> <httpclient.version>4.3.4</httpclient.version>
<rest-assured.version>2.1.0</rest-assured.version> <rest-assured.version>2.3.2</rest-assured.version>
<!-- maven plugins --> <!-- maven plugins -->
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-war-plugin.version>2.4</maven-war-plugin.version> <maven-war-plugin.version>2.4</maven-war-plugin.version>
<maven-surefire-plugin.version>2.16</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version> <maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<cargo-maven2-plugin.version>1.4.5</cargo-maven2-plugin.version>
</properties> </properties>

View File

@ -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<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
final List<Integer> listWithoutNulls = list.parallelStream().filter(i -> i != null).collect(Collectors.toList());
assertThat(listWithoutNulls, hasSize(3));
}
@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());
assertThat(listWithoutNulls, hasSize(3));
}
@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());
assertThat(listWithoutDuplicates, hasSize(3));
}
}

View File

@ -1,6 +1,5 @@
package org.baeldung.java8; package org.baeldung.java8;
import static org.baeldung.java8.entity.Human.compareByNameThenAge;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import java.util.Collections; import java.util.Collections;