@Test void should_ignore_violation_on_unknown_rule() { final File file1 = new File("test/source.java"); addToFileSystem(file1); final String ruleName = "UNKNOWN"; final RuleViolation pmdViolation = createPmdViolation(file1, ruleName); final RuleKey expectedRuleKey1 = RuleKey.of(PmdConstants.REPOSITORY_KEY, ruleName); final RuleKey expectedRuleKey2 = RuleKey.of(PmdConstants.REPOSITORY_KEY, ruleName); pmdViolationRecorder.saveViolation(pmdViolation, mockContext); verify(spiedFs).inputFile(any(FilePredicate.class)); verify(mockActiveRules).find(expectedRuleKey1); verify(mockActiveRules).find(expectedRuleKey2); verifyNoMoreInteractions(mockContext); }
public void saveViolation(RuleViolation pmdViolation, SensorContext context) { final InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } final RuleKey ruleKey = findActiveRuleKeyFor(pmdViolation); if (ruleKey == null) { return; } final NewIssue issue = context.newIssue() .forRule(ruleKey); final TextRange issueTextRange = TextRangeCalculator.calculate(pmdViolation, inputFile); final NewIssueLocation issueLocation = issue.newLocation() .on(inputFile) .message(pmdViolation.getDescription()) .at(issueTextRange); issue.at(issueLocation) .save(); }
PmdViolationRecorder { public void saveViolation(RuleViolation pmdViolation, SensorContext context) { final InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } final RuleKey ruleKey = findActiveRuleKeyFor(pmdViolation); if (ruleKey == null) { return; } final NewIssue issue = context.newIssue() .forRule(ruleKey); final TextRange issueTextRange = TextRangeCalculator.calculate(pmdViolation, inputFile); final NewIssueLocation issueLocation = issue.newLocation() .on(inputFile) .message(pmdViolation.getDescription()) .at(issueTextRange); issue.at(issueLocation) .save(); } }
PmdViolationRecorder { public void saveViolation(RuleViolation pmdViolation, SensorContext context) { final InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } final RuleKey ruleKey = findActiveRuleKeyFor(pmdViolation); if (ruleKey == null) { return; } final NewIssue issue = context.newIssue() .forRule(ruleKey); final TextRange issueTextRange = TextRangeCalculator.calculate(pmdViolation, inputFile); final NewIssueLocation issueLocation = issue.newLocation() .on(inputFile) .message(pmdViolation.getDescription()) .at(issueTextRange); issue.at(issueLocation) .save(); } PmdViolationRecorder(FileSystem fs, ActiveRules activeRules); }
PmdViolationRecorder { public void saveViolation(RuleViolation pmdViolation, SensorContext context) { final InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } final RuleKey ruleKey = findActiveRuleKeyFor(pmdViolation); if (ruleKey == null) { return; } final NewIssue issue = context.newIssue() .forRule(ruleKey); final TextRange issueTextRange = TextRangeCalculator.calculate(pmdViolation, inputFile); final NewIssueLocation issueLocation = issue.newLocation() .on(inputFile) .message(pmdViolation.getDescription()) .at(issueTextRange); issue.at(issueLocation) .save(); } PmdViolationRecorder(FileSystem fs, ActiveRules activeRules); void saveViolation(RuleViolation pmdViolation, SensorContext context); }
PmdViolationRecorder { public void saveViolation(RuleViolation pmdViolation, SensorContext context) { final InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { return; } final RuleKey ruleKey = findActiveRuleKeyFor(pmdViolation); if (ruleKey == null) { return; } final NewIssue issue = context.newIssue() .forRule(ruleKey); final TextRange issueTextRange = TextRangeCalculator.calculate(pmdViolation, inputFile); final NewIssueLocation issueLocation = issue.newLocation() .on(inputFile) .message(pmdViolation.getDescription()) .at(issueTextRange); issue.at(issueLocation) .save(); } PmdViolationRecorder(FileSystem fs, ActiveRules activeRules); void saveViolation(RuleViolation pmdViolation, SensorContext context);  }