Search in sources :

Example 6 with NewActiveRule

use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.

the class NewActiveRuleTest method severity_should_have_default_value.

@Test
public void severity_should_have_default_value() {
    NewActiveRule rule = builder.build();
    assertThat(rule.severity).isEqualTo(Severity.defaultSeverity());
}
Also used : NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) Test(org.junit.Test)

Example 7 with NewActiveRule

use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.

the class NewActiveRuleTest method set_param_remove_param_if_value_is_null.

@Test
public void set_param_remove_param_if_value_is_null() {
    NewActiveRule rule = builder.setParam("foo", "bar").setParam("removed", "value").setParam("removed", null).build();
    assertThat(rule.params).isEqualTo(ImmutableMap.of("foo", "bar"));
}
Also used : NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) Test(org.junit.Test)

Example 8 with NewActiveRule

use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.

the class SensorContextTesterTest method testActiveRules.

@Test
public void testActiveRules() {
    NewActiveRule activeRule = new NewActiveRule.Builder().setRuleKey(RuleKey.of("foo", "bar")).build();
    ActiveRules activeRules = new ActiveRulesBuilder().addRule(activeRule).build();
    tester.setActiveRules(activeRules);
    assertThat(tester.activeRules().findAll()).hasSize(1);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ActiveRules(org.sonar.api.batch.rule.ActiveRules) Test(org.junit.Test)

Example 9 with NewActiveRule

use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.

the class CheckFactoryTest method class_name_as_check_key.

@Test
public void class_name_as_check_key() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithoutProperties");
    NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).build();
    builder.addRule(rule);
    CheckFactory checkFactory = new CheckFactory(builder.build());
    Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithoutProperties.class);
    Object check = checks.of(ruleKey);
    assertThat(check).isInstanceOf(CheckWithoutProperties.class);
    assertThat(checks.all()).containsOnly(check);
    assertThat(checks.ruleKey(check)).isEqualTo(ruleKey);
}
Also used : NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) RuleKey(org.sonar.api.rule.RuleKey) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Test(org.junit.Test)

Example 10 with NewActiveRule

use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.

the class CheckFactoryTest method fail_if_field_type_is_not_supported.

@Test
public void fail_if_field_type_is_not_supported() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithUnsupportedPropertyType");
    NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("max", "300").build();
    builder.addRule(rule);
    CheckFactory checkFactory = new CheckFactory(builder.build());
    assertThatThrownBy(() -> checkFactory.create("squid").addAnnotatedChecks(CheckWithUnsupportedPropertyType.class)).isInstanceOf(SonarException.class);
}
Also used : NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) RuleKey(org.sonar.api.rule.RuleKey) Test(org.junit.Test)

Aggregations

NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)24 Test (org.junit.Test)17 RuleKey (org.sonar.api.rule.RuleKey)11 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)9 ActiveRules (org.sonar.api.batch.rule.ActiveRules)7 Map (java.util.Map)3 InputFile (org.sonar.api.batch.fs.InputFile)3 CheckFactory (org.sonar.api.batch.rule.CheckFactory)3 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)3 FileLinesContext (org.sonar.api.measures.FileLinesContext)3 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 RulesProfile (org.sonar.api.profiles.RulesProfile)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 File (java.io.File)1