-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 522 - Allow custom notifications
Fixes #522 Signed-off-by: Victor Rubezhny <[email protected]>
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JavaModelEventProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.core.ElementChangedEvent; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IElementChangedListener; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.IPackageFragment; | ||
import org.eclipse.jdt.core.IPackageFragmentRoot; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.ls.core.internal.handlers.DocumentLifeCycleHandler; | ||
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest; | ||
import org.eclipse.jdt.ls.core.internal.preferences.Preferences; | ||
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.Severity; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class JavaModelEventProviderTest extends AbstractProjectsManagerBasedTest { | ||
private DocumentLifeCycleHandler lifeCycleHandler; | ||
private JavaClientConnection javaClient; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
mockPreferences(); | ||
|
||
javaClient = new JavaClientConnection(client); | ||
lifeCycleHandler = new DocumentLifeCycleHandler(javaClient, preferenceManager, projectsManager, false); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
javaClient.disconnect(); | ||
for (ICompilationUnit cu : JavaCore.getWorkingCopies(null)) { | ||
cu.discardWorkingCopy(); | ||
} | ||
} | ||
|
||
private Preferences mockPreferences() { | ||
Preferences mockPreferences = Mockito.mock(Preferences.class); | ||
Mockito.when(preferenceManager.getPreferences()).thenReturn(mockPreferences); | ||
Mockito.when(preferenceManager.getPreferences(Mockito.any())).thenReturn(mockPreferences); | ||
Mockito.when(mockPreferences.getIncompleteClasspathSeverity()).thenReturn(Severity.ignore); | ||
return mockPreferences; | ||
} | ||
|
||
@Test | ||
public void testSendNotification() throws Exception { | ||
JavaCore.addElementChangedListener(new IElementChangedListener() { | ||
|
||
@Override | ||
public void elementChanged(ElementChangedEvent event) { | ||
client.notify("notify", event); | ||
} | ||
}); | ||
IJavaProject javaProject = newDefaultProject(); | ||
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); | ||
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null); | ||
|
||
// @formatter:off | ||
String standaloneFileContent = | ||
"package java;\n"+ | ||
"public class Foo extends UnknownType {"+ | ||
" public void method1(){\n"+ | ||
" super.whatever();"+ | ||
" }\n"+ | ||
"}"; | ||
// @formatter:on | ||
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null); | ||
|
||
List<ElementChangedEvent> diagnosticReports = getClientRequests("notify"); | ||
assertEquals(7, diagnosticReports.size()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private <T> List<T> getClientRequests(String name) { | ||
List<?> requests = clientRequests.get(name); | ||
return requests != null ? (List<T>) requests : Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters