Search in sources :

Example 11 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class ScmInfoDbLoaderTest method do_not_read_from_db_on_first_analysis_if_there_is_no_reference_branch.

@Test
public void do_not_read_from_db_on_first_analysis_if_there_is_no_reference_branch() {
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
    analysisMetadataHolder.setBaseAnalysis(null);
    analysisMetadataHolder.setBranch(branch);
    assertThat(underTest.getScmInfo(FILE)).isEmpty();
    assertThat(logTester.logs(TRACE)).isEmpty();
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Test(org.junit.Test)

Example 12 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class ScmInfoDbLoaderTest method read_from_target_if_pullrequest.

@Test
public void read_from_target_if_pullrequest() {
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
    analysisMetadataHolder.setBaseAnalysis(null);
    analysisMetadataHolder.setBranch(branch);
    String targetBranchFileUuid = "targetBranchFileUuid";
    String hash = computeSourceHash(1);
    when(referenceBranchComponentUuids.getComponentUuid(FILE.getDbKey())).thenReturn(targetBranchFileUuid);
    addFileSourceInDb("henry", DATE_1, "rev-1", hash, targetBranchFileUuid);
    DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
    assertThat(scmInfo.getAllChangesets()).hasSize(1);
    assertThat(scmInfo.fileHash()).isEqualTo(hash);
    assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from DB for file 'targetBranchFileUuid'");
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Test(org.junit.Test)

Example 13 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class CrossProjectDuplicationStatusHolderImplTest method newBranch.

private static Branch newBranch(boolean supportsCrossProjectCpd) {
    Branch branch = mock(Branch.class);
    when(branch.supportsCrossProjectCpd()).thenReturn(supportsCrossProjectCpd);
    return branch;
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 14 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class IssueTrackingDelegatorTest method delegate_pull_request_tracker.

@Test
public void delegate_pull_request_tracker() {
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
    when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
    when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
    underTest.track(component, rawInput);
    verify(prBranchTracker).track(component, rawInput);
    verifyNoInteractions(tracker);
    verifyNoInteractions(mergeBranchTracker);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Test(org.junit.Test)

Example 15 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class NewEffortAggregatorTest method no_measures_if_no_periods.

@Test
public void no_measures_if_no_periods() {
    when(newIssueClassifier.isEnabled()).thenReturn(false);
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.BRANCH);
    periodsHolder.setPeriod(null);
    DefaultIssue unresolved = newCodeSmellIssue(10);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, unresolved);
    underTest.afterComponent(FILE);
    assertThat(measureRepository.getRawMeasures(FILE)).isEmpty();
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)40 Test (org.junit.Test)21 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Before (org.junit.Before)5 BranchType (org.sonar.db.component.BranchType)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 DbTester (org.sonar.db.DbTester)4 Project (org.sonar.server.project.Project)4 Date (java.util.Date)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 ComponentTesting (org.sonar.db.component.ComponentTesting)3 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)3 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 RuleKey (org.sonar.api.rule.RuleKey)2