use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class CpdExecutorTest method should_limit_number_of_clones.
@Test
public void should_limit_number_of_clones() {
// 1 origin part + 101 duplicates = 102
List<CloneGroup> dups = new ArrayList<>(CpdExecutor.MAX_CLONE_GROUP_PER_FILE + 1);
for (int i = 0; i < CpdExecutor.MAX_CLONE_GROUP_PER_FILE + 1; i++) {
ClonePart clonePart = new ClonePart(batchComponent1.key(), i, i, i + 1);
ClonePart dupPart = new ClonePart(batchComponent1.key(), i + 1, i + 1, i + 2);
dups.add(newCloneGroup(clonePart, dupPart));
}
executor.saveDuplications(batchComponent1, dups);
assertThat(reader.readComponentDuplications(batchComponent1.scannerId())).toIterable().hasSize(CpdExecutor.MAX_CLONE_GROUP_PER_FILE);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Too many duplication groups on file " + batchComponent1 + ". Keep only the first " + CpdExecutor.MAX_CLONE_GROUP_PER_FILE + " groups.");
}
use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class CpdExecutorTest method should_limit_number_of_references.
@Test
public void should_limit_number_of_references() {
// 1 origin part + 101 duplicates = 102
List<ClonePart> parts = new ArrayList<>(CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2);
for (int i = 0; i < CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2; i++) {
parts.add(new ClonePart(batchComponent1.key(), i, i, i + 1));
}
List<CloneGroup> groups = Collections.singletonList(CloneGroup.builder().setLength(0).setOrigin(parts.get(0)).setParts(parts).build());
executor.saveDuplications(batchComponent1, groups);
Duplication[] dups = readDuplications(1);
assertThat(dups[0].getDuplicateList()).hasSize(CpdExecutor.MAX_CLONE_PART_PER_GROUP);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Too many duplication references on file " + batchComponent1 + " for block at line 0. Keep only the first " + CpdExecutor.MAX_CLONE_PART_PER_GROUP + " references.");
}
Aggregations