Package org.sonar.api.rule

Examples of org.sonar.api.rule.RuleKey


  /**
   * SONAR-2900
   */
  @Test
  public void checks_as_objects() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
    builder.create(ruleKey).setParam("pattern", "foo").activate();
    CheckFactory checkFactory = new CheckFactory(builder.build());

    CheckWithStringProperty check = new CheckWithStringProperty();
    Checks checks = checkFactory.create("squid").addAnnotatedChecks(check);
View Full Code Here


    assertThat(patternMatcher.getMatchingPattern(create(CHECKSTYLE_RULE, JAVA_FILE, 5))).isNull();
  }

  private Issue create(Rule rule, String component, Integer line) {
    Issue mockIssue = mock(Issue.class);
    RuleKey ruleKey = null;
    if (rule != null) {
      ruleKey = rule.ruleKey();
    }
    when(mockIssue.ruleKey()).thenReturn(ruleKey);
    when(mockIssue.componentKey()).thenReturn(component);
View Full Code Here

    assertThat(checks.all()).isEmpty();
  }

  @Test
  public void class_name_as_check_key() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithoutProperties");
    builder.create(ruleKey).activate();
    CheckFactory checkFactory = new CheckFactory(builder.build());

    Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithoutProperties.class);
View Full Code Here

    assertThat(checks.ruleKey(check)).isEqualTo(ruleKey);
  }

  @Test
  public void param_as_string_field() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
    builder.create(ruleKey).setParam("pattern", "foo").activate();

    CheckFactory checkFactory = new CheckFactory(builder.build());
    Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
View Full Code Here

  @Test
  public void fail_if_missing_field() {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("The field 'unknown' does not exist or is not annotated with @RuleProperty in the class org.sonar.api.batch.rule.CheckWithStringProperty");

    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
    builder.create(ruleKey).setParam("unknown", "foo").activate();

    CheckFactory checkFactory = new CheckFactory(builder.build());
    checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
  }
View Full Code Here

    checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
  }

  @Test
  public void param_as_primitive_fields() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithPrimitiveProperties");
    builder.create(ruleKey).setParam("max", "300").setParam("ignore", "true").activate();

    CheckFactory checkFactory = new CheckFactory(builder.build());
    Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithPrimitiveProperties.class);
View Full Code Here

  /**
   * SONAR-3164
   */
  @Test
  public void param_as_inherited_field() {
    RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithPrimitiveProperties");
    builder.create(ruleKey).setParam("max", "300").activate();

    CheckFactory checkFactory = new CheckFactory(builder.build());
    Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithPrimitiveProperties.class);

View Full Code Here

    assertThat(new IssuePattern("org.*.??ar", "*").matchResource("plop")).isFalse();
  }

  @Test
  public void shouldMatchRule() {
    RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey();
    assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue();
    assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue();
    assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue();
    assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue();
    assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue();
 
View Full Code Here

    assertThat(pattern.match(create((Rule) null, null, null))).isFalse();
  }

  private Issue create(Rule rule, String component, Integer line) {
    Issue mockIssue = mock(Issue.class);
    RuleKey ruleKey = null;
    if (rule != null) {
      ruleKey = rule.ruleKey();
    }
    when(mockIssue.ruleKey()).thenReturn(ruleKey);
    when(mockIssue.componentKey()).thenReturn(component);
View Full Code Here

  }

  @Test
  public void shouldPassToChainIfRuleDoesNotMatch() {
    String rule = "rule";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);

    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
View Full Code Here

TOP

Related Classes of org.sonar.api.rule.RuleKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.