aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-20 18:10:01 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-21 17:03:57 +0200
commit1bb0e1cfd1aa5f2de1d20d6d9a10af3803dde057 (patch)
tree0000a1b57d84753c7a19e811439c57b9a9bafd3b /sonar-core/src/test
parent8a59810c57e65e6dbbe8245dfcbce25e96cd4dc1 (diff)
downloadsonarqube-1bb0e1cfd1aa5f2de1d20d6d9a10af3803dde057.tar.gz
sonarqube-1bb0e1cfd1aa5f2de1d20d6d9a10af3803dde057.zip
add Collectors.join(Joiner)
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java b/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java
index 9bac9ee7d8f..a5d9466a494 100644
--- a/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.core.util.stream;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
@@ -37,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.core.util.stream.Collectors.index;
+import static org.sonar.core.util.stream.Collectors.join;
import static org.sonar.core.util.stream.Collectors.toArrayList;
import static org.sonar.core.util.stream.Collectors.toHashSet;
import static org.sonar.core.util.stream.Collectors.toList;
@@ -351,6 +353,34 @@ public class CollectorsTest {
assertThat(multimap).contains(entry(1, "A"), entry(2, "B"), entry(3, "C"));
}
+ @Test
+ public void join_on_empty_stream_returns_empty_string() {
+ assertThat(Collections.emptyList().stream().collect(join(Joiner.on(",")))).isEmpty();
+ }
+
+ @Test
+ public void join_fails_with_NPE_if_joiner_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("Joiner can't be null");
+
+ join(null);
+ }
+
+ @Test
+ public void join_applies_joiner_to_stream() {
+ assertThat(Arrays.asList("1", "2", "3", "4").stream().collect(join(Joiner.on(","))))
+ .isEqualTo("1,2,3,4");
+ }
+
+ @Test
+ public void join_supports_null_if_joiner_does() {
+ Stream<String> stream = Arrays.asList("1", null).stream();
+
+ expectedException.expect(NullPointerException.class);
+
+ stream.collect(join(Joiner.on(",")));
+ }
+
private void expectedDuplicateKey1IAE() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Duplicate key 1");