Skip to content

Commit

Permalink
SLLS-226 throw exception if automatic connection setup was stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Aug 28, 2024
1 parent d2d9ffa commit 4e34cd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ public AssistCreatingConnectionResponse assistCreatingConnection(AssistCreatingC
var serverProductName = isSonarCloud ? "SonarCloud" : "SonarQube";
client.showMessage(new MessageParams(MessageType.Info, format("Connection to %s was successfully created.", serverProductName)));
backendServiceFacade.getBackendService().didChangeConnections(currentConnections);
return new AssistCreatingConnectionResponse(newConnectionId);
} else {
throw new CancellationException("Automatic connection setup was cancelled");
}
return new AssistCreatingConnectionResponse(newConnectionId);
}).join();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.awaitility.Awaitility;
Expand Down Expand Up @@ -128,6 +129,7 @@
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -489,11 +491,11 @@ void assistCreateConnectionShouldCallClientMethod_noTokenCase() {
var assistCreatingConnectionParams = new AssistCreatingConnectionParams(new SonarQubeConnectionParams(serverUrl, null, null));
when(client.workspaceFolders()).thenReturn(CompletableFuture.completedFuture(List.of()));
when(client.assistCreatingConnection(any())).thenReturn(CompletableFuture.completedFuture(
new AssistCreatingConnectionResponse(null)
null
));
when(settingsManager.getCurrentSettings()).thenReturn(mock(WorkspaceSettings.class));
when(backendServiceFacade.getBackendService()).thenReturn(mock(BackendService.class));
underTest.assistCreatingConnection(assistCreatingConnectionParams, null);
assertThrows(CompletionException.class, () -> underTest.assistCreatingConnection(assistCreatingConnectionParams, null));

var argCaptor = ArgumentCaptor.forClass(CreateConnectionParams.class);
verify(client).assistCreatingConnection(argCaptor.capture());
Expand Down

0 comments on commit 4e34cd6

Please sign in to comment.