@Test public void create_issue() throws Exception { Issue issue = new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setEffort(Duration.create(10L)) .setType(RuleType.BUG) .build(); assertThat(issue.key()).isEqualTo("ABCD"); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("xoo", "S01")); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.status()).isEqualTo(org.sonar.api.issue.Issue.STATUS_RESOLVED); assertThat(issue.resolution()).isEqualTo(org.sonar.api.issue.Issue.RESOLUTION_FIXED); assertThat(issue.effort()).isEqualTo(Duration.create(10L)); }
@Test public void get_issues() throws Exception { Issue issue = new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setEffort(Duration.create(10L)) .setType(RuleType.BUG) .build(); underTest.setIssues(Arrays.asList(issue)); assertThat(underTest.getIssues()).hasSize(1); } }
@Test public void create_issue_with_minimal_fields() throws Exception { Issue issue = new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setType(RuleType.BUG) .build(); assertThat(issue.resolution()).isNull(); assertThat(issue.effort()).isNull(); }
@Test public void fail_with_IAE_when_building_issue_with_invalid_severity() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("severity 'unknown' is invalid"); new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity("unknown") .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); }
@Test public void fail_with_IAE_when_building_issue_with_invalid_status() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("status 'unknown' is invalid"); new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus("unknown") .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); } }
@Test public void fail_with_IAE_when_building_issue_with_invalid_resolution() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("resolution 'unknown' is invalid"); new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution("unknown") .setType(RuleType.BUG) .build(); }
@Test public void fail_with_NPE_when_building_issue_without_status() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("status cannot be null"); new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); }
@Test public void fail_with_NPE_when_building_issue_without_severity() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("severity cannot be null"); new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); }
@Test public void fail_with_NPE_when_building_issue_without_rule_key() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("ruleKey cannot be null"); new TestIssue.Builder() .setKey("ABCD") .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); }
@Test public void fail_with_NPE_when_building_issue_without_key() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("key cannot be null"); new TestIssue.Builder() .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setType(RuleType.BUG) .build(); }