Search in sources :

Example 21 with TextBlock

use of org.sonar.server.computation.task.projectanalysis.duplication.TextBlock in project sonarqube by SonarSource.

the class NewSizeMeasuresStepTest method compute_duplicated_blocks_one_for_original_one_for_each_InnerDuplicate.

@Test
public void compute_duplicated_blocks_one_for_original_one_for_each_InnerDuplicate() {
    TextBlock original = new TextBlock(1, 1);
    duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2), new TextBlock(4, 4), new TextBlock(3, 4));
    setChangesets(FILE_1_REF);
    underTest.execute();
    assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
Also used : TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 22 with TextBlock

use of org.sonar.server.computation.task.projectanalysis.duplication.TextBlock in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_duplication.

@Test
public void persist_duplication() {
    initBasicReport(1);
    duplicationRepository.add(FILE_REF, new Duplication(new TextBlock(1, 2), Arrays.<Duplicate>asList(new InnerDuplicate(new TextBlock(3, 4)))));
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getDuplicationList()).hasSize(1);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Duplication(org.sonar.server.computation.task.projectanalysis.duplication.Duplication) InnerDuplicate(org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate) Duplicate(org.sonar.server.computation.task.projectanalysis.duplication.Duplicate) InnerDuplicate(org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate) DbFileSources(org.sonar.db.protobuf.DbFileSources) TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 23 with TextBlock

use of org.sonar.server.computation.task.projectanalysis.duplication.TextBlock in project sonarqube by SonarSource.

the class ReportDuplicationMeasuresStepTest method addDuplicatedBlock.

/**
   * Adds duplication blocks of a single line (each line is specific to its block).
   *
   * This is a very simple use case, convenient for unit tests but more realistic and complex use cases must be tested separately.
   */
private void addDuplicatedBlock(int fileRef, int blockCount) {
    checkArgument(blockCount > 1, "BlockCount can not be less than 2");
    TextBlock original = new TextBlock(1, 1);
    TextBlock[] duplicates = new TextBlock[blockCount - 1];
    for (int i = 10; i < blockCount + 9; i++) {
        duplicates[i - 10] = new TextBlock(i, i);
    }
    duplicationRepository.addDuplication(fileRef, original, duplicates);
}
Also used : TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock)

Example 24 with TextBlock

use of org.sonar.server.computation.task.projectanalysis.duplication.TextBlock in project sonarqube by SonarSource.

the class ReportDuplicationMeasuresStepTest method compute_duplicated_blocks_one_for_original_one_for_each_InnerDuplicate.

@Test
public void compute_duplicated_blocks_one_for_original_one_for_each_InnerDuplicate() {
    TextBlock original = new TextBlock(1, 1);
    duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2), new TextBlock(3, 3), new TextBlock(2, 3));
    underTest.execute();
    assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 4);
}
Also used : TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 25 with TextBlock

use of org.sonar.server.computation.task.projectanalysis.duplication.TextBlock in project sonarqube by SonarSource.

the class ReportDuplicationMeasuresStepTest method compute_duplicated_blocks_one_for_original_and_ignores_InProjectDuplicate.

@Test
public void compute_duplicated_blocks_one_for_original_and_ignores_InProjectDuplicate() {
    duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), FILE_2_REF, new TextBlock(2, 2));
    underTest.execute();
    assertRawMeasureValue(FILE_1_REF, DUPLICATED_BLOCKS_KEY, 1);
}
Also used : TextBlock(org.sonar.server.computation.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Aggregations

TextBlock (org.sonar.server.computation.task.projectanalysis.duplication.TextBlock)26 Test (org.junit.Test)24 DbFileSources (org.sonar.db.protobuf.DbFileSources)1 FileSourceDto (org.sonar.db.source.FileSourceDto)1 CrossProjectDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicate)1 Duplicate (org.sonar.server.computation.task.projectanalysis.duplication.Duplicate)1 Duplication (org.sonar.server.computation.task.projectanalysis.duplication.Duplication)1 InProjectDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InProjectDuplicate)1 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)1