Skip to content

Commit 9c3ff77

Browse files
author
eugenp
committed
minor java testing work
1 parent bb662b4 commit 9c3ff77

2 files changed

Lines changed: 94 additions & 17 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.baeldung.java.collections;
2+
3+
import static org.hamcrest.Matchers.hasSize;
4+
import static org.junit.Assert.assertThat;
5+
6+
import java.util.List;
7+
8+
import org.apache.commons.collections4.CollectionUtils;
9+
import org.apache.commons.collections4.PredicateUtils;
10+
import org.junit.Test;
11+
12+
import com.google.common.base.Predicates;
13+
import com.google.common.collect.Iterables;
14+
import com.google.common.collect.Lists;
15+
16+
public class JavaCollectionCleanupUnitTest {
17+
18+
// removing nulls
19+
20+
@Test
21+
public final void givenListContainsNulls_whenRemovingNullsWithPlainJava_thenCorrect() {
22+
final List<Integer> list = Lists.newArrayList(null, 1, null);
23+
while (list.remove(null))
24+
;
25+
26+
assertThat(list, hasSize(1));
27+
}
28+
29+
@Test
30+
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV1_thenCorrect() {
31+
final List<Integer> listWithNulls = Lists.newArrayList(null, 1, null);
32+
Iterables.removeIf(listWithNulls, Predicates.isNull());
33+
34+
assertThat(listWithNulls, hasSize(1));
35+
}
36+
37+
@Test
38+
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV2_thenCorrect() {
39+
final List<Integer> listWithNulls = Lists.newArrayList(null, 1, null, 2, 3);
40+
final List<Integer> listWithoutNulls = Lists.newArrayList(Iterables.filter(listWithNulls, Predicates.notNull()));
41+
42+
assertThat(listWithoutNulls, hasSize(3));
43+
}
44+
45+
@Test
46+
public final void givenListContainsNulls_whenRemovingNullsWithCommonsCollections_thenCorrect() {
47+
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
48+
CollectionUtils.filter(list, PredicateUtils.notNullPredicate());
49+
50+
assertThat(list, hasSize(3));
51+
}
52+
53+
}

‎spring-security-rest/pom.xml‎

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
<artifactId>spring-core</artifactId>
3131
<version>${org.springframework.version}</version>
3232
<exclusions>
33-
<exclusion>
34-
<artifactId>commons-logging</artifactId>
35-
<groupId>commons-logging</groupId>
36-
</exclusion>
33+
<exclusion>
34+
<artifactId>commons-logging</artifactId>
35+
<groupId>commons-logging</groupId>
36+
</exclusion>
3737
</exclusions>
3838
</dependency>
3939
<dependency>
@@ -93,15 +93,15 @@
9393
<version>1.2</version>
9494
<scope>runtime</scope>
9595
</dependency>
96-
96+
9797
<!-- marshalling -->
9898

9999
<dependency>
100100
<groupId>com.fasterxml.jackson.core</groupId>
101101
<artifactId>jackson-databind</artifactId>
102102
<version>2.2.2</version>
103103
</dependency>
104-
104+
105105
<!-- util -->
106106

107107
<dependency>
@@ -114,7 +114,31 @@
114114
<artifactId>commons-lang3</artifactId>
115115
<version>3.1</version>
116116
</dependency>
117+
<!-- logging -->
117118

119+
<dependency>
120+
<groupId>org.slf4j</groupId>
121+
<artifactId>slf4j-api</artifactId>
122+
<version>${org.slf4j.version}</version>
123+
</dependency>
124+
<dependency>
125+
<groupId>ch.qos.logback</groupId>
126+
<artifactId>logback-classic</artifactId>
127+
<version>${logback.version}</version>
128+
<!-- <scope>runtime</scope> -->
129+
</dependency>
130+
<dependency>
131+
<groupId>org.slf4j</groupId>
132+
<artifactId>jcl-over-slf4j</artifactId>
133+
<version>${org.slf4j.version}</version>
134+
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
135+
</dependency>
136+
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
137+
<groupId>org.slf4j</groupId>
138+
<artifactId>log4j-over-slf4j</artifactId>
139+
<version>${org.slf4j.version}</version>
140+
</dependency>
141+
118142
<!-- test scoped -->
119143

120144
<dependency>
@@ -157,16 +181,16 @@
157181

158182
<plugins>
159183

160-
<plugin>
161-
<groupId>org.apache.maven.plugins</groupId>
162-
<artifactId>maven-compiler-plugin</artifactId>
163-
<version>3.1</version>
164-
<configuration>
165-
<source>1.7</source>
166-
<target>1.7</target>
167-
</configuration>
168-
</plugin>
169-
184+
<plugin>
185+
<groupId>org.apache.maven.plugins</groupId>
186+
<artifactId>maven-compiler-plugin</artifactId>
187+
<version>3.1</version>
188+
<configuration>
189+
<source>1.7</source>
190+
<target>1.7</target>
191+
</configuration>
192+
</plugin>
193+
170194
<plugin>
171195
<groupId>org.apache.maven.plugins</groupId>
172196
<artifactId>maven-war-plugin</artifactId>
@@ -247,7 +271,7 @@
247271
<maven-war-plugin.version>2.4</maven-war-plugin.version>
248272
<maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
249273
<cargo-maven2-plugin.version>1.4.8</cargo-maven2-plugin.version>
250-
274+
251275
</properties>
252276

253277
</project>

0 commit comments

Comments
 (0)