]> source.dussan.org Git - sonarqube.git/commitdiff
DbTester: add executeInsert with varargs
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 6 Jun 2016 15:11:06 +0000 (17:11 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 13 Jun 2016 06:45:47 +0000 (08:45 +0200)
sonar-db/src/test/java/org/sonar/db/DbTester.java

index 99a17517e07b0fd6cd5cb4bd5a9b75e9323fa25e..31afa94ca3e852f266cbed6a56dc7dc86cb4827e 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.db;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.sql.Clob;
@@ -135,6 +136,23 @@ public class DbTester extends ExternalResource {
     }
   }
 
+  /**
+   * Very simple helper method to insert some data into a table.
+   * It's the responsibility of the caller to convert column values to string.
+   */
+  public void executeInsert(String table, String... valuesByColumn) {
+    executeInsert(table, mapOf(valuesByColumn));
+  }
+
+  private static Map<String, String> mapOf(String... values) {
+    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+    for (int i = 0; i < values.length; i++) {
+      builder.put(values[i], values[i + 1]);
+      i++;
+    }
+    return builder.build();
+  }
+
   /**
    * Very simple helper method to insert some data into a table.
    * It's the responsibility of the caller to convert column values to string.