@Test void should_convert_pmd_violation_to_sonar_violation() { final ActiveRule rule = createRuleInActiveRules(); final File file1 = new File("src/source.java"); final DefaultInputFile inputFile1 = addToFileSystem(file1); final RuleViolation pmdViolation = createPmdViolation(file1, "RULE"); final NewIssue newIssue = mock(NewIssue.class); final NewIssueLocation issueLocation = mock(NewIssueLocation.class); when(mockContext.newIssue()).thenReturn(newIssue); when(newIssue.forRule(rule.ruleKey())).thenReturn(newIssue); when(newIssue.newLocation()).thenReturn(issueLocation); when(newIssue.at(issueLocation)).thenReturn(newIssue); when(issueLocation.on(inputFile1)).thenReturn(issueLocation); when(issueLocation.message("Description")).thenReturn(issueLocation); when(issueLocation.at(any(TextRange.class))).thenReturn(issueLocation); pmdViolationRecorder.saveViolation(pmdViolation, mockContext); verify(mockContext).newIssue(); verify(newIssue).save(); }
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);  }