use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ScmInfoRepositoryImplTest method return_empty_if_component_is_not_file.
@Test
public void return_empty_if_component_is_not_file() {
Component c = mock(Component.class);
when(c.getType()).thenReturn(Type.DIRECTORY);
assertThat(underTest.getScmInfo(c)).isEmpty();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class DbLineHashVersionTest method should_cache_line_hash_version_from_db.
@Test
public void should_cache_line_hash_version_from_db() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid(file.uuid()).build();
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
assertThat(db.countRowsOfTable("file_sources")).isOne();
db.executeUpdateSql("delete from file_sources");
db.commit();
assertThat(db.countRowsOfTable("file_sources")).isZero();
// still true because it uses cache
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class DbLineHashVersionTest method hasLineHashWithSignificantCode_should_return_true_if_pr_reference_has_file_and_it_is_in_db.
@Test
public void hasLineHashWithSignificantCode_should_return_true_if_pr_reference_has_file_and_it_is_in_db() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
when(referenceBranchComponentUuids.getComponentUuid("key")).thenReturn(file.uuid());
Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid("123").build();
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
verify(analysisMetadataHolder).isPullRequest();
verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class DbLineHashVersionTest method hasLineHashWithSignificantCode_should_return_false_if_pr_reference_doesnt_have_file.
@Test
public void hasLineHashWithSignificantCode_should_return_false_if_pr_reference_doesnt_have_file() {
when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid("123").build();
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse();
verify(analysisMetadataHolder).isPullRequest();
verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class FileSourceDataWarningsTest method addWarning_fails_with_NPE_if_readError_is_null.
@Test
public void addWarning_fails_with_NPE_if_readError_is_null() {
Component component = mock(Component.class);
assertThatThrownBy(() -> underTest.addWarning(component, null)).isInstanceOf(NullPointerException.class).hasMessage("readError can't be null");
}
Aggregations