@Test public void should_convert_pmd_violation_to_sonar_violation() { org.sonar.api.rules.Rule sonarRule = createRuleInRuleFinder("RULE"); File file1 = new File("src/source.java"); DefaultInputFile inputFile1 = addToFileSystem(file1); Issuable issuable = createIssuable(inputFile1); RuleViolation pmdViolation = createPmdViolation(file1, 42, "Description", "RULE"); Issue issue = mock(Issue.class); IssueBuilder issueBuilder = mock(IssueBuilder.class); when(issuable.newIssueBuilder()).thenReturn(issueBuilder); when(issueBuilder.ruleKey(sonarRule.ruleKey())).thenReturn(issueBuilder); when(issueBuilder.message("Description")).thenReturn(issueBuilder); when(issueBuilder.line(42)).thenReturn(issueBuilder); when(issueBuilder.build()).thenReturn(issue); pmdViolationRecorder.saveViolation(pmdViolation); verify(issuable).addIssue(issue); verify(issueBuilder).ruleKey(sonarRule.ruleKey()); verify(issueBuilder).message("Description"); verify(issueBuilder).line(42); verify(sonarRule, atLeastOnce()).ruleKey(); }
public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); }
PmdViolationRecorder implements BatchExtension { public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); } }
PmdViolationRecorder implements BatchExtension { public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); } PmdViolationRecorder(FileSystem fs, RuleFinder ruleFinder, ResourcePerspectives perspectives); }
PmdViolationRecorder implements BatchExtension { public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); } PmdViolationRecorder(FileSystem fs, RuleFinder ruleFinder, ResourcePerspectives perspectives); void saveViolation(RuleViolation pmdViolation); }
PmdViolationRecorder implements BatchExtension { public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); } PmdViolationRecorder(FileSystem fs, RuleFinder ruleFinder, ResourcePerspectives perspectives); void saveViolation(RuleViolation pmdViolation);  }