Search in sources :

Example 1 with ProjectBranches

use of org.sonarsource.sonarlint.core.client.api.connected.ProjectBranches in project sonarlint-language-server by SonarSource.

the class WorkspaceFolderBranchManagerTests method didBranchNameChangeBindingPresent.

@Test
void didBranchNameChangeBindingPresent(@TempDir Path gitProjectBasedir) throws Exception {
    String currentBranchName = "some/branch/name";
    try (Git git = Git.init().setInitialBranch("main").setDirectory(gitProjectBasedir.toFile()).call()) {
        Path readme = gitProjectBasedir.resolve("README.txt");
        Files.createFile(readme);
        git.add().addFilepattern("README.txt").call();
        git.commit().setMessage("Initial commit").call();
        git.checkout().setName(currentBranchName).setCreateBranch(true).call();
    }
    var client = mock(SonarLintExtendedLanguageClient.class);
    var bindingManager = mock(ProjectBindingManager.class);
    var underTest = new WorkspaceFolderBranchManager(client, bindingManager, new ImmediateExecutorService());
    var folderUri = gitProjectBasedir.toUri();
    var bindingWrapper = mock(ProjectBindingWrapper.class);
    when(bindingManager.getBinding(folderUri)).thenReturn(Optional.of(bindingWrapper));
    var engine = mock(ConnectedSonarLintEngine.class);
    when(bindingWrapper.getEngine()).thenReturn(engine);
    String projectKey = "project_key";
    when(bindingWrapper.getBinding()).thenReturn(new ProjectBinding(projectKey, null, null));
    when(engine.getServerBranches(projectKey)).thenReturn(new ProjectBranches(Set.of("main", currentBranchName), Optional.of("main")));
    underTest.didBranchNameChange(folderUri, currentBranchName);
    var branchCaptor = ArgumentCaptor.forClass(SonarLintExtendedLanguageClient.ReferenceBranchForFolder.class);
    verify(client).setReferenceBranchNameForFolder(branchCaptor.capture());
    var capturedValue = branchCaptor.getValue();
    assertThat(capturedValue.getFolderUri()).isEqualTo(folderUri.toString());
    assertThat(capturedValue.getBranchName()).isEqualTo(currentBranchName);
}
Also used : Path(java.nio.file.Path) ProjectBinding(org.sonarsource.sonarlint.core.client.api.connected.ProjectBinding) Git(org.eclipse.jgit.api.Git) ProjectBranches(org.sonarsource.sonarlint.core.client.api.connected.ProjectBranches) SonarLintExtendedLanguageClient(org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageClient) ImmediateExecutorService(testutils.ImmediateExecutorService) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)1 Git (org.eclipse.jgit.api.Git)1 Test (org.junit.jupiter.api.Test)1 ProjectBinding (org.sonarsource.sonarlint.core.client.api.connected.ProjectBinding)1 ProjectBranches (org.sonarsource.sonarlint.core.client.api.connected.ProjectBranches)1 SonarLintExtendedLanguageClient (org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageClient)1 ImmediateExecutorService (testutils.ImmediateExecutorService)1