aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-29 11:38:54 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-04 15:20:30 +0200
commit57954d360f60214e732aa002f03af12f69e21d49 (patch)
treeea5382b5ffb5dd89c0b5bf90849ca668b18273cc /sonar-core/src/test
parentec7f7285d2f8131e52b3f54494c1e7deb1ff450a (diff)
downloadsonarqube-57954d360f60214e732aa002f03af12f69e21d49.tar.gz
sonarqube-57954d360f60214e732aa002f03af12f69e21d49.zip
add collectors util classes in sonar-core
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java57
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/stream/GuavaCollectorsTest.java59
2 files changed, 116 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
new file mode 100644
index 00000000000..e3bd3c1b101
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util.stream;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CollectorsTest {
+ @Test
+ public void toList_builds_an_ArrayList() {
+ List<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(Collectors.toList());
+ assertThat(res).isInstanceOf(ArrayList.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+ @Test
+ public void toList_with_size_builds_an_ArrayList() {
+ List<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(Collectors.toList(30));
+ assertThat(res).isInstanceOf(ArrayList.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+
+ @Test
+ public void toSet_builds_an_HashSet() {
+ Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(Collectors.toSet());
+ assertThat(res).isInstanceOf(HashSet.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+ @Test
+ public void toSet_with_size_builds_an_ArrayList() {
+ Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(Collectors.toSet(30));
+ assertThat(res).isInstanceOf(HashSet.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/util/stream/GuavaCollectorsTest.java b/sonar-core/src/test/java/org/sonar/core/util/stream/GuavaCollectorsTest.java
new file mode 100644
index 00000000000..2ff0c28fb6a
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/util/stream/GuavaCollectorsTest.java
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util.stream;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GuavaCollectorsTest {
+ @Test
+ public void toList_builds_an_ImmutableList() {
+ List<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(GuavaCollectors.toList());
+ assertThat(res).isInstanceOf(ImmutableList.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+ @Test
+ public void toList_with_size_builds_an_ImmutableList() {
+ List<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(GuavaCollectors.toList(30));
+ assertThat(res).isInstanceOf(ImmutableList.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+
+ @Test
+ public void toSet_builds_an_ImmutableSet() {
+ Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(GuavaCollectors.toSet());
+ assertThat(res).isInstanceOf(ImmutableSet.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+ @Test
+ public void toSet_with_size_builds_an_ImmutableSet() {
+ Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(GuavaCollectors.toSet(30));
+ assertThat(res).isInstanceOf(ImmutableSet.class)
+ .containsExactly(1, 2, 3, 4, 5);
+ }
+
+
+}