@Test public void testFlowWithSingleLocation() throws Exception { List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiple.xoo")); assertThat(issues).hasSize(1); Issue issue = issues.get(0); assertThat(issue.getMsg()).isEqualTo("Primary location"); assertThat(issue.getTextRange().getStartLine()).isEqualTo(6); assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23); assertThat(issue.getTextRange().getEndLine()).isEqualTo(6); assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50); assertThat(issue.getFlowList()).hasSize(1); Flow flow = issue.getFlow(0); assertThat(flow.getLocationList()).hasSize(1); IssueLocation additionalLocation = flow.getLocation(0); assertThat(additionalLocation.getMsg()).isEqualTo("Flow step #1"); assertThat(additionalLocation.getTextRange().getStartLine()).isEqualTo(7); assertThat(additionalLocation.getTextRange().getStartOffset()).isEqualTo(26); assertThat(additionalLocation.getTextRange().getEndLine()).isEqualTo(7); assertThat(additionalLocation.getTextRange().getEndOffset()).isEqualTo(53); }
private Optional<DbIssues.Location> convertLocation(ScannerReport.IssueLocation source) { DbIssues.Location.Builder target = DbIssues.Location.newBuilder(); if (source.getComponentRef() != 0 && source.getComponentRef() != component.getReportAttributes().getRef()) { // SONAR-10781 Component might not exist because on short living branch and PR, only changed components are included in the report Optional<Component> optionalComponent = treeRootHolder.getOptionalComponentByRef(source.getComponentRef()); if (!optionalComponent.isPresent()) { return Optional.empty(); } target.setComponentId(optionalComponent.get().getUuid()); } if (isNotEmpty(source.getMsg())) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { ScannerReport.TextRange sourceRange = source.getTextRange(); DbCommons.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } return Optional.of(target.build()); }
assertThat(issue.hasTextRange()).isFalse(); assertThat(issue.getFlow(0).getLocationCount()).isOne(); assertThat(issue.getFlow(0).getLocation(0).getTextRange().getStartLine()).isOne(); assertThat(issue.getFlow(1).getLocationCount()).isOne(); assertThat(issue.getFlow(1).getLocation(0).getTextRange().getStartLine()).isEqualTo(3);
private Optional<DbIssues.Location> convertLocation(ScannerReport.IssueLocation source) { DbIssues.Location.Builder target = DbIssues.Location.newBuilder(); if (source.getComponentRef() != 0 && source.getComponentRef() != component.getReportAttributes().getRef()) { // SONAR-10781 Component might not exist because on short living branch and PR, only changed components are included in the report Optional<Component> optionalComponent = treeRootHolder.getOptionalComponentByRef(source.getComponentRef()); if (!optionalComponent.isPresent()) { return Optional.empty(); } target.setComponentId(optionalComponent.get().getUuid()); } if (isNotEmpty(source.getMsg())) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { ScannerReport.TextRange sourceRange = source.getTextRange(); DbCommons.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } return Optional.of(target.build()); }