]> source.dussan.org Git - sonarqube.git/commitdiff
Add unit tests
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Feb 2015 09:26:46 +0000 (10:26 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Feb 2015 10:36:37 +0000 (11:36 +0100)
sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java

index db891b609ec852adb0e474d5bf76c9026a56e5d2..03e1d41d380c984de8bc5d74cffb782e6d0ea194 100644 (file)
  */
 package org.sonar.core.persistence;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
 import org.junit.Test;
 
+import java.util.Collections;
 import java.util.List;
 
+import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 
 public class DaoUtilsTest {
 
@@ -38,6 +43,44 @@ public class DaoUtilsTest {
   public void repeatCondition() throws Exception {
     assertThat(DaoUtils.repeatCondition("uuid=?", 1, "or")).isEqualTo("uuid=?");
     assertThat(DaoUtils.repeatCondition("uuid=?", 3, "or")).isEqualTo("uuid=? or uuid=? or uuid=?");
+  }
+
+  @Test
+  public void execute_large_inputs() throws Exception {
+    List<Integer> inputs = newArrayList();
+    List<String> expectedOutputs = newArrayList();
+    for (int i = 0; i < 2010; i++) {
+      inputs.add(i);
+      expectedOutputs.add(Integer.toString(i));
+    }
+
+    List<String> outputs = DaoUtils.executeLargeInputs(inputs, new Function<List<Integer>, List<String>>() {
+      @Override
+      public List<String> apply(List<Integer> input) {
+        // Check that each partition is only done on 1000 elements max
+        assertThat(input.size()).isLessThanOrEqualTo(1000);
+        return newArrayList(Iterables.transform(input, new Function<Integer, String>() {
+          @Override
+          public String apply(Integer input) {
+            return Integer.toString(input);
+          }
+        }));
+      }
+    });
+
+    assertThat(outputs).isEqualTo(expectedOutputs);
+  }
+
+  @Test
+  public void execute_large_inputs_on_empty_list() throws Exception {
+    List<String> outputs = DaoUtils.executeLargeInputs(Collections.<Integer>emptyList(), new Function<List<Integer>, List<String>>() {
+      @Override
+      public List<String> apply(List<Integer> input) {
+        fail("No partition should be made on empty list");
+        return Collections.emptyList();
+      }
+    });
 
+    assertThat(outputs).isEmpty();
   }
 }