From f4c5740e7cc033a29235499869410b068e057c9f Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Sun, 8 Jun 2025 19:04:32 +0200 Subject: [PATCH] Creates TestUtil.CleanupRule based on TestUtil In https://github.com/eclipse-platform/eclipse.platform.ui/pull/3029 it was suggested to add a rule, this is the rule. It is applied to the tests. Some tearDown methods did also spin the event loop, that is not necessary as the rule does this already. --- .../text/tests/codemining/CodeMiningTest.java | 8 +++- .../ui/editors/tests/CaseActionTest.java | 5 ++- .../tests/ChainedPreferenceStoreTest.java | 11 +++-- .../tests/DocumentProviderRegistryTest.java | 6 ++- .../ui/editors/tests/EncodingChangeTests.java | 7 +++- .../tests/FileDocumentProviderTest.java | 8 ++-- .../ui/editors/tests/FindNextActionTest.java | 6 ++- .../ui/editors/tests/GotoLineTest.java | 7 +++- .../ui/editors/tests/LargeFileTest.java | 5 ++- .../tests/MarkerAnnotationOrderTest.java | 5 ++- .../ui/editors/tests/SegmentedModeTest.java | 5 ++- .../ui/editors/tests/StatusEditorTest.java | 7 +++- .../eclipse/ui/editors/tests/TestUtil.java | 41 +++++++++---------- .../tests/TextFileDocumentProviderTest.java | 6 ++- .../tests/TextMultiCaretNavigationTest.java | 5 ++- .../TextMultiCaretSelectionCommandsTest.java | 6 ++- .../ui/editors/tests/TextNavigationTest.java | 5 ++- .../eclipse/ui/editors/tests/ZoomTest.java | 5 ++- .../DefaultStickyLinesProviderTest.java | 10 ++--- .../StickyLinesProviderRegistryTest.java | 9 ++-- .../StickyScrollingControlTest.java | 5 ++- .../StickyScrollingHandlerTest.java | 5 ++- 22 files changed, 113 insertions(+), 64 deletions(-) diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java index 9abe1e3a6b5..829c09bfe58 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java @@ -20,6 +20,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.eclipse.swt.custom.StyledText; @@ -58,6 +59,10 @@ import org.eclipse.ui.editors.tests.TestUtil; public class CodeMiningTest { + + @Rule + public TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule(); + private static String PROJECT_NAME = "test_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); private static IProject project; @@ -80,7 +85,6 @@ public void after() { drainEventQueue(); CodeMiningTestProvider.provideContentMiningAtOffset = -1; CodeMiningTestProvider.provideHeaderMiningAtLine = -1; - TestUtil.cleanUp(); } private static void closeAllEditors() { @@ -357,4 +361,4 @@ private final boolean waitForCondition(Display display, long timeout, Callable stickyLines = stickyLinesProvider.getStickyLines(sourceViewer, 0, stickyLinesProperties); diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderRegistryTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderRegistryTest.java index d3fa25e72a6..75abb6f5a3c 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderRegistryTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderRegistryTest.java @@ -8,8 +8,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.eclipse.core.runtime.IConfigurationElement; @@ -24,6 +24,9 @@ public class StickyLinesProviderRegistryTest { + @Rule + public TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule(); + private StickyLinesProviderDescriptor stickyLinesProviderDescriptor; private StickyLinesProviderRegistry cut; private ISourceViewer viewer; @@ -43,10 +46,6 @@ public void setup() { cut = new StickyLinesProviderRegistry(extensionRegistry, e -> stickyLinesProviderDescriptor); } - @After - public void teardown() { - TestUtil.cleanUp(); - } @Test public void testGetDefaultProviderIfNoMatch() { diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java index 200de84a31a..353a4a819ae 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java @@ -24,6 +24,7 @@ import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.eclipse.swt.SWT; @@ -52,6 +53,9 @@ public class StickyScrollingControlTest { + @Rule + public TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule(); + private Shell shell; private SourceViewer sourceViewer; private Color lineNumberColor; @@ -88,7 +92,6 @@ public void teardown() { lineNumberColor.dispose(); hoverColor.dispose(); backgroundColor.dispose(); - TestUtil.cleanUp(); } @Test diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java index 411a2b73fee..ad3b1bc83b3 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingHandlerTest.java @@ -34,6 +34,7 @@ import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.eclipse.swt.SWT; @@ -63,6 +64,9 @@ public class StickyScrollingHandlerTest { + @Rule + public TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule(); + private Shell shell; private SourceViewer sourceViewer; private Color lineNumberColor; @@ -101,7 +105,6 @@ public void setup() { @After public void teardown() { shell.dispose(); - TestUtil.cleanUp(); } @Test