Search in sources :

Example 61 with Component

use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class TrackerTargetBranchInputFactoryTest method gets_nothing_when_there_is_no_matching_component.

@Test
public void gets_nothing_when_there_is_no_matching_component() {
    Component component = mock(Component.class);
    when(component.getDbKey()).thenReturn(COMPONENT_KEY);
    when(component.getType()).thenReturn(Component.Type.FILE);
    Input<DefaultIssue> input = underTest.createForTargetBranch(component);
    assertThat(input.getIssues()).isEmpty();
    assertThat(input.getLineHashSequence().length()).isZero();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 62 with Component

use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class SourceLinesHashCacheTest method get_throws_ISE_if_not_cached.

@Test
public void get_throws_ISE_if_not_cached() {
    Component component = createComponent(1);
    assertThatThrownBy(() -> underTest.get(component)).isInstanceOf(IllegalStateException.class).hasMessage("Source line hashes for component ReportComponent{ref=1, key='FILE_KEY', type=FILE} not cached");
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 63 with Component

use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class SourceLinesHashCacheTest method should_computeIfAbsent.

@Test
public void should_computeIfAbsent() {
    Component component = createComponent(1);
    Function<Component, List<String>> f = mock(Function.class);
    List<String> list = Collections.singletonList("hash1");
    when(f.apply(component)).thenReturn(list);
    assertThat(underTest.contains(component)).isFalse();
    List<String> returned = underTest.computeIfAbsent(component, f);
    assertThat(returned).isEqualTo(list);
    assertThat(underTest.contains(component)).isTrue();
    returned = underTest.computeIfAbsent(component, f);
    assertThat(returned).isEqualTo(list);
    verify(f).apply(component);
}
Also used : List(java.util.List) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 64 with Component

use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class SourceLinesHashCacheTest method get_returns_value_if_cached.

@Test
public void get_returns_value_if_cached() {
    List<String> list = Collections.singletonList("hash1");
    Component component = createComponent(1);
    underTest.computeIfAbsent(component, c -> list);
    assertThat(underTest.get(component)).isEqualTo(list);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 65 with Component

use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class DbLineHashVersionTest method hasLineHashWithSignificantCode_should_return_true.

@Test
public void hasLineHashWithSignificantCode_should_return_true() {
    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();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

Component (org.sonar.ce.task.projectanalysis.component.Component)118 Test (org.junit.Test)82 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)47 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 ComponentDto (org.sonar.db.component.ComponentDto)25 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)14 DefaultIssue (org.sonar.core.issue.DefaultIssue)14 DbSession (org.sonar.db.DbSession)11 Period (org.sonar.ce.task.projectanalysis.period.Period)8 SnapshotDto (org.sonar.db.component.SnapshotDto)8 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)6 DbClient (org.sonar.db.DbClient)6 List (java.util.List)5 ComputationStep (org.sonar.ce.task.step.ComputationStep)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 DepthTraversalTypeAwareCrawler (org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Map (java.util.Map)3