Search in sources :

Example 11 with ActiveRule

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

the class CommentDensityRuleTest method no_issues_if_enough_comments.

@Test
public void no_issues_if_enough_comments() {
    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(90.0, 1));
    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 12 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
public void issue_if_not_enough_comments() {
    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(10.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(40));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(360));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // min_comments = (min_percent * ncloc) / (1 - min_percent)
    // -> threshold of 25% for 360 ncloc is 120 comment lines. 40 are already written.
    assertThat(issue.effortToFix()).isEqualTo(120.0 - 40.0);
    assertThat(issue.message()).isEqualTo("80 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)

Example 13 with ActiveRule

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

the class TestErrorRuleTest method no_issues_if_test_measures_are_absent.

@Test
public void no_issues_if_test_measures_are_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 14 with ActiveRule

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

the class CommonRuleTest method test_getMinDensityParam.

@Test
public void test_getMinDensityParam() throws Exception {
    ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "30.5"), 1_000L);
    double minDensity = CommonRule.getMinDensityParam(activeRule, "minDensity");
    assertThat(minDensity).isEqualTo(30.5);
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 15 with ActiveRule

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

the class CommonRuleTest method getMinDensityParam_fails_if_param_value_is_greater_than_100.

@Test
public void getMinDensityParam_fails_if_param_value_is_greater_than_100() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Minimum density of rule [xoo:x1] is incorrect. Got [305] but must be between 0 and 100.");
    ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "305"), 1_000L);
    CommonRule.getMinDensityParam(activeRule, "minDensity");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) 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