Search in sources :

Example 36 with CloneGroup

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.");
}
Also used : ClonePart(org.sonar.duplications.index.ClonePart) ArrayList(java.util.ArrayList) CloneGroup(org.sonar.duplications.index.CloneGroup) Test(org.junit.Test)

Example 37 with CloneGroup

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.");
}
Also used : Duplication(org.sonar.scanner.protocol.output.ScannerReport.Duplication) ClonePart(org.sonar.duplications.index.ClonePart) ArrayList(java.util.ArrayList) CloneGroup(org.sonar.duplications.index.CloneGroup) Test(org.junit.Test)

Aggregations

CloneGroup (org.sonar.duplications.index.CloneGroup)37 Test (org.junit.Test)30 CloneIndex (org.sonar.duplications.index.CloneIndex)17 Block (org.sonar.duplications.block.Block)16 CloneGroupMatcher.hasCloneGroup (org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup)15 ClonePart (org.sonar.duplications.index.ClonePart)11 MemoryCloneIndex (org.sonar.duplications.index.MemoryCloneIndex)10 ArrayList (java.util.ArrayList)5 File (java.io.File)2 ByteArray (org.sonar.duplications.block.ByteArray)2 PackedMemoryCloneIndex (org.sonar.duplications.index.PackedMemoryCloneIndex)2 Duplication (org.sonar.scanner.protocol.output.ScannerReport.Duplication)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)1