1515
1616import static org .eclipse .ui .genericeditor .tests .contributions .BarContentAssistProcessor .BAR_CONTENT_ASSIST_PROPOSAL ;
1717import static org .eclipse .ui .genericeditor .tests .contributions .LongRunningBarContentAssistProcessor .LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL ;
18+ import static org .eclipse .ui .tests .harness .util .DisplayHelper .runEventLoop ;
19+ import static org .eclipse .ui .tests .harness .util .DisplayHelper .sleep ;
20+ import static org .eclipse .ui .tests .harness .util .DisplayHelper .waitForCondition ;
1821import static org .hamcrest .CoreMatchers .endsWith ;
1922import static org .hamcrest .MatcherAssert .assertThat ;
2023import static org .junit .jupiter .api .Assertions .assertEquals ;
6972import org .eclipse .ui .PlatformUI ;
7073import org .eclipse .ui .genericeditor .tests .contributions .EnabledPropertyTester ;
7174import org .eclipse .ui .genericeditor .tests .contributions .LongRunningBarContentAssistProcessor ;
72- import org .eclipse .ui .tests .harness .util .DisplayHelper ;
7375
7476import org .eclipse .ui .texteditor .ContentAssistAction ;
7577import org .eclipse .ui .texteditor .ITextEditorActionConstants ;
@@ -101,7 +103,7 @@ public void testDefaultContentAssistBug570488() throws Exception {
101103 log .addLogListener (listener );
102104 createAndOpenFile ("Bug570488.txt" , "bar 'bar'" );
103105 openContentAssist (false );
104- DisplayHelper . runEventLoop (Display .getCurrent (), 0 );
106+ runEventLoop (Display .getCurrent (), 0 );
105107 assertFalse (listener .messages .stream ().anyMatch (s -> s .matches (IStatus .ERROR )), "There are errors in the log" );
106108 log .removeLogListener (listener );
107109 }
@@ -116,7 +118,7 @@ public void testCompletionService() throws Exception {
116118 MockContentAssistProcessor service = new MockContentAssistProcessor ();
117119 ServiceRegistration <IContentAssistProcessor > registration = bundleContext .registerService (IContentAssistProcessor .class , service ,
118120 new Hashtable <>(Collections .singletonMap ("contentType" , "org.eclipse.ui.genericeditor.tests.content-type" )));
119- DisplayHelper . runEventLoop (Display .getCurrent (), 0 );
121+ runEventLoop (Display .getCurrent (), 0 );
120122 editor .selectAndReveal (3 , 0 );
121123 this .completionShell = openContentAssist (true );
122124 final Table completionProposalList = findCompletionSelectionControl (completionShell );
@@ -132,7 +134,7 @@ public void testCompletionUsingViewerSelection() throws Exception {
132134 editor .selectAndReveal (0 , 3 );
133135 this .completionShell = openContentAssist (true );
134136 final Table completionProposalList = findCompletionSelectionControl (completionShell );
135- assertTrue (DisplayHelper . waitForCondition (completionProposalList .getDisplay (), 5000 , () -> {
137+ assertTrue (waitForCondition (completionProposalList .getDisplay (), 5000 , () -> {
136138 assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
137139 return Arrays .stream (completionProposalList .getItems ()).map (TableItem ::getText ).anyMatch ("ABC" ::equals );
138140 }), "Proposal list did not contain expected item: ABC" );
@@ -160,7 +162,7 @@ private Shell openContentAssist(boolean expectShell) {
160162 final Set <Shell > beforeShells = Arrays .stream (editor .getSite ().getShell ().getDisplay ().getShells ()).filter (Shell ::isVisible ).collect (Collectors .toSet ());
161163 action .run (); //opens shell
162164 Shell shell = findNewShell (beforeShells , editor .getSite ().getShell ().getDisplay (),expectShell );
163- DisplayHelper . runEventLoop (PlatformUI .getWorkbench ().getDisplay (), 100 ); // can dispose shell when focus lost during debugging
165+ runEventLoop (PlatformUI .getWorkbench ().getDisplay (), 100 ); // can dispose shell when focus lost during debugging
164166 return shell ;
165167 }
166168
@@ -173,22 +175,24 @@ private Shell openContentAssist(boolean expectShell) {
173175 */
174176 private void checkCompletionContent (final Table completionProposalList ) {
175177 // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
176- assertTrue (DisplayHelper . waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
178+ assertTrue (waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
177179 assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
178180 return completionProposalList .getItemCount () == 2 && completionProposalList .getItem (1 ).getData () != null ;
179181 }), "Proposal list did not show two initial items" );
180182 assertTrue (isComputingInfoEntry (completionProposalList .getItem (0 )), "Missing computing info entry in proposal list" );
181183 final TableItem initialProposalItem = completionProposalList .getItem (1 );
182- System .out .println (initialProposalItem .toString ());
183184 final String initialProposalString = ((ICompletionProposal )initialProposalItem .getData ()).getDisplayString ();
184185 assertThat ("Unexpected initial proposal item" ,
185186 BAR_CONTENT_ASSIST_PROPOSAL , endsWith (initialProposalString ));
186187 completionProposalList .setSelection (initialProposalItem );
187188 // asynchronous
188- assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), LongRunningBarContentAssistProcessor .DELAY * 2 , () -> {
189- assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
190- return !isComputingInfoEntry (completionProposalList .getItem (0 )) && completionProposalList .getItemCount () == 2 ;
191- }), "Proposal list did not show two items after finishing computing" );
189+ assertTrue (waitForCondition (completionProposalList .getDisplay (), LongRunningBarContentAssistProcessor .DELAY * 2 ,
190+ () -> {
191+ assertFalse (completionProposalList .isDisposed (),
192+ "Completion proposal list was unexpectedly disposed" );
193+ return !isComputingInfoEntry (completionProposalList .getItem (0 ))
194+ && completionProposalList .getItemCount () == 2 ;
195+ }), "Proposal list did not show two items after finishing computing" );
192196 final TableItem firstCompletionProposalItem = completionProposalList .getItem (0 );
193197 final TableItem secondCompletionProposalItem = completionProposalList .getItem (1 );
194198 String firstCompletionProposalText = ((ICompletionProposal )firstCompletionProposalItem .getData ()).getDisplayString ();
@@ -221,7 +225,7 @@ public void testCompletionFreeze_bug521484() throws Exception {
221225 this .completionShell =openContentAssist (true );
222226 final Table completionProposalList = findCompletionSelectionControl (this .completionShell );
223227 // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
224- assertTrue (DisplayHelper . waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
228+ assertTrue (waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
225229 assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
226230 return completionProposalList .getItemCount () == 2 ;
227231 }), "Proposal list did not show two items" );
@@ -230,7 +234,7 @@ public void testCompletionFreeze_bug521484() throws Exception {
230234 // asynchronous
231235 long timestamp = System .currentTimeMillis ();
232236 emulatePressLeftArrowKey ();
233- DisplayHelper . sleep (editor .getSite ().getShell ().getDisplay (), 200 ); //give time to process events
237+ sleep (editor .getSite ().getShell ().getDisplay (), 200 ); //give time to process events
234238 long processingDuration = System .currentTimeMillis () - timestamp ;
235239 assertTrue (processingDuration < LongRunningBarContentAssistProcessor .DELAY , "UI Thread frozen for " + processingDuration + "ms" );
236240 }
@@ -241,7 +245,7 @@ public void testMoveCaretBackUsesAllProcessors_bug522255() throws Exception {
241245 testCompletion ();
242246 emulatePressLeftArrowKey ();
243247 final Set <Shell > beforeShells = Arrays .stream (editor .getSite ().getShell ().getDisplay ().getShells ()).filter (Shell ::isVisible ).collect (Collectors .toSet ());
244- DisplayHelper . sleep (editor .getSite ().getShell ().getDisplay (), 200 );
248+ sleep (editor .getSite ().getShell ().getDisplay (), 200 );
245249 this .completionShell = findNewShell (beforeShells , editor .getSite ().getShell ().getDisplay (), true );
246250 final Table completionProposalList = findCompletionSelectionControl (this .completionShell );
247251 checkCompletionContent (completionProposalList );
0 commit comments