Search in sources :

Example 11 with ActiveRule

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

the class CommonRuleTest method getMinDensityParam_fails_if_param_value_is_negative.

@Test
public void getMinDensityParam_fails_if_param_value_is_negative() {
    assertThatThrownBy(() -> {
        ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "-30.5"), 1_000L, PLUGIN_KEY, QP_KEY);
        CommonRule.getMinDensityParam(activeRule, "minDensity");
    }).isInstanceOf(IllegalStateException.class).hasMessage("Minimum density of rule [xoo:x1] is incorrect. Got [-30.5] but must be between 0 and 100.");
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 12 with ActiveRule

use of org.sonar.ce.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() {
    assertThatThrownBy(() -> {
        ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "305"), 1_000L, PLUGIN_KEY, QP_KEY);
        CommonRule.getMinDensityParam(activeRule, "minDensity");
    }).isInstanceOf(IllegalStateException.class).hasMessage("Minimum density of rule [xoo:x1] is incorrect. Got [305] but must be between 0 and 100.");
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) Test(org.junit.Test)

Example 13 with ActiveRule

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

the class CommonRuleTest method test_getMinDensityParam.

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

Example 14 with ActiveRule

use of org.sonar.ce.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() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.emptyMap(), 1_000L, PLUGIN_KEY, QP_KEY));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 15 with ActiveRule

use of org.sonar.ce.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, PLUGIN_KEY, QP_KEY));
    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.gap()).isEqualTo(23.0);
    assertThat(issue.message()).isEqualTo(getExpectedIssueMessage());
}
Also used : ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

ActiveRule (org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule)21 Test (org.junit.Test)17 DefaultIssue (org.sonar.core.issue.DefaultIssue)13 RuleKey (org.sonar.api.rule.RuleKey)2 HashMap (java.util.HashMap)1 CheckForNull (javax.annotation.CheckForNull)1 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)1