diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-08-21 17:15:40 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-08-21 17:15:40 +0200 |
commit | ac37e02d6d3d99e3e6acd3557e9a3fc202fe742f (patch) | |
tree | 58c10adcf0b8cafd13092eec4a03965506805c03 /sonar-plugin-api | |
parent | 7fb8d5ab68f92fc0e9ca123c635ef687cab1bf16 (diff) | |
download | sonarqube-ac37e02d6d3d99e3e6acd3557e9a3fc202fe742f.tar.gz sonarqube-ac37e02d6d3d99e3e6acd3557e9a3fc202fe742f.zip |
Add some unit tests
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java | 6 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java | 74 |
2 files changed, 80 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java index 35ddc491194..4fb8450de13 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java @@ -50,6 +50,7 @@ public class IssueQueryTest { .assigned(true) .createdAfter(new Date()) .createdBefore(new Date()) + .createdAt(new Date()) .planned(true) .resolved(true) .sort(IssueQuery.SORT_BY_ASSIGNEE) @@ -71,6 +72,7 @@ public class IssueQueryTest { assertThat(query.actionPlans()).containsOnly("AP1", "AP2"); assertThat(query.createdAfter()).isNotNull(); assertThat(query.createdBefore()).isNotNull(); + assertThat(query.createdAt()).isNotNull(); assertThat(query.planned()).isTrue(); assertThat(query.resolved()).isTrue(); assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_ASSIGNEE); @@ -84,11 +86,15 @@ public class IssueQueryTest { public void should_build_query_without_dates() throws Exception { IssueQuery query = IssueQuery.builder() .issueKeys(newArrayList("ABCDE")) + .createdAfter(null) + .createdBefore(null) + .createdAt(null) .build(); assertThat(query.issueKeys()).containsOnly("ABCDE"); assertThat(query.createdAfter()).isNull(); assertThat(query.createdBefore()).isNull(); + assertThat(query.createdAt()).isNull(); } @Test diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java index b50e7f32594..40646371131 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java @@ -22,8 +22,11 @@ package org.sonar.api.issue.internal; import com.google.common.collect.ImmutableMap; import org.apache.commons.lang.StringUtils; import org.junit.Test; +import org.sonar.api.issue.Issue; import org.sonar.api.issue.IssueComment; +import org.sonar.api.rule.RuleKey; +import java.text.SimpleDateFormat; import java.util.List; import static org.fest.assertions.Assertions.assertThat; @@ -35,6 +38,77 @@ public class DefaultIssueTest { DefaultIssue issue = new DefaultIssue(); @Test + public void test_setters_and_getters() throws Exception { + issue.setKey("ABCD") + .setComponentKey("org.sample.Sample") + .setProjectKey("Sample") + .setRuleKey(RuleKey.of("squid", "S100")) + .setSeverity("MINOR") + .setManualSeverity(true) + .setMessage("a message") + .setLine(7) + .setEffortToFix(1.2d) + .setActionPlanKey("BCDE") + .setStatus(Issue.STATUS_CLOSED) + .setResolution(Issue.RESOLUTION_FIXED) + .setReporter("simon") + .setAssignee("julien") + .setAuthorLogin("steph") + .setChecksum("c7b5db46591806455cf082bb348631e8") + .setNew(true) + .setEndOfLife(true) + .setOnDisabledRule(true) + .setChanged(true) + .setSendNotifications(true) + .setCreationDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19")) + .setUpdateDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-20")) + .setCloseDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-21")) + .setSelectedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-22")) + ; + + assertThat(issue.key()).isEqualTo("ABCD"); + assertThat(issue.componentKey()).isEqualTo("org.sample.Sample"); + assertThat(issue.projectKey()).isEqualTo("Sample"); + assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("squid", "S100")); + assertThat(issue.severity()).isEqualTo("MINOR"); + assertThat(issue.manualSeverity()).isTrue(); + assertThat(issue.message()).isEqualTo("a message"); + assertThat(issue.line()).isEqualTo(7); + assertThat(issue.effortToFix()).isEqualTo(1.2d); + assertThat(issue.actionPlanKey()).isEqualTo("BCDE"); + assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED); + assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED); + assertThat(issue.reporter()).isEqualTo("simon"); + assertThat(issue.assignee()).isEqualTo("julien"); + assertThat(issue.authorLogin()).isEqualTo("steph"); + assertThat(issue.checksum()).isEqualTo("c7b5db46591806455cf082bb348631e8"); + assertThat(issue.isNew()).isTrue(); + assertThat(issue.isEndOfLife()).isTrue(); + assertThat(issue.isOnDisabledRule()).isTrue(); + assertThat(issue.isChanged()).isTrue(); + assertThat(issue.mustSendNotifications()).isTrue(); + assertThat(issue.creationDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19")); + assertThat(issue.updateDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-20")); + assertThat(issue.closeDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-21")); + assertThat(issue.selectedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-22")); + } + + @Test + public void should_set_empty_dates() throws Exception { + issue + .setCreationDate(null) + .setUpdateDate(null) + .setCloseDate(null) + .setSelectedAt(null) + ; + + assertThat(issue.creationDate()).isNull(); + assertThat(issue.updateDate()).isNull(); + assertThat(issue.closeDate()).isNull(); + assertThat(issue.selectedAt()).isNull(); + } + + @Test public void test_attributes() throws Exception { assertThat(issue.attribute("foo")).isNull(); issue.setAttribute("foo", "bar"); |