Search in sources :

Example 11 with TextBlock

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

the class DuplicationLineReaderTest method read_duplication_with_duplicates_on_other_file.

@Test
public void read_duplication_with_duplicates_on_other_file() {
    DuplicationLineReader reader = duplicationLineReader(duplication(1, 2, new InProjectDuplicate(fileComponent(1).build(), new TextBlock(3, 4))));
    assertThat(reader.read(line1)).isEmpty();
    assertThat(reader.read(line2)).isEmpty();
    assertThat(reader.read(line3)).isEmpty();
    assertThat(reader.read(line4)).isEmpty();
    assertThat(line1.getDuplicationList()).containsExactly(1);
    assertThat(line2.getDuplicationList()).containsExactly(1);
    assertThat(line3.getDuplicationList()).isEmpty();
    assertThat(line4.getDuplicationList()).isEmpty();
}
Also used : InProjectDuplicate(org.sonar.ce.task.projectanalysis.duplication.InProjectDuplicate) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 12 with TextBlock

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

the class NewSizeMeasuresStepTest method compute_duplicated_lines_counts_lines_from_original_and_ignores_CrossProjectDuplicate.

@Test
public void compute_duplicated_lines_counts_lines_from_original_and_ignores_CrossProjectDuplicate() {
    TextBlock original = new TextBlock(1, 1);
    duplicationRepository.addCrossProjectDuplication(FILE_1_REF, original, SOME_FILE_KEY, new TextBlock(2, 2));
    setNewLines(FILE_1);
    underTest.execute(new TestComputationStepContext());
    assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 13 with TextBlock

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

the class NewSizeMeasuresStepTest method compute_duplicated_lines_counts_lines_from_original_and_InnerDuplicate.

@Test
public void compute_duplicated_lines_counts_lines_from_original_and_InnerDuplicate() {
    TextBlock original = new TextBlock(1, 5);
    duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(10, 11));
    setNewLines(FILE_1);
    underTest.execute(new TestComputationStepContext());
    assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 14 with TextBlock

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

the class NewSizeMeasuresStepTest method compute_duplicated_blocks_does_not_count_blocks_only_once_it_assumes_consistency_from_duplication_data.

@Test
public void compute_duplicated_blocks_does_not_count_blocks_only_once_it_assumes_consistency_from_duplication_data() {
    duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), new TextBlock(4, 4));
    duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(2, 2), new TextBlock(4, 4));
    setNewLines(FILE_1);
    underTest.execute(new TestComputationStepContext());
    assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Example 15 with TextBlock

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

the class PersistDuplicationDataStepTest method compute_duplications_on_unchanged_file.

@Test
public void compute_duplications_on_unchanged_file() {
    duplicationRepository.addExtendedProjectDuplication(FILE_1_REF, new TextBlock(1, 5), FILE_2_REF, new TextBlock(6, 10));
    TestComputationStepContext context = new TestComputationStepContext();
    underTest().execute(context);
    assertThat(selectMeasureData(FILE_1_UUID)).hasValue("<duplications><g><b s=\"1\" l=\"5\" t=\"false\" r=\"" + FILE_1_KEY + "\"/><b s=\"6\" l=\"5\" t=\"true\" r=\"" + FILE_2_KEY + "\"/></g></duplications>");
    assertThat(selectMeasureData(FILE_2_UUID)).isEmpty();
    assertThat(selectMeasureData(PROJECT_UUID)).isEmpty();
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock) Test(org.junit.Test)

Aggregations

TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)17 Test (org.junit.Test)15 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)13 ArrayList (java.util.ArrayList)1 CrossProjectDuplicate (org.sonar.ce.task.projectanalysis.duplication.CrossProjectDuplicate)1 Duplication (org.sonar.ce.task.projectanalysis.duplication.Duplication)1 InProjectDuplicate (org.sonar.ce.task.projectanalysis.duplication.InProjectDuplicate)1