Package org.sonar.api.rules

Examples of org.sonar.api.rules.Rule


    assertThat(index.getViolations(ViolationQuery.create().forResource(file).setSwitchMode(ViolationQuery.SwitchMode.OFF))).hasSize(1);
  }

  @Test
  public void should_get_filtered_violation_with_on_switch_mode() {
    Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
    File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
    Violation violation = Violation.create(rule, file).setSwitchedOff(false);

    when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
View Full Code Here


    assertThat(filteredMeasures.hasNext(), is(false));
  }

  @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),
View Full Code Here

    assertThat(filter.filter(measures).getValue(), is(50.0));
  }

  @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),
View Full Code Here

    for (DefaultIssue issue : issueCache.all()) {
      if (issue.isNew() && issue.resolution() == null) {
        newIssues.add(issue);
      }
      if (!issue.isNew() && issue.isChanged() && issue.mustSendNotifications()) {
        Rule rule = ruleFinder.findByKey(issue.ruleKey());
        // TODO warning - rules with status REMOVED are currently ignored, but should not
        if (rule != null) {
          shouldSentNotification.put(issue, rule);
        }
      }
View Full Code Here

    assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse();
  }

  @Test
  public void shouldMatchViolation() {
    Rule rule = Rule.create("checkstyle", "IllegalRegexp", "");
    String javaFile = "org.foo.Bar";

    IssuePattern pattern = new IssuePattern("*", "*");
    pattern.addLine(12);

View Full Code Here

      return null;
    }

    @Override
    public Rule findByKey(RuleKey key) {
      Rule rule = Rule.create().setRepositoryKey(key.repository()).setKey(key.rule());
      rule.setId(200);
      return rule;
    }
View Full Code Here

  DeprecatedViolations deprecatedViolations = new DeprecatedViolations(issueCache, ruleFinder, resourceCache);

  @Test
  public void test_toViolation() throws Exception {
    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles");
    when(ruleFinder.findByKey(ruleKey)).thenReturn(new Rule("squid", "AvoidCycles"));
    when(resourceCache.get("org.apache:struts")).thenReturn(new Project("org.apache:struts"));

    DefaultIssue issue = newIssue(ruleKey);

    Violation violation = deprecatedViolations.toViolation(issue);
View Full Code Here

  }

  @Test
  public void test_get() throws Exception {
    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles");
    when(ruleFinder.findByKey(ruleKey)).thenReturn(new Rule("squid", "AvoidCycles"));
    when(resourceCache.get("org.apache:struts")).thenReturn(new Project("org.apache:struts"));
    when(issueCache.byComponent("org.apache:struts")).thenReturn(Arrays.asList(newIssue(ruleKey)));

    List<Violation> violations = deprecatedViolations.get("org.apache:struts");
View Full Code Here

    Set<Integer> noSonarLines = new HashSet<Integer>();
    noSonarLines.add(31);
    filter.addResource(javaFile, noSonarLines);

    Rule noSonarRule = new Rule("squid", "NoSonarCheck");
    assertThat(filter.isIgnored(new Violation(noSonarRule, javaFile).setLineId(31))).isFalse();

  }
View Full Code Here

  }

  @Test
  public void createCheckWithStringProperty() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", "");
    rule.createParameter("pattern");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("pattern", "foo");
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
View Full Code Here

TOP

Related Classes of org.sonar.api.rules.Rule

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.