From 8ea681fc581fd2010d72fefdaf36683688f79588 Mon Sep 17 00:00:00 2001 From: Joerg Kubitz Date: Fri, 26 May 2023 08:32:02 +0200 Subject: [PATCH] fix ContextInformationTest #35 Identify correct shell instead of taking random one. --- .../AbstractContentAssistTest.java | 12 ++++++------ .../ContextInformationPresenterTest.java | 2 +- .../contentassist/ContextInformationTest.java | 18 +++++++----------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java index a5aa006fd..2925a1b13 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java @@ -14,6 +14,7 @@ package org.eclipse.jface.text.tests.contentassist; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; @@ -226,14 +227,13 @@ protected List findNewShells(Collection beforeShells) { } protected Shell findNewShell(Collection beforeShells) { - DisplayHelper.sleep(getDisplay(), 100); List afterShells= findNewShells(beforeShells); - if (afterShells.isEmpty()) { - DisplayHelper.sleep(getDisplay(), 1000); + for (int attempt= 0; afterShells.size() != 1 && attempt < 10; attempt++) { + DisplayHelper.sleep(getDisplay(), 100); + afterShells= findNewShells(beforeShells); } - afterShells= findNewShells(beforeShells); - assertTrue("No new shell found, existing: " + beforeShells, afterShells.size() > beforeShells.size()); - return afterShells.get(afterShells.size() - 1); + assertEquals("Not unique new shell found", 1, afterShells.size()); + return afterShells.get(0); } } diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationPresenterTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationPresenterTest.java index ecf95d72e..5f2ab4788 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationPresenterTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationPresenterTest.java @@ -87,13 +87,13 @@ public IContextInformationValidator getContextInformationValidator() { @Test public void testContextInfo_withStyledTextPresentation() throws Exception { - final List beforeShells= getCurrentShells(); setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL); postSourceViewerKeyEvent(SWT.ARROW_RIGHT, 0, SWT.KeyDown); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); triggerContextInformation(); this.infoShell= findNewShell(beforeShells); assertEquals("idx= 0", getInfoText(this.infoShell)); diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationTest.java index 6830339a6..176d1ac17 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationTest.java @@ -15,7 +15,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; import java.util.List; @@ -27,8 +26,6 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.core.runtime.Platform; - import org.eclipse.text.tests.Accessor; import org.eclipse.jface.text.IDocument; @@ -49,12 +46,12 @@ private ContentAssistant createBarContentAssist() { @Test public void testContextInfo() throws Exception { - final List beforeShells= getCurrentShells(); setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); triggerContextInformation(); this.infoShell= findNewShell(beforeShells); assertEquals("idx= 0", getInfoText(this.infoShell)); @@ -69,12 +66,12 @@ public void testContextInfo() throws Exception { @Test public void testContextInfo_hide_Bug512251() throws Exception { - final List beforeShells= getCurrentShells(); setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); triggerContextInformation(); this.infoShell= findNewShell(beforeShells); @@ -92,15 +89,14 @@ public void testContextInfo_hide_Bug512251() throws Exception { @Test public void testContextInfo_hide_focusOut() throws Exception { - assumeFalse("Test fails on Mac: Bug 558989", Platform.OS_MACOSX.equals(Platform.getOS())); - assumeFalse("Test fails on CentOS 8: See https://github.com/eclipse-platform/eclipse.platform.text/pull/162", Platform.OS_LINUX.equals(Platform.getOS())); - - final List beforeShells= getCurrentShells(); + // opens source viewer shell: setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); + // opens content assist shell: triggerContextInformation(); this.infoShell= findNewShell(beforeShells); assertEquals("idx= 0", getInfoText(this.infoShell)); @@ -120,12 +116,12 @@ public void testContextInfo_hide_focusOut() throws Exception { @Test public void testContextInfo_hide_keyEsc() throws Exception { - final List beforeShells= getCurrentShells(); setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); triggerContextInformation(); this.infoShell= findNewShell(beforeShells); assertEquals("idx= 0", getInfoText(this.infoShell)); @@ -149,12 +145,12 @@ public void testContextInfo_hide_keyEsc() throws Exception { @Test public void testContextInfo_hide_validRange() throws Exception { - final List beforeShells= getCurrentShells(); setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL + '\n'); selectAndReveal(4, 0); processEvents(); + final List beforeShells= getCurrentShells(); triggerContextInformation(); this.infoShell= findNewShell(beforeShells); assertEquals("idx= 0", getInfoText(this.infoShell));