Skip to content

Commit 0cd32ee

Browse files
committed
Creates TestUtilCleanupRule based on TestUtil
In #3029 it was suggested to add a rule, this is the rule. It is applied to the tests. TestRule is still necessary, as some tests spin the event loop or wait for jobs using it. Some tearDown methods did also spin the event loop, that is not necessary as the rule does this already.
1 parent ef9a336 commit 0cd32ee

23 files changed

+157
-62
lines changed

tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.AfterClass;
2121
import org.junit.Assert;
2222
import org.junit.BeforeClass;
23+
import org.junit.Rule;
2324
import org.junit.Test;
2425

2526
import org.eclipse.swt.custom.StyledText;
@@ -55,9 +56,13 @@
5556
import org.eclipse.ui.PlatformUI;
5657
import org.eclipse.ui.ide.IDE;
5758

58-
import org.eclipse.ui.editors.tests.TestUtil;
59+
import org.eclipse.ui.editors.tests.TestUtilCleanupRule;
5960

6061
public class CodeMiningTest {
62+
63+
@Rule
64+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
65+
6166
private static String PROJECT_NAME = "test_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
6267

6368
private static IProject project;
@@ -80,7 +85,6 @@ public void after() {
8085
drainEventQueue();
8186
CodeMiningTestProvider.provideContentMiningAtOffset = -1;
8287
CodeMiningTestProvider.provideHeaderMiningAtLine = -1;
83-
TestUtil.cleanUp();
8488
}
8589

8690
private static void closeAllEditors() {

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/CaseActionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.AfterClass;
2323
import org.junit.Before;
2424
import org.junit.BeforeClass;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627

2728
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -50,6 +51,9 @@ public class CaseActionTest {
5051
private static IFile file;
5152
private AbstractTextEditor editor;
5253

54+
@Rule
55+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
56+
5357
@BeforeClass
5458
public static void setUpBeforeClass() throws Exception {
5559
project = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
@@ -63,7 +67,6 @@ public static void setUpBeforeClass() throws Exception {
6367
public static void tearDownAfterClass() throws Exception {
6468
file.delete(true, new NullProgressMonitor());
6569
project.delete(true, new NullProgressMonitor());
66-
TestUtil.cleanUp();
6770
}
6871

6972
@Before

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ChainedPreferenceStoreTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.junit.After;
22+
import org.junit.Rule;
2323
import org.junit.Test;
2424

2525
import org.eclipse.jface.preference.IPreferenceStore;
@@ -31,6 +31,9 @@
3131

3232
public class ChainedPreferenceStoreTest {
3333

34+
@Rule
35+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
36+
3437
private class PropertyChangeListener implements IPropertyChangeListener {
3538

3639
@Override
@@ -47,10 +50,6 @@ public void propertyChange(PropertyChangeEvent event) {
4750
private static final String DEFAULT_VALUE= "4";
4851
private static final String DEFAULT_DEFAULT_VALUE= "";
4952

50-
@After
51-
public void tearDown() {
52-
TestUtil.cleanUp();
53-
}
5453

5554
/**
5655
* [implementation] ChainedPreferenceStore

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public class DocumentProviderRegistryTest {
4444
@Rule
4545
public TemporaryFolder tmp = new TemporaryFolder();
4646

47+
@Rule
48+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
49+
4750
private IFile file;
4851

4952
@After
5053
public void tearDown() throws Exception {
5154
if (file != null) {
5255
ResourceHelper.delete(file.getProject());
5356
}
54-
TestUtil.cleanUp();
5557
}
5658

5759
@Test

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EncodingChangeTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.junit.After;
2222
import org.junit.Before;
23+
import org.junit.Rule;
2324
import org.junit.Test;
2425

2526
import org.eclipse.swt.custom.ScrolledComposite;
@@ -61,6 +62,9 @@
6162
*/
6263
public class EncodingChangeTests {
6364

65+
@Rule
66+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
67+
6468
private static final String NON_DEFAULT_ENCODING= "US-ASCII".equals(ResourcesPlugin.getEncoding()) ? "ISO-8859-1" : "US-ASCII";
6569
private static final String ORIGINAL_CONTENT= "line1\nline2\nline3";
6670

@@ -94,7 +98,6 @@ public void tearDown() throws Exception {
9498
fEditor= null;
9599
fFile= null;
96100
ResourceHelper.deleteProject("EncodingChangeTestProject");
97-
TestUtil.cleanUp();
98101
}
99102

100103
@Test

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/FileDocumentProviderTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.junit.After;
2626
import org.junit.Before;
27+
import org.junit.Rule;
2728
import org.junit.Test;
2829

2930
import org.eclipse.swt.widgets.Display;
@@ -73,6 +74,9 @@
7374
*/
7475
public class FileDocumentProviderTest {
7576

77+
@Rule
78+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
79+
7680
private File file;
7781
private AtomicBoolean stoppedByTest;
7882
private AtomicBoolean stopLockingFlag;
@@ -136,8 +140,6 @@ public void tearDown() throws Exception {
136140
page.closeEditor(editor, false);
137141
}
138142
ResourceHelper.deleteProject(file.getProject().getName());
139-
TestUtil.runEventLoop();
140-
TestUtil.cleanUp();
141143
}
142144

143145
@Test

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/FindNextActionTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hamcrest.Matchers;
2323
import org.junit.After;
2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.osgi.framework.FrameworkUtil;
2728

@@ -52,6 +53,10 @@
5253
import org.eclipse.ui.texteditor.FindReplaceAction;
5354

5455
public class FindNextActionTest {
56+
57+
@Rule
58+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
59+
5560
private static final String TEST_PROJECT_NAME = "TestProject";
5661

5762
private static final String BUNDLE_FOR_CONSTRUCTED_KEYS_NAME = "org.eclipse.ui.texteditor.ConstructedEditorMessages";//$NON-NLS-1$
@@ -103,7 +108,6 @@ public void tearDown() throws Exception {
103108
editor = null;
104109
project.delete(true, null);
105110
project = null;
106-
TestUtil.cleanUp();
107111
}
108112

109113
private void resetInitialSearchSettings() {

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/GotoLineTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.junit.After;
2020
import org.junit.Before;
21+
import org.junit.Rule;
2122
import org.junit.Test;
2223

2324
import org.eclipse.swt.custom.StyledText;
@@ -53,6 +54,9 @@
5354
*/
5455
public class GotoLineTest {
5556

57+
@Rule
58+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
59+
5660
private static final String ORIGINAL_CONTENT= "line1\nline2\nline3";
5761

5862
private IFile fFile;
@@ -71,7 +75,6 @@ public void setUp() throws Exception {
7175
public void tearDown() throws Exception {
7276
ResourceHelper.deleteProject("GoToLineTestProject");
7377
fFile= null;
74-
TestUtil.cleanUp();
7578
}
7679

7780
@Test

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/LargeFileTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.junit.After;
2121
import org.junit.Before;
22+
import org.junit.Rule;
2223
import org.junit.Test;
2324

2425
import org.eclipse.swt.widgets.Display;
@@ -51,6 +52,9 @@
5152
*/
5253
public class LargeFileTest {
5354

55+
@Rule
56+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
57+
5458
private IFile fLargeFile;
5559

5660
private IPreferenceStore preferenceStore;
@@ -84,7 +88,6 @@ public void tearDown() throws Exception {
8488
ResourceHelper.deleteProject("LargeFileTestProject");
8589
fLargeFile= null;
8690
preferenceStore.setValue(AbstractTextEditor.PREFERENCE_WORD_WRAP_ENABLED, initialWordWrap);
87-
TestUtil.cleanUp();
8891
}
8992

9093
@Test

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/MarkerAnnotationOrderTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.After;
2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.osgi.framework.Bundle;
2728

@@ -46,6 +47,9 @@
4647

4748
public class MarkerAnnotationOrderTest {
4849

50+
@Rule
51+
public TestUtilCleanupRule cleanup = new TestUtilCleanupRule();
52+
4953
IContributor pointContributor= null;
5054

5155
Object masterToken= null;
@@ -81,7 +85,6 @@ public void tearDown() throws Exception {
8185
registry.removeExtension(extension, masterToken);
8286
}
8387
}
84-
TestUtil.cleanUp();
8588
}
8689

8790
@Test

0 commit comments

Comments
 (0)