diff options
author | lukasz-jarocki-sonarsource <77498856+lukasz-jarocki-sonarsource@users.noreply.github.com> | 2022-02-22 14:02:49 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-22 20:02:46 +0000 |
commit | dc26d2b53d3d862109116b7f1b153998cac61449 (patch) | |
tree | 8cff9e32f7c316420cc77ba86bb3b91ed98ff25a /server/sonar-webserver-pushapi/src/test | |
parent | 60c1a4038e041a342dda9810e6fd761d66b01bdb (diff) | |
download | sonarqube-dc26d2b53d3d862109116b7f1b153998cac61449.tar.gz sonarqube-dc26d2b53d3d862109116b7f1b153998cac61449.zip |
SONAR-15919 fixed starting of Data Center edition with server push feature (#5459)
Diffstat (limited to 'server/sonar-webserver-pushapi/src/test')
-rw-r--r-- | server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java index 208fa45715f..0e222a9aeb0 100644 --- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java +++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java @@ -35,8 +35,10 @@ import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.pushapi.qualityprofile.StandaloneRuleActivatorEventsDistributor; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -56,12 +58,13 @@ public class SonarLintClientsRegistryTest { private final ServletOutputStream outputStream = mock(ServletOutputStream.class); private final SonarLintClientPermissionsValidator permissionsValidator = mock(SonarLintClientPermissionsValidator.class); + private final StandaloneRuleActivatorEventsDistributor eventsDistributor = mock(StandaloneRuleActivatorEventsDistributor.class); private SonarLintClientsRegistry underTest; @Before public void before() { - underTest = new SonarLintClientsRegistry(mock(StandaloneRuleActivatorEventsDistributor.class), permissionsValidator); + underTest = new SonarLintClientsRegistry(eventsDistributor, permissionsValidator); } @Test @@ -191,6 +194,32 @@ public class SonarLintClientsRegistryTest { verify(sonarLintClient, times(2)).close(); } + @Test + public void registerClient_whenCalledFirstTime_registerAlsoToListenToEvents() { + underTest.registerClient(createSampleSLClient()); + + verify(eventsDistributor).subscribe(underTest); + } + + @Test + public void registerClient_whenCalledSecondTime_doNotRegisterToEvents() { + underTest.registerClient(createSampleSLClient()); + clearInvocations(eventsDistributor); + + underTest.registerClient(createSampleSLClient()); + verifyNoInteractions(eventsDistributor); + } + + @Test + public void registerClient_whenExceptionAndCalledSecondTime_registerToEvents() { + doThrow(new RuntimeException()).when(eventsDistributor).subscribe(any()); + underTest.registerClient(createSampleSLClient()); + clearInvocations(eventsDistributor); + + underTest.registerClient(createSampleSLClient()); + verify(eventsDistributor).subscribe(underTest); + } + private SonarLintClient createSampleSLClient() { SonarLintClient mock = mock(SonarLintClient.class); when(mock.getLanguages()).thenReturn(Set.of("java")); |