Search in sources :

Example 6 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CoverageRuleTest method issue_if_coverage_is_too_low.

@Test
public void issue_if_coverage_is_too_low() {
    activeRuleHolder.put(new ActiveRule(getRuleKey(), Severity.CRITICAL, ImmutableMap.of(getMinPropertyKey(), "65"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getCoverageMetricKey(), Measure.newMeasureBuilder().create(20.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getUncoveredMetricKey(), Measure.newMeasureBuilder().create(40));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getToCoverMetricKey(), Measure.newMeasureBuilder().create(50));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(getRuleKey());
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // FIXME explain
    assertThat(issue.effortToFix()).isEqualTo(23.0);
    assertThat(issue.message()).isEqualTo(getExpectedIssueMessage());
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 7 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CoverageRuleTest method no_issue_if_coverage_is_not_set.

@Test
public void no_issue_if_coverage_is_not_set() {
    activeRuleHolder.put(new ActiveRule(getRuleKey(), Severity.CRITICAL, ImmutableMap.of(getMinPropertyKey(), "65"), 1_000L));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 8 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class SkippedTestRuleTest method no_issues_if_measure_is_absent.

@Test
public void no_issues_if_measure_is_absent() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 9 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CommentDensityRuleTest method fail_if_min_density_is_100.

/**
  * SQALE-110
  */
@Test
public void fail_if_min_density_is_100() {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Minimum density of rule [common-java:InsufficientCommentDensity] is incorrect. Got [100] but must be strictly less than 100.");
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, "100"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(0.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(0));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(1));
    underTest.processFile(FILE, "java");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 10 with ActiveRule

use of org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.

the class CommentDensityRuleTest method issue_if_not_enough_comments__test_ceil.

@Test
public void issue_if_not_enough_comments__test_ceil() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, "25"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(0.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(0));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(1));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // 1 ncloc requires 1 comment line to reach 25% of comment density
    assertThat(issue.effortToFix()).isEqualTo(1.0);
    assertThat(issue.message()).isEqualTo("1 more comment lines need to be written to reach the minimum threshold of 25.0% comment density.");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

ActiveRule (org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)21 Test (org.junit.Test)19 DefaultIssue (org.sonar.core.issue.DefaultIssue)15 RuleKey (org.sonar.api.rule.RuleKey)2 HashMap (java.util.HashMap)1 CheckForNull (javax.annotation.CheckForNull)1