Skip to content

Commit bb8824a

Browse files
committed
Creates TestUtil.CleanupRule based on TestUtil
In #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.
1 parent cd33843 commit bb8824a

22 files changed

+113
-64
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;
@@ -58,6 +59,10 @@
5859
import org.eclipse.ui.editors.tests.TestUtil;
5960

6061
public class CodeMiningTest {
62+
63+
@Rule
64+
public TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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() {
@@ -357,4 +361,4 @@ private final boolean waitForCondition(Display display, long timeout, Callable<B
357361
} while (!cond && diff < timeout);
358362
return cond;
359363
}
360-
}
364+
}

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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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: 5 additions & 6 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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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
@@ -140,4 +139,4 @@ public void testChainedStore3() {
140139
assertEquals(null, event.getOldValue());
141140
assertEquals(DEFAULT_VALUE, event.getNewValue());
142141
}
143-
}
142+
}

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

Lines changed: 4 additions & 2 deletions
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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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
@@ -81,4 +83,4 @@ public static class TestDocumentProvider extends TextFileDocumentProvider {
8183
// found the right one.
8284

8385
}
84-
}
86+
}

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

Lines changed: 5 additions & 2 deletions
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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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
@@ -186,4 +189,4 @@ public void testAInvalidEncoding() {
186189
fail();
187190
}
188191
}
189-
}
192+
}

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

Lines changed: 5 additions & 3 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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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
@@ -432,4 +434,4 @@ public IStatus run2() {
432434
}
433435
return Status.OK_STATUS;
434436
}
435-
}
437+
}

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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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: 5 additions & 2 deletions
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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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
@@ -122,4 +125,4 @@ private void goToLine(int line, int expectedResult) {
122125
fail();
123126
}
124127
}
125-
}
128+
}

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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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 TestUtil.CleanupRule cleanup = new TestUtil.CleanupRule();
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)