Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java')
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
index dd18ceaf298..dcf4a7d27c0 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
@@ -20,12 +20,18 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceRegistration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ST;
@@ -45,7 +51,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.jface.text.tests.util.DisplayHelper;
import org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor;
@@ -87,6 +97,26 @@ public class CompletionTest extends AbstratGenericEditorTest {
}
@Test
+ public void testCompletionService() throws Exception {
+ Bundle bundle= FrameworkUtil.getBundle(CompletionTest.class);
+ assertNotNull(bundle);
+ BundleContext bundleContext= bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ MockContentAssistProcessor service= new MockContentAssistProcessor();
+ ServiceRegistration<IContentAssistProcessor> registration= bundleContext.registerService(IContentAssistProcessor.class, service,
+ new Hashtable<>(Collections.singletonMap("contentType", "org.eclipse.ui.genericeditor.tests.content-type")));
+ DisplayHelper.driveEventQueue(Display.getCurrent());
+ final Set<Shell> beforeShells= Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ editor.selectAndReveal(3, 0);
+ openConentAssist();
+ this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
+ final Table completionProposalList= findCompletionSelectionControl(completionShell);
+ checkCompletionContent(completionProposalList);
+ assertTrue("Service was not called!", service.called);
+ registration.unregister();
+ }
+
+ @Test
public void testCompletionUsingViewerSelection() throws Exception {
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("abc");
@@ -257,4 +287,41 @@ public class CompletionTest extends AbstratGenericEditorTest {
}
}
+
+ private static final class MockContentAssistProcessor implements IContentAssistProcessor {
+
+ private boolean called;
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ called= true;
+ return null;
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return null;
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ }
}

Back to the top