Search in sources :

Example 1 with DiagnosticService

use of org.springframework.ide.vscode.commons.languageserver.DiagnosticService in project sts4 by spring-projects.

the class MavenProjectCacheTest method testErrorLoadingProject.

@Test
public void testErrorLoadingProject() throws Exception {
    Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/empty-boot-project-with-classpath-file").toURI());
    Path cacheFolder = testProjectPath.resolve(IJavaProject.PROJECT_CACHE_FOLDER);
    AtomicBoolean progressDone = new AtomicBoolean();
    ProgressService progressService = mock(ProgressService.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            progressDone.set(true);
            return null;
        }
    }).when(progressService).progressEvent(any(String.class), (String) isNull());
    when(server.getProgressService()).thenReturn(progressService);
    DiagnosticService diagnosticService = mock(DiagnosticService.class);
    when(server.getDiagnosticService()).thenReturn(diagnosticService);
    MavenProjectCache cache = new MavenProjectCache(server, MavenCore.getDefault(), true, cacheFolder);
    MavenJavaProject project = cache.project(pomFile);
    assertTrue(project.getClasspath().getClasspathEntries().isEmpty());
    CompletableFuture.runAsync(() -> {
        while (!progressDone.get()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).get(30, TimeUnit.SECONDS);
    progressDone.set(false);
    verify(diagnosticService, never()).diagnosticEvent(any(ShowMessageException.class));
    writeContent(pomFile, "");
    fileObserver.notifyFileChanged(pomFile.toURI().toString());
    CompletableFuture.runAsync(() -> {
        while (!progressDone.get()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).get(30, TimeUnit.SECONDS);
    progressDone.set(false);
    verify(diagnosticService, times(1)).diagnosticEvent(any(ShowMessageException.class));
    assertTrue(project.getClasspath().getClasspathEntries().isEmpty());
    assertFalse(cacheFolder.resolve(ClasspathFileBasedCache.CLASSPATH_DATA_CACHE_FILE).toFile().exists());
}
Also used : Path(java.nio.file.Path) ShowMessageException(org.springframework.ide.vscode.commons.languageserver.util.ShowMessageException) DiagnosticService(org.springframework.ide.vscode.commons.languageserver.DiagnosticService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProjectCache(org.springframework.ide.vscode.commons.maven.java.MavenProjectCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DiagnosticService (org.springframework.ide.vscode.commons.languageserver.DiagnosticService)1 ProgressService (org.springframework.ide.vscode.commons.languageserver.ProgressService)1 ShowMessageException (org.springframework.ide.vscode.commons.languageserver.util.ShowMessageException)1 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)1 MavenProjectCache (org.springframework.ide.vscode.commons.maven.java.MavenProjectCache)1