diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-27 17:50:38 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-27 17:50:55 +0200 |
commit | ec794baf4fc1cffe4fd15f58081a0dcf23b3748f (patch) | |
tree | 41453b85467f65e6d36cd8f4673a1f62ea35ffa8 | |
parent | 055ca6aaf138acf489063707df70ec95c9899b86 (diff) | |
download | sonarqube-ec794baf4fc1cffe4fd15f58081a0dcf23b3748f.tar.gz sonarqube-ec794baf4fc1cffe4fd15f58081a0dcf23b3748f.zip |
Improve code coverage
3 files changed, 60 insertions, 8 deletions
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java index 36c6dc2677f..0fc741e3910 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java @@ -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")); } diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java index fbcb0c9f216..9196a831ec9 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java @@ -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 index 00000000000..2c523ee3cce --- /dev/null +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/QProfileTest.java @@ -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); + } +} |