11/*******************************************************************************
2- * Copyright (c) 2006, 2018 Brad Reynolds, IBM Corporation and others.
2+ * Copyright (c) 2006, 2026 Brad Reynolds, IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
1515 *******************************************************************************/
1616package org .eclipse .jface .tests .viewers ;
1717
18+ import static org .eclipse .ui .tests .harness .util .DisplayHelper .runEventLoop ;
19+ import static org .eclipse .ui .tests .harness .util .DisplayHelper .waitAndAssertCondition ;
1820import static org .junit .jupiter .api .Assertions .assertEquals ;
1921import static org .junit .jupiter .api .Assertions .assertNotEquals ;
2022
2729import org .eclipse .jface .viewers .Viewer ;
2830import org .eclipse .swt .SWT ;
2931import org .eclipse .swt .layout .FillLayout ;
30- import org .eclipse .swt .widgets .Display ;
3132import org .eclipse .swt .widgets .Label ;
3233import org .eclipse .swt .widgets .Shell ;
33- import org .eclipse .ui .tests .harness .util .DisplayHelper ;
3434import org .junit .jupiter .api .AfterEach ;
3535import org .junit .jupiter .api .BeforeEach ;
3636import org .junit .jupiter .api .Test ;
@@ -47,7 +47,7 @@ public class ListViewerRefreshTest {
4747
4848 private ListViewer viewer = null ;
4949
50- private ArrayList <String > input = null ;
50+ private List <String > input = null ;
5151
5252 @ BeforeEach
5353 public void setUp () throws Exception {
@@ -81,16 +81,15 @@ public void tearDown() throws Exception {
8181 @ Test
8282 public void testNoSelectionRefresh () throws Exception {
8383 shell .setText ("Lost Scrolled Position Test" ); //$NON-NLS-1$
84- readAndDispatch ( );
84+ runEventLoop ( shell . getDisplay (), DELAY );
8585
8686 run ("Scrolled to position 30." , () -> viewer .reveal (input .get (30 )));
8787
88- run ("Refreshed viewer without a selection." , () -> viewer . refresh () );
88+ run ("Refreshed viewer without a selection." , viewer :: refresh );
8989
9090 // BUG: The top index should not be the first item.
9191
92- DisplayHelper .waitAndAssertCondition (shell .getDisplay (),
93- () -> assertNotEquals (viewer .getList ().getTopIndex (), 0 ));
92+ waitAndAssertCondition (shell .getDisplay (), () -> assertNotEquals (viewer .getList ().getTopIndex (), 0 ));
9493 }
9594
9695 /**
@@ -100,22 +99,21 @@ public void testNoSelectionRefresh() throws Exception {
10099 @ Test
101100 public void testSelectionRefresh () throws Exception {
102101 shell .setText ("Preserved Scrolled Position Test" ); //$NON-NLS-1$
103- readAndDispatch ( );
102+ runEventLoop ( shell . getDisplay (), DELAY );
104103
105104 run ("Setting selection to index 30." , () -> viewer .setSelection (new StructuredSelection (input .get (30 ))));
106105
107106 // Ensure that to index is 0
108107 viewer .getList ().setTopIndex (0 );
109108
110- run ("Refreshed viewer with selection." , () -> viewer . refresh () );
109+ run ("Refreshed viewer with selection." , viewer :: refresh );
111110
112111 // Checking that the viewer is not scrolling
113112 assertEquals (0 , viewer .getList ().getTopIndex ());
114113
115114 viewer .getList ().showSelection ();
116115
117- DisplayHelper .waitAndAssertCondition (shell .getDisplay (),
118- () -> assertNotEquals (viewer .getList ().getTopIndex (), 0 ));
116+ waitAndAssertCondition (shell .getDisplay (), () -> assertNotEquals (viewer .getList ().getTopIndex (), 0 ));
119117 }
120118
121119 /**
@@ -125,22 +123,7 @@ private void run(String description, Runnable runnable) {
125123 runnable .run ();
126124 label .setText (description );
127125
128- readAndDispatch ();
129- }
130-
131- /**
132- * Flush UI events and {@link #DELAY delays}.
133- */
134- private static void readAndDispatch () {
135- Display display = Display .getCurrent ();
136- while (display .readAndDispatch ()) {
137- }
138-
139- try {
140- Thread .sleep (DELAY );
141- } catch (InterruptedException e ) {
142- e .printStackTrace ();
143- }
126+ runEventLoop (shell .getDisplay (), DELAY );
144127 }
145128
146129 private static class ContentProvider implements IStructuredContentProvider {
0 commit comments