@Test public void should_pass_checks() throws InvalidBindingException { when(connectedEngine.getState()).thenReturn(ConnectedSonarLintEngine.State.UPDATED); when(connectedEngine.getProjectStorageStatus("project1")).thenReturn(projectOk); globalSettings.setSonarQubeServers(Collections.singletonList(createServer("server1"))); manager = new SonarLintEngineManager(globalSettings, engineFactory); manager.initComponent(); assertThat(manager.getConnectedEngine(notifications, "server1", "project1")).isEqualTo(connectedEngine); verify(engineFactory, Mockito.times(1)).createEngine("server1"); verify(connectedEngine).getState(); }
private static void checkConnectedEngineStatus(ConnectedSonarLintEngine engine, SonarLintProjectNotifications notifications, String serverId, String projectKey) throws InvalidBindingException { // Check if engine's global storage is OK ConnectedSonarLintEngine.State state = engine.getState(); if (state != ConnectedSonarLintEngine.State.UPDATED) { if (state != ConnectedSonarLintEngine.State.NEED_UPDATE) { notifications.notifyServerNotUpdated(); } else if (state != ConnectedSonarLintEngine.State.NEVER_UPDATED) { notifications.notifyServerStorageNeedsUpdate(serverId); } throw new InvalidBindingException("Server is not updated: " + serverId); } // Check if project's storage is OK. Global storage was updated and all project's binding that were open too, // but we might have now opened a new project with a different binding. ProjectStorageStatus moduleStorageStatus = engine.getProjectStorageStatus(projectKey); if (moduleStorageStatus == null) { notifications.notifyModuleInvalid(); throw new InvalidBindingException("Project is bound to a module that doesn't exist: " + projectKey); } else if (moduleStorageStatus.isStale()) { notifications.notifyModuleStale(); throw new InvalidBindingException("Stale module's storage: " + projectKey); } }