diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java index 751c1ffb9..f82d598ef 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import org.junit.After; @@ -153,39 +154,50 @@ public void testCompleteActivationChar() { final Set beforeShells= Arrays.stream(display.getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); Event keyEvent= new Event(); Control control= viewer.getTextWidget(); - display.timerExec(200, new Runnable() { - @Override - public void run() { - if (control.isDisposed()) { - // https://github.com/eclipse-platform/eclipse.platform.text/issues/75#issuecomment-1263429480 - return; // do not fail other unit tests - } - control.forceFocus(); - keyEvent.widget= control; - keyEvent.type= SWT.KeyDown; - keyEvent.character= 'b'; - keyEvent.keyCode= 'b'; - control.getDisplay().post(keyEvent); - keyEvent.type= SWT.KeyUp; - control.getDisplay().post(keyEvent); - DisplayHelper.driveEventQueue(control.getDisplay()); - if (!document.get().startsWith("bb")) { - display.timerExec(200, this); + AtomicBoolean testEnded= new AtomicBoolean(); + try { + display.timerExec(0, new Runnable() { + @Override + public void run() { + if (control.isDisposed() || testEnded.get()) { + // https://github.com/eclipse-platform/eclipse.platform.text/issues/75#issuecomment-1263429480 + return; // do not fail other unit tests + } + control.getShell().forceActive(); + if (!control.forceFocus()) { + display.timerExec(200, this); + System.out.println("no focus"); + return; + } + keyEvent.widget= control; + keyEvent.type= SWT.KeyDown; + keyEvent.character= 'b'; + keyEvent.keyCode= 'b'; + control.getDisplay().post(keyEvent); + keyEvent.type= SWT.KeyUp; + control.getDisplay().post(keyEvent); + DisplayHelper.driveEventQueue(control.getDisplay()); + if (!document.get().startsWith("bb")) { + System.out.println("character b not added to control"); + display.timerExec(200, this); + } } - } - }); - assertTrue("Completion item not shown", new DisplayHelper() { - @Override - protected boolean condition() { - Set newShells= Arrays.stream(display.getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); - newShells.removeAll(beforeShells); - if (!newShells.isEmpty()) { - Table completionTable= findCompletionSelectionControl(newShells.iterator().next()); - return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength()))); + }); + assertTrue("Completion item not shown", new DisplayHelper() { + @Override + protected boolean condition() { + Set newShells= Arrays.stream(display.getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); + newShells.removeAll(beforeShells); + if (!newShells.isEmpty()) { + Table completionTable= findCompletionSelectionControl(newShells.iterator().next()); + return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength()))); + } + return false; } - return false; - } - }.waitForCondition(display, 4000)); + }.waitForCondition(display, 4000)); + } finally { + testEnded.set(true); + } } private static Table findCompletionSelectionControl(Widget control) { diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/DelayedErrorContentAssistProcessor.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/DelayedErrorContentAssistProcessor.java index 10c2ec26e..2cde5f31a 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/DelayedErrorContentAssistProcessor.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/DelayedErrorContentAssistProcessor.java @@ -28,7 +28,7 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int } catch (InterruptedException e) { Thread.currentThread().interrupt(); } - throw new RuntimeException(); + throw new RuntimeException("Expected Exception for junit test"); } @Override