minor java testing work
This commit is contained in:
parent
bb662b4252
commit
9c3ff77d8f
@ -0,0 +1,53 @@
|
||||
package org.baeldung.java.collections;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.PredicateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class JavaCollectionCleanupUnitTest {
|
||||
|
||||
// removing nulls
|
||||
|
||||
@Test
|
||||
public final void givenListContainsNulls_whenRemovingNullsWithPlainJava_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, null);
|
||||
while (list.remove(null))
|
||||
;
|
||||
|
||||
assertThat(list, hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV1_thenCorrect() {
|
||||
final List<Integer> listWithNulls = Lists.newArrayList(null, 1, null);
|
||||
Iterables.removeIf(listWithNulls, Predicates.isNull());
|
||||
|
||||
assertThat(listWithNulls, hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV2_thenCorrect() {
|
||||
final List<Integer> listWithNulls = Lists.newArrayList(null, 1, null, 2, 3);
|
||||
final List<Integer> listWithoutNulls = Lists.newArrayList(Iterables.filter(listWithNulls, Predicates.notNull()));
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenListContainsNulls_whenRemovingNullsWithCommonsCollections_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
CollectionUtils.filter(list, PredicateUtils.notNullPredicate());
|
||||
|
||||
assertThat(list, hasSize(3));
|
||||
}
|
||||
|
||||
}
|
@ -30,10 +30,10 @@
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -93,7 +93,7 @@
|
||||
<version>1.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- marshalling -->
|
||||
|
||||
<dependency>
|
||||
@ -101,7 +101,7 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- util -->
|
||||
|
||||
<dependency>
|
||||
@ -114,7 +114,31 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<!-- logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
@ -157,16 +181,16 @@
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
@ -247,7 +271,7 @@
|
||||
<maven-war-plugin.version>2.4</maven-war-plugin.version>
|
||||
<maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.4.8</cargo-maven2-plugin.version>
|
||||
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user