Skip to content

Commit 418d9e0

Browse files
committed
Handle event loop consistently in genericeditor tests
Instead of a mixture of UITestCase, DisplayHelper and custom code - unify on DisplayHelper. Enabled save actions to ease migrating code.
1 parent 81b2533 commit 418d9e0

File tree

7 files changed

+176
-29
lines changed

7 files changed

+176
-29
lines changed

tests/org.eclipse.ui.genericeditor.tests/.settings/org.eclipse.jdt.ui.prefs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
eclipse.preferences.version=1
2+
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
23
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
34
formatter_settings_version=23
45
org.eclipse.jdt.ui.exception.name=e
@@ -9,3 +10,152 @@ org.eclipse.jdt.ui.keywordthis=false
910
org.eclipse.jdt.ui.ondemandthreshold=99
1011
org.eclipse.jdt.ui.overrideannotation=true
1112
org.eclipse.jdt.ui.staticondemandthreshold=99
13+
sp_cleanup.add_all=false
14+
sp_cleanup.add_default_serial_version_id=true
15+
sp_cleanup.add_generated_serial_version_id=false
16+
sp_cleanup.add_missing_annotations=true
17+
sp_cleanup.add_missing_deprecated_annotations=true
18+
sp_cleanup.add_missing_methods=false
19+
sp_cleanup.add_missing_nls_tags=false
20+
sp_cleanup.add_missing_override_annotations=true
21+
sp_cleanup.add_missing_override_annotations_interface_methods=true
22+
sp_cleanup.add_serial_version_id=false
23+
sp_cleanup.also_simplify_lambda=true
24+
sp_cleanup.always_use_blocks=true
25+
sp_cleanup.always_use_parentheses_in_expressions=false
26+
sp_cleanup.always_use_this_for_non_static_field_access=false
27+
sp_cleanup.always_use_this_for_non_static_method_access=false
28+
sp_cleanup.array_with_curly=false
29+
sp_cleanup.arrays_fill=false
30+
sp_cleanup.bitwise_conditional_expression=false
31+
sp_cleanup.boolean_literal=false
32+
sp_cleanup.boolean_value_rather_than_comparison=false
33+
sp_cleanup.break_loop=false
34+
sp_cleanup.collection_cloning=false
35+
sp_cleanup.comparing_on_criteria=false
36+
sp_cleanup.comparison_statement=false
37+
sp_cleanup.controlflow_merge=false
38+
sp_cleanup.convert_functional_interfaces=false
39+
sp_cleanup.convert_to_enhanced_for_loop=false
40+
sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
41+
sp_cleanup.convert_to_switch_expressions=false
42+
sp_cleanup.correct_indentation=false
43+
sp_cleanup.do_while_rather_than_while=false
44+
sp_cleanup.double_negation=false
45+
sp_cleanup.else_if=false
46+
sp_cleanup.embedded_if=false
47+
sp_cleanup.evaluate_nullable=false
48+
sp_cleanup.extract_increment=false
49+
sp_cleanup.format_source_code=false
50+
sp_cleanup.format_source_code_changes_only=false
51+
sp_cleanup.hash=false
52+
sp_cleanup.if_condition=false
53+
sp_cleanup.insert_inferred_type_arguments=false
54+
sp_cleanup.instanceof=false
55+
sp_cleanup.instanceof_keyword=false
56+
sp_cleanup.invert_equals=false
57+
sp_cleanup.join=false
58+
sp_cleanup.lazy_logical_operator=false
59+
sp_cleanup.make_local_variable_final=true
60+
sp_cleanup.make_parameters_final=false
61+
sp_cleanup.make_private_fields_final=true
62+
sp_cleanup.make_type_abstract_if_missing_method=false
63+
sp_cleanup.make_variable_declarations_final=false
64+
sp_cleanup.map_cloning=false
65+
sp_cleanup.merge_conditional_blocks=false
66+
sp_cleanup.multi_catch=false
67+
sp_cleanup.never_use_blocks=false
68+
sp_cleanup.never_use_parentheses_in_expressions=true
69+
sp_cleanup.no_string_creation=false
70+
sp_cleanup.no_super=false
71+
sp_cleanup.number_suffix=false
72+
sp_cleanup.objects_equals=false
73+
sp_cleanup.on_save_use_additional_actions=true
74+
sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
75+
sp_cleanup.operand_factorization=false
76+
sp_cleanup.organize_imports=true
77+
sp_cleanup.overridden_assignment=false
78+
sp_cleanup.overridden_assignment_move_decl=true
79+
sp_cleanup.plain_replacement=false
80+
sp_cleanup.precompile_regex=false
81+
sp_cleanup.primitive_comparison=false
82+
sp_cleanup.primitive_parsing=false
83+
sp_cleanup.primitive_rather_than_wrapper=false
84+
sp_cleanup.primitive_serialization=false
85+
sp_cleanup.pull_out_if_from_if_else=false
86+
sp_cleanup.pull_up_assignment=false
87+
sp_cleanup.push_down_negation=false
88+
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
89+
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
90+
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
91+
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
92+
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
93+
sp_cleanup.reduce_indentation=false
94+
sp_cleanup.redundant_comparator=false
95+
sp_cleanup.redundant_falling_through_block_end=false
96+
sp_cleanup.remove_private_constructors=true
97+
sp_cleanup.remove_redundant_modifiers=false
98+
sp_cleanup.remove_redundant_semicolons=false
99+
sp_cleanup.remove_redundant_type_arguments=false
100+
sp_cleanup.remove_trailing_whitespaces=false
101+
sp_cleanup.remove_trailing_whitespaces_all=true
102+
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
103+
sp_cleanup.remove_unnecessary_array_creation=false
104+
sp_cleanup.remove_unnecessary_casts=true
105+
sp_cleanup.remove_unnecessary_nls_tags=false
106+
sp_cleanup.remove_unnecessary_suppress_warnings=false
107+
sp_cleanup.remove_unused_imports=false
108+
sp_cleanup.remove_unused_local_variables=false
109+
sp_cleanup.remove_unused_method_parameters=false
110+
sp_cleanup.remove_unused_private_fields=true
111+
sp_cleanup.remove_unused_private_members=false
112+
sp_cleanup.remove_unused_private_methods=true
113+
sp_cleanup.remove_unused_private_types=true
114+
sp_cleanup.replace_deprecated_calls=false
115+
sp_cleanup.replace_deprecated_fields=false
116+
sp_cleanup.return_expression=false
117+
sp_cleanup.simplify_boolean_if_else=false
118+
sp_cleanup.simplify_lambda_expression_and_method_ref=false
119+
sp_cleanup.single_used_field=false
120+
sp_cleanup.sort_members=false
121+
sp_cleanup.sort_members_all=false
122+
sp_cleanup.standard_comparison=false
123+
sp_cleanup.static_inner_class=false
124+
sp_cleanup.strictly_equal_or_different=false
125+
sp_cleanup.stringbuffer_to_stringbuilder=false
126+
sp_cleanup.stringbuilder=false
127+
sp_cleanup.stringbuilder_for_local_vars=true
128+
sp_cleanup.stringconcat_stringbuffer_stringbuilder=false
129+
sp_cleanup.stringconcat_to_textblock=false
130+
sp_cleanup.substring=false
131+
sp_cleanup.switch=false
132+
sp_cleanup.switch_for_instanceof_pattern=false
133+
sp_cleanup.system_property=false
134+
sp_cleanup.system_property_boolean=false
135+
sp_cleanup.system_property_file_encoding=false
136+
sp_cleanup.system_property_file_separator=false
137+
sp_cleanup.system_property_javaspecversion=false
138+
sp_cleanup.system_property_javaversion=false
139+
sp_cleanup.system_property_line_separator=false
140+
sp_cleanup.system_property_path_separator=false
141+
sp_cleanup.ternary_operator=false
142+
sp_cleanup.try_with_resource=false
143+
sp_cleanup.unlooped_while=false
144+
sp_cleanup.unreachable_block=false
145+
sp_cleanup.use_anonymous_class_creation=false
146+
sp_cleanup.use_autoboxing=false
147+
sp_cleanup.use_blocks=true
148+
sp_cleanup.use_blocks_only_for_return_and_throw=false
149+
sp_cleanup.use_directly_map_method=false
150+
sp_cleanup.use_lambda=true
151+
sp_cleanup.use_parentheses_in_expressions=false
152+
sp_cleanup.use_string_is_blank=false
153+
sp_cleanup.use_this_for_non_static_field_access=false
154+
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
155+
sp_cleanup.use_this_for_non_static_method_access=false
156+
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
157+
sp_cleanup.use_unboxing=false
158+
sp_cleanup.use_var=false
159+
sp_cleanup.useless_continue=false
160+
sp_cleanup.useless_return=false
161+
sp_cleanup.valueof_rather_than_instantiation=false

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.genericeditor.tests;
1515

16+
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
17+
1618
import java.io.ByteArrayInputStream;
1719
import java.nio.charset.StandardCharsets;
1820
import java.util.function.Supplier;
@@ -91,7 +93,7 @@ protected void createAndOpenFile(String name, String contents, Supplier<? extend
9193
this.file.setCharset(StandardCharsets.UTF_8.name(), null);
9294
this.editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
9395
.getActivePage().openEditor(inputCreator.get(), "org.eclipse.ui.genericeditor.GenericEditor");
94-
UITestCase.processEvents();
96+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
9597
}
9698

9799
/**
@@ -104,7 +106,7 @@ protected void cleanFileAndEditor() throws Exception {
104106
editor.close(false);
105107
editor = null;
106108
}
107-
UITestCase.processEvents();
109+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
108110
if (file != null) {
109111
file.delete(true, new NullProgressMonitor());
110112
file = null;
@@ -123,16 +125,7 @@ private static void closeIntro() {
123125
IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro();
124126
if (intro != null) {
125127
PlatformUI.getWorkbench().getIntroManager().closeIntro(intro);
126-
UITestCase.processEvents();
128+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
127129
}
128130
}
129-
130-
public static void waitAndDispatch(long milliseconds) {
131-
long timeout = milliseconds; //ms
132-
long start = System.currentTimeMillis();
133-
while (start + timeout > System.currentTimeMillis()) {
134-
UITestCase.processEvents();
135-
}
136-
}
137-
138131
}

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.eclipse.jface.text.contentassist.IContextInformation;
7070
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
7171

72+
import org.eclipse.ui.PlatformUI;
7273
import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
7374
import org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor;
7475
import org.eclipse.ui.tests.harness.util.DisplayHelper;
@@ -171,7 +172,7 @@ private Shell openConentAssist(boolean expectShell) {
171172
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
172173
action.run(); //opens shell
173174
Shell shell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay(),expectShell);
174-
waitAndDispatch(100); // can dispose shell when focus lost during debugging
175+
DisplayHelper.runEventLoop(PlatformUI.getWorkbench().getDisplay(), 100); // can dispose shell when focus lost during debugging
175176
return shell;
176177
}
177178

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ContextInfoTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.ui.genericeditor.tests;
1515

1616
import static org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor.BAR_CONTENT_ASSIST_PROPOSAL;
17+
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertTrue;
1920

@@ -35,7 +36,7 @@
3536
import org.eclipse.jface.text.contentassist.ContentAssistant;
3637
import org.eclipse.jface.text.source.SourceViewer;
3738

38-
import org.eclipse.ui.tests.harness.util.UITestCase;
39+
import org.eclipse.ui.PlatformUI;
3940

4041
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
4142
import org.eclipse.ui.texteditor.TextOperationAction;
@@ -56,15 +57,15 @@ public void testContextInfo() throws Exception {
5657
TextOperationAction action = (TextOperationAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST_CONTEXT_INFORMATION);
5758

5859
editor.selectAndReveal(4, 0);
59-
UITestCase.processEvents();
60+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
6061

6162
action.update();
6263
action.run();
6364
this.completionShell= findNewShell(beforeShells);
6465
assertEquals("idx= 0", getInfoText(this.completionShell));
6566

6667
editor.selectAndReveal(8, 0);
67-
UITestCase.processEvents();
68+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
6869

6970
action.update();
7071
action.run();
@@ -81,14 +82,14 @@ public void testContextInfo_hide_Bug512251() throws Exception {
8182
TextOperationAction action = (TextOperationAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST_CONTEXT_INFORMATION);
8283

8384
editor.selectAndReveal(4, 0);
84-
UITestCase.processEvents();
85+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
8586

8687
action.update();
8788
action.run();
8889
this.completionShell= findNewShell(beforeShells);
8990

9091
editor.selectAndReveal(8, 0);
91-
UITestCase.processEvents();
92+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
9293

9394
action.update();
9495
action.run();
@@ -103,10 +104,10 @@ public void testContextInfo_hide_Bug512251() throws Exception {
103104

104105

105106
private Shell findNewShell(Set<Shell> beforeShells) {
106-
waitAndDispatch(100);
107+
runEventLoop(PlatformUI.getWorkbench().getDisplay(), 100);
107108
Shell[] afterShells= findNewShells(beforeShells);
108109
if(afterShells.length == 0) {
109-
waitAndDispatch(1000);
110+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),1000);
110111
}
111112
afterShells= findNewShells(beforeShells);
112113
assertEquals("No new shell found", 1, afterShells.length);

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/IconsTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2019 Lakshminarayana Nekkanti([email protected])
2+
* Copyright (c) 2019, 2025 Lakshminarayana Nekkanti([email protected])
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -12,11 +12,13 @@
1212
********************************************************************************/
1313
package org.eclipse.ui.genericeditor.tests;
1414

15+
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
1516
import static org.junit.Assert.assertEquals;
1617

1718
import java.io.ByteArrayInputStream;
1819
import java.lang.reflect.Field;
1920

21+
import org.junit.After;
2022
import org.junit.Test;
2123

2224
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -33,7 +35,6 @@
3335
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
3436
import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
3537
import org.eclipse.ui.part.FileEditorInput;
36-
import org.eclipse.ui.tests.harness.util.UITestCase;
3738

3839
public class IconsTest extends AbstratGenericEditorTest {
3940

@@ -86,11 +87,12 @@ public void testEditorIconChildSet() throws Exception {
8687
}
8788

8889
@Override
90+
@After
8991
public void tearDown() throws Exception {
9092
if (genericEditor != null) {
9193
genericEditor.close(false);
9294
genericEditor= null;
93-
UITestCase.processEvents();
95+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
9496
}
9597
if (testFile != null) {
9698
testFile.delete(true, new NullProgressMonitor());

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.genericeditor.tests;
1515

16+
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
1617
import static org.junit.Assert.assertTrue;
1718

1819
import java.io.ByteArrayInputStream;
@@ -35,7 +36,6 @@
3536
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
3637
import org.eclipse.ui.part.FileEditorInput;
3738
import org.eclipse.ui.tests.harness.util.DisplayHelper;
38-
import org.eclipse.ui.tests.harness.util.UITestCase;
3939

4040
import org.eclipse.ui.texteditor.IDocumentProvider;
4141

@@ -104,7 +104,7 @@ public void tearDown() throws Exception {
104104
if (secondEditor != null) {
105105
secondEditor.close(false);
106106
secondEditor = null;
107-
UITestCase.processEvents();
107+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
108108
}
109109
if (secondFile != null) {
110110
secondFile.delete(true, new NullProgressMonitor());

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.ui.genericeditor.tests;
1616

1717
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
18+
import static org.eclipse.ui.tests.harness.util.DisplayHelper.waitForCondition;
1819
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertTrue;
2021

@@ -32,9 +33,8 @@
3233

3334
import org.eclipse.core.resources.IMarker;
3435

35-
36+
import org.eclipse.ui.PlatformUI;
3637
import org.eclipse.ui.genericeditor.tests.contributions.MarkerResolutionGenerator;
37-
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3838

3939
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
4040
import org.eclipse.ui.texteditor.TextOperationAction;
@@ -105,7 +105,7 @@ private Shell openQuickAssist() {
105105
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
106106
action.run();
107107
Shell shell= CompletionTest.findNewShell(beforeShells, editor.getSite().getShell().getDisplay(), true);
108-
waitAndDispatch(100);
108+
runEventLoop(PlatformUI.getWorkbench().getDisplay(),100);
109109
return shell;
110110
}
111111

@@ -117,7 +117,7 @@ private Shell openQuickAssist() {
117117
*/
118118
private void checkCompletionContent(final Table completionProposalList, String[] proposals) {
119119
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
120-
DisplayHelper.waitForCondition(completionProposalList.getDisplay(), 200,
120+
waitForCondition(completionProposalList.getDisplay(), 200,
121121
() -> completionProposalList.getItemCount() >= proposals.length);
122122
assertEquals(proposals.length, completionProposalList.getItemCount());
123123
Set<String> existing= Arrays.stream(completionProposalList.getItems()).map(TableItem::getText).collect(Collectors.toSet());

0 commit comments

Comments
 (0)