]> source.dussan.org Git - sonarqube.git/commitdiff
Improve code coverage
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 27 Aug 2014 15:50:38 +0000 (17:50 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 27 Aug 2014 15:50:55 +0000 (17:50 +0200)
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/QProfileTest.java [new file with mode: 0644]

index 36c6dc2677f174dec01bd0580f0bb293522c0ed0..0fc741e39108a691d81dad37d29267692a2735aa 100644 (file)
@@ -56,6 +56,14 @@ public class GlobalReferentialsTest {
     assertThat(metric.id()).isEqualTo(1);
     assertThat(metric.key()).isEqualTo("ncloc");
     assertThat(metric.valueType()).isEqualTo("DATA");
+    assertThat(metric.description()).isEqualTo("Description");
+    assertThat(metric.direction()).isEqualTo(-1);
+    assertThat(metric.name()).isEqualTo("NCLOC");
+    assertThat(metric.isQualitative()).isTrue();
+    assertThat(metric.isUserManaged()).isFalse();
+    assertThat(metric.worstValue()).isEqualTo(2.0);
+    assertThat(metric.bestValue()).isEqualTo(1.0);
+    assertThat(metric.isOptimizedBestValue()).isTrue();
 
     assertThat(ref.globalSettings()).includes(MapAssert.entry("prop", "value"));
   }
index fbcb0c9f2160e1319c9a69eb615a10867d2a4457..9196a831ec97289ddf360dd8c63908aa0c419bdd 100644 (file)
@@ -24,6 +24,7 @@ import org.json.JSONException;
 import org.junit.Test;
 import org.skyscreamer.jsonassert.JSONAssert;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.HashMap;
 
@@ -34,10 +35,19 @@ public class ProjectReferentialsTest {
   @Test
   public void testToJson() throws Exception {
     ProjectReferentials ref = new ProjectReferentials();
+    assertThat(ref.settings("foo")).isEmpty();
+
     ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984")));
-    ref.addSettings("foo", new HashMap<String, String>());
+    HashMap<String, String> settings = new HashMap<String, String>();
+    settings.put("prop1", "value1");
+    ref.addSettings("foo", settings);
+    settings = new HashMap<String, String>();
+    settings.put("prop2", "value2");
+    ref.addSettings("foo", settings);
     ref.settings("foo").put("prop", "value");
-    ref.addActiveRule(new ActiveRule("repo", "rule", "Rule", "MAJOR", "rule", "java"));
+    ActiveRule activeRule = new ActiveRule("repo", "rule", "Rule", "MAJOR", "rule", "java");
+    activeRule.addParam("param1", "value1");
+    ref.addActiveRule(activeRule);
     ref.setTimestamp(10);
 
     System.out.println(ref.toJson());
@@ -45,22 +55,33 @@ public class ProjectReferentialsTest {
       .assertEquals(
         "{timestamp:10,"
           + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
-          + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
-          + "settingsByModule:{foo:{prop:value}}}",
+          + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
+          + "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}}}",
         ref.toJson(), true);
   }
 
   @Test
-  public void testFromJson() throws JSONException {
+  public void testFromJson() throws JSONException, ParseException {
     ProjectReferentials ref = ProjectReferentials.fromJson("{timestamp:1,"
       + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
-      + "activeRules:[{repositoryKey:repo,ruleKey:rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
+      + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
       + "settingsByModule:{foo:{prop:value}}}");
 
     assertThat(ref.timestamp()).isEqualTo(1);
 
-    assertThat(ref.activeRules().iterator().next().ruleKey()).isEqualTo("rule");
-    assertThat(ref.qProfiles().iterator().next().name()).isEqualTo("Java");
+    ActiveRule activeRule = ref.activeRules().iterator().next();
+    assertThat(activeRule.ruleKey()).isEqualTo("rule");
+    assertThat(activeRule.repositoryKey()).isEqualTo("repo");
+    assertThat(activeRule.name()).isEqualTo("Rule");
+    assertThat(activeRule.severity()).isEqualTo("MAJOR");
+    assertThat(activeRule.internalKey()).isEqualTo("rule1");
+    assertThat(activeRule.language()).isEqualTo("java");
+    assertThat(activeRule.params()).includes(MapAssert.entry("param1", "value1"));
+    assertThat(activeRule.param("param1")).isEqualTo("value1");
+    QProfile qProfile = ref.qProfiles().iterator().next();
+    assertThat(qProfile.key()).isEqualTo("squid-java");
+    assertThat(qProfile.name()).isEqualTo("Java");
+    assertThat(qProfile.rulesUpdatedAt()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"));
     assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value"));
   }
 }
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/QProfileTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/QProfileTest.java
new file mode 100644 (file)
index 0000000..2c523ee
--- /dev/null
@@ -0,0 +1,23 @@
+package org.sonar.batch.protocol.input;
+
+import org.junit.Test;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class QProfileTest {
+
+  @Test
+  public void testEqualsAndHashCode() throws ParseException {
+    QProfile qProfile1 = new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"));
+    QProfile qProfile2 = new QProfile("squid-java", "Java 2", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1985"));
+
+    assertThat(qProfile1.equals(qProfile1)).isTrue();
+    assertThat(qProfile1.equals("foo")).isFalse();
+    assertThat(qProfile1.equals(qProfile2)).isTrue();
+
+    assertThat(qProfile1.hashCode()).isEqualTo(148572637);
+  }
+}