public void execute_detects_no_move_if_baseProjectSnapshot_is_null() {
analysisMetadataHolder.setBaseAnalysis(null);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
+ verifyStatistics(context, null, null);
}
@Test
Component file2 = fileComponent(FILE_2_REF, null);
setFilesInReport(file1, file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
+ verifyStatistics(context, 0, null);
}
@Test
insertFiles( /* no components */);
setFilesInReport();
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
+ verifyStatistics(context, 0, null);
}
@Test
insertFiles(file1.getKey(), file2.getKey());
setFilesInReport(file2, file1);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
+ verifyStatistics(context, 0, null);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT1);
setFilesInReport(file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).containsExactly(file2);
MovedFilesRepository.OriginalFile originalFile = movedFilesRepository.getOriginalFile(file2).get();
assertThat(originalFile.getId()).isEqualTo(dtos[0].getId());
assertThat(originalFile.getKey()).isEqualTo(dtos[0].getDbKey());
assertThat(originalFile.getUuid()).isEqualTo(dtos[0].uuid());
+ verifyStatistics(context, 1, 1);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT1);
setFilesInReport(file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore())
.isGreaterThan(0)
.isLessThan(MIN_REQUIRED_SCORE);
+ verifyStatistics(context, 1, 1);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT_EMPTY);
setFilesInReport(file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero();
+ verifyStatistics(context, 1, 1);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT1);
setFilesInReport(file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix).isNull();
+ verifyStatistics(context, 0, null);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT1);
setFilesInReport(file2);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero();
+ verifyStatistics(context, 1, 1);
}
@Test
insertContentOfFileInDb(file1.getKey(), CONTENT1);
setFilesInReport(file2, file3);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isEqualTo(100);
+ verifyStatistics(context, 1, 2);
}
@Test
insertContentOfFileInDb(file2.getKey(), CONTENT1);
setFilesInReport(file3);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isEqualTo(100);
+ verifyStatistics(context, 2, 1);
}
@Test
insertContentOfFileInDb(file1.getKey(), null);
insertContentOfFileInDb(file2.getKey(), null);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix).isNull();
+ verifyStatistics(context, 2, null);
}
@Test
insertContentOfFileInDb(file5.getKey(), CONTENT2);
setFilesInReport(file3, file4, file6);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).containsOnly(file3, file6);
MovedFilesRepository.OriginalFile originalFile2 = movedFilesRepository.getOriginalFile(file3).get();
assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getDbKey());
assertThat(originalFile5.getUuid()).isEqualTo(dtos[3].uuid());
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isGreaterThan(MIN_REQUIRED_SCORE);
+ verifyStatistics(context, 4, 2);
}
@Test
insertContentOfFileInDb(file2.getKey(), arrayOf(30));
setFilesInReport(file3, file4);
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero();
+ verifyStatistics(context, 2, 2);
}
/**
setFilesInReport(comps.values().toArray(new Component[0]));
- underTest.execute(new TestComputationStepContext());
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
Component makeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex = comps.get("MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java");
Component migrationRb1238 = comps.get("1238_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb");
.isEqualTo("1242_make_analysis_uuid_not_null_on_duplications_index.rb");
assertThat(movedFilesRepository.getOriginalFile(addComponentUuidAndAnalysisUuidColumnToDuplicationsIndex).get().getKey())
.isEqualTo("AddComponentUuidColumnToDuplicationsIndex.java");
+ verifyStatistics(context, 12, 6);
}
private String[] readLines(File filename) throws IOException {
this.scoreMatrix = scoreMatrix;
}
}
+
+ private static void verifyStatistics(TestComputationStepContext context, @Nullable Integer expectedDbFiles, @Nullable Integer expectedAddedFiles) {
+ context.getStatistics().assertValue("dbFiles", expectedDbFiles);
+ context.getStatistics().assertValue("addedFiles", expectedAddedFiles);
+ }
}