Search in sources :

Example 16 with ActiveRule

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

the class CoverageRuleTest method no_issue_if_enough_coverage.

@Test
public void no_issue_if_enough_coverage() {
    activeRuleHolder.put(new ActiveRule(getRuleKey(), Severity.CRITICAL, ImmutableMap.of(getMinPropertyKey(), "65"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), getCoverageMetricKey(), 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 17 with ActiveRule

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

the class DuplicatedBlockRuleTest method no_issue_if_no_duplicated_blocks.

@Test
public void no_issue_if_no_duplicated_blocks() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.DUPLICATED_BLOCKS_KEY, Measure.newMeasureBuilder().create(0));
    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 18 with ActiveRule

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

the class DuplicatedBlockRuleTest method issue_if_duplicated_blocks.

@Test
public void issue_if_duplicated_blocks() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.DUPLICATED_BLOCKS_KEY, Measure.newMeasureBuilder().create(3));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.effortToFix()).isEqualTo(3.0);
    assertThat(issue.message()).isEqualTo("3 duplicated blocks of code must be removed.");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 19 with ActiveRule

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

the class SkippedTestRuleTest method issue_if_skipped_tests.

@Test
public void issue_if_skipped_tests() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.SKIPPED_TESTS_KEY, Measure.newMeasureBuilder().create(2));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.effortToFix()).isEqualTo(2.0);
    assertThat(issue.message()).isEqualTo("Fix or remove skipped unit tests in file \"FooTest.java\".");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 20 with ActiveRule

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

the class SkippedTestRuleTest method no_issues_if_zero_skipped_tests.

@Test
public void no_issues_if_zero_skipped_tests() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.SKIPPED_TESTS_KEY, Measure.newMeasureBuilder().create(0));
    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)

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