@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(range(2, 3)).build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); } }
@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { Builder locations = DbIssues.Locations.newBuilder() .setTextRange(range(2, 3)) .addFlow(newFlow(newLocation(4, 5))) .addFlow(newFlow(newLocation(6, 7, COMPONENT_UUID), newLocation(8, 9, COMPONENT_UUID))); when(issue.getLocations()).thenReturn(locations.build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); setDateOfChangetsetAtLine(scmInfo, 4, 1400L); setDateOfChangetsetAtLine(scmInfo, 5, 1500L); // some lines missing should be ok setDateOfChangetsetAtLine(scmInfo, 9, 1900L); } }
@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { Builder locations = DbIssues.Locations.newBuilder() .setTextRange(range(2, 3)) .addFlow(newFlow(newLocation(4, 5))) .addFlow(newFlow(newLocation(6, 7, COMPONENT_UUID), newLocation(8, 9, "another"))); when(issue.getLocations()).thenReturn(locations.build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); setDateOfChangetsetAtLine(scmInfo, 4, 1400L); setDateOfChangetsetAtLine(scmInfo, 5, 1500L); setDateOfChangetsetAtLine(scmInfo, 6, 1600L); setDateOfChangetsetAtLine(scmInfo, 7, 1700L); setDateOfChangetsetAtLine(scmInfo, 8, 1800L); setDateOfChangetsetAtLine(scmInfo, 9, 1900L); } }
issue.setLocations(dbLocationsBuilder.build()); issue.setType(toRuleType(reportIssue.getType()));
issue.setLocations(dbLocationsBuilder.build()); return issue;
.setEndLine(12) .build()) .build(); DefaultIssue base = new DefaultIssue() .setKey("BASE_KEY")
.setEndLine(12) .build()) .build(); DefaultIssue base = new DefaultIssue() .setKey("BASE_KEY")
.setEndLine(12) .build()) .build(); DefaultIssue base = new DefaultIssue() .setKey("BASE_KEY")
.build()))); RuleDefinitionDto rule = newRule().getDefinition(); db.issues().insert(rule, project, file, i -> i.setLocations(locations.build())); indexIssues();
issue.setLocations(dbLocationsBuilder.build()); return issue;
issue.setLocations(dbLocationsBuilder.build()); issue.setType(toRuleType(reportExternalIssue.getType()));
@Test public void allLinesFor_traverses_all_flows() { DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder(); locations.addFlowBuilder() .addLocation(newLocation("file1", 5, 5)) .addLocation(newLocation("file2", 10, 11)) .build(); locations.addFlowBuilder() .addLocation(newLocation("file1", 7, 9)) .addLocation(newLocation("file2", 12, 12)) .build(); DefaultIssue issue = new DefaultIssue().setLocations(locations.build()); assertThat(IssueLocations.allLinesFor(issue, "file1")).containsExactlyInAnyOrder(5, 7, 8, 9); assertThat(IssueLocations.allLinesFor(issue, "file2")).containsExactlyInAnyOrder(10, 11, 12); }
@Test public void allLinesFor_default_component_of_location_is_the_issue_component() { DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder(); locations.addFlowBuilder() .addLocation(newLocation("", 5, 5)) .addLocation(newLocation(null, 7, 7)) .addLocation(newLocation("file2", 9, 9)) .build(); DefaultIssue issue = new DefaultIssue() .setComponentUuid("file1") .setLocations(locations.build()); assertThat(IssueLocations.allLinesFor(issue, "file1")).containsExactlyInAnyOrder(5, 7); assertThat(IssueLocations.allLinesFor(issue, "file2")).containsExactlyInAnyOrder(9); assertThat(IssueLocations.allLinesFor(issue, "file3")).isEmpty(); }
@Test public void allLinesFor_filters_lines_for_specified_component() { DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder(); locations.addFlowBuilder() .addLocation(newLocation("file1", 5, 5)) .addLocation(newLocation("file1", 10, 12)) .addLocation(newLocation("file1", 15, 15)) .addLocation(newLocation("file2", 10, 11)) .build(); DefaultIssue issue = new DefaultIssue().setLocations(locations.build()); assertThat(IssueLocations.allLinesFor(issue, "file1")).containsExactlyInAnyOrder(5, 10, 11, 12, 15); assertThat(IssueLocations.allLinesFor(issue, "file2")).containsExactlyInAnyOrder(10, 11); assertThat(IssueLocations.allLinesFor(issue, "file3")).isEmpty(); }
@Test public void allLinesFor_keeps_duplicated_lines() { DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder(); locations.addFlowBuilder() .addLocation(newLocation("file1", 5, 5)) .addLocation(newLocation("file1", 4, 6)) .build(); DefaultIssue issue = new DefaultIssue().setLocations(locations.build()); assertThat(IssueLocations.allLinesFor(issue, "file1")).containsExactlyInAnyOrder(4, 5, 5, 6); }
private static DefaultIssue newIssueOnLines(int... lines) { DefaultIssue issue = new DefaultIssue(); issue.setComponentUuid(FILE.getUuid()); DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder(); DbIssues.Flow.Builder flow = DbIssues.Flow.newBuilder(); Arrays.stream(lines).forEach(line -> flow.addLocation(newLocation(line))); locations.addFlow(flow.build()); issue.setLocations(locations.build()); return issue; }