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);
}
Aggregations