use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class MeasureTest method notEqualRuleMeasures.
@Test
public void notEqualRuleMeasures() {
Measure measure = new Measure(CoreMetrics.VIOLATIONS, 30.0);
RuleMeasure ruleMeasure = new RuleMeasure(CoreMetrics.VIOLATIONS, new Rule("foo", "bar"), RulePriority.CRITICAL, 3);
assertThat(measure.equals(ruleMeasure)).isFalse();
assertThat(ruleMeasure.equals(measure)).isFalse();
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class MeasuresFiltersTest method rule.
@Test
public void rule() {
Rule rule1 = new Rule("pmd", "key1");
Rule rule2 = new Rule("pmd", "key2");
MeasuresFilter<RuleMeasure> filter = MeasuresFilters.rule(CoreMetrics.VIOLATIONS, rule1);
List<Measure> measures = Arrays.asList(RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0), RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0), RuleMeasure.createForRule(CoreMetrics.INFO_VIOLATIONS, rule2, 3.3), RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0), RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0), new Measure(CoreMetrics.VIOLATIONS, 500.0));
assertThat(filter.filter(measures).getValue(), is(50.0));
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class MeasuresFiltersTest method rules.
@Test
public void rules() {
Rule rule1 = new Rule("pmd", "key1");
Rule rule2 = new Rule("pmd", "key2");
MeasuresFilter<Collection<RuleMeasure>> filter = MeasuresFilters.rules(CoreMetrics.VIOLATIONS);
List<Measure> measures = Arrays.asList(RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0), RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0), RuleMeasure.createForRule(CoreMetrics.INFO_VIOLATIONS, rule2, 3.3), RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0), RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0), new Measure(CoreMetrics.VIOLATIONS, 500.0));
assertThat(filter.filter(measures).size(), is(2));
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class RulesProfileTest method fail_to_activate_already_activated_rule.
@Test
public void fail_to_activate_already_activated_rule() {
RulesProfile profile = RulesProfile.create("Default", "java");
Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, null);
try {
profile.activateRule(rule, null);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(MessageException.class).hasMessage("The definition of the profile 'Default' (language 'java') contains multiple occurrences of the 'repo:key1' rule. The plugin which declares this profile should fix this.");
}
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class RulesProfileTest method activateRuleWithSpecificPriority.
@Test
public void activateRuleWithSpecificPriority() {
RulesProfile profile = RulesProfile.create();
Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, RulePriority.MINOR);
assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR);
}
Aggregations