Skip to content

Commit 44bfc55

Browse files
committed
Replace navigator tests hierarchy to UITestCase with test rule
1 parent 93e7d58 commit 44bfc55

14 files changed

+77
-211
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/BadIndexDecoratorTestCase.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,16 @@
1414

1515
package org.eclipse.ui.tests.decorators;
1616

17-
import org.eclipse.ui.internal.WorkbenchPlugin;
18-
import org.eclipse.ui.internal.decorators.DecoratorDefinition;
1917
import org.junit.Test;
20-
import org.junit.runner.RunWith;
21-
import org.junit.runners.JUnit4;
2218

2319
/**
2420
* @since 3.2
2521
*/
26-
@RunWith(JUnit4.class)
2722
public class BadIndexDecoratorTestCase extends DecoratorEnablementTestCase {
2823

29-
public BadIndexDecoratorTestCase() {
30-
super(BadIndexDecoratorTestCase.class.getSimpleName());
31-
}
32-
33-
/**
34-
* Sets up the hierarchy.
35-
*/
3624
@Override
37-
protected void doSetUp() throws Exception {
38-
super.doSetUp();
39-
createTestFile();
40-
showNav();
41-
42-
WorkbenchPlugin.getDefault().getDecoratorManager().addListener(this);
43-
44-
DecoratorDefinition[] definitions = WorkbenchPlugin.getDefault()
45-
.getDecoratorManager().getAllDecoratorDefinitions();
46-
for (DecoratorDefinition definition2 : definitions) {
47-
if (definition2.getId().equals(
48-
"org.eclipse.ui.tests.decorators.badIndexDecorator")) {
49-
definition = definition2;
50-
}
51-
}
25+
protected String getTestDecoratorId() {
26+
return "org.eclipse.ui.tests.decorators.badIndexDecorator";
5227
}
5328

5429
/**

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorCacheTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.eclipse.ui.tests.decorators;
1616

17+
import static org.junit.Assert.assertTrue;
18+
1719
import org.eclipse.core.runtime.CoreException;
1820
import org.eclipse.jface.viewers.DecoratingLabelProvider;
1921
import org.eclipse.jface.viewers.LabelProvider;
@@ -27,21 +29,14 @@
2729
import org.eclipse.ui.PlatformUI;
2830
import org.eclipse.ui.tests.navigator.AbstractNavigatorTest;
2931
import org.junit.Test;
30-
import org.junit.runner.RunWith;
31-
import org.junit.runners.JUnit4;
3232

3333
/**
3434
* @since 3.4
3535
*/
36-
@RunWith(JUnit4.class)
3736
public class DecoratorCacheTest extends AbstractNavigatorTest {
3837

3938
protected DecoratingLabelProvider dlp;
4039

41-
public DecoratorCacheTest() {
42-
super(DecoratorCacheTest.class.getSimpleName());
43-
}
44-
4540
protected StructuredViewer createViewer(Composite parent) {
4641
dlp = new DecoratingLabelProvider(new LabelProvider(), PlatformUI
4742
.getWorkbench().getDecoratorManager());

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorEnablementTestCase.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.decorators;
1515

16+
import org.eclipse.core.runtime.CoreException;
1617
import org.eclipse.jface.viewers.ILabelProviderListener;
1718
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
1819
import org.eclipse.ui.internal.WorkbenchPlugin;
1920
import org.eclipse.ui.internal.decorators.DecoratorDefinition;
2021
import org.eclipse.ui.internal.decorators.DecoratorManager;
2122
import org.eclipse.ui.tests.navigator.AbstractNavigatorTest;
23+
import org.junit.After;
24+
import org.junit.Before;
2225
import org.junit.Test;
2326

2427
/**
@@ -31,29 +34,18 @@ public abstract class DecoratorEnablementTestCase extends AbstractNavigatorTest
3134

3235
protected boolean updated = false;
3336

34-
/**
35-
* Constructor for DecoratorTestCase.
36-
*/
37-
public DecoratorEnablementTestCase(String testName) {
38-
super(testName);
39-
}
37+
protected abstract String getTestDecoratorId();
4038

41-
/**
42-
* Sets up the hierarchy.
43-
*/
44-
@Override
45-
protected void doSetUp() throws Exception {
46-
super.doSetUp();
39+
@Before
40+
public final void setUpHierarchy() throws CoreException {
4741
createTestFile();
4842
showNav();
4943

50-
WorkbenchPlugin.getDefault().getDecoratorManager().addListener(this);
44+
getDecoratorManager().addListener(this);
5145

52-
DecoratorDefinition[] definitions = WorkbenchPlugin.getDefault()
53-
.getDecoratorManager().getAllDecoratorDefinitions();
46+
DecoratorDefinition[] definitions = getDecoratorManager().getAllDecoratorDefinitions();
5447
for (DecoratorDefinition definition2 : definitions) {
55-
if (definition2.getId().equals(
56-
"org.eclipse.ui.tests.decorators.lightweightdecorator")) {
48+
if (definition2.getId().equals(getTestDecoratorId())) {
5749
definition = definition2;
5850
}
5951
}
@@ -63,16 +55,11 @@ protected DecoratorManager getDecoratorManager() {
6355
return WorkbenchPlugin.getDefault().getDecoratorManager();
6456
}
6557

66-
/**
67-
* Remove the listener.
68-
*/
69-
@Override
70-
protected void doTearDown() throws Exception {
71-
super.doTearDown();
58+
@After
59+
public final void removeListener() throws Exception {
7260
getDecoratorManager().removeListener(this);
7361
}
7462

75-
7663
/**
7764
* Test enabling the contributor
7865
*/

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorTableTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,13 @@
1919
import org.eclipse.ui.IWorkbenchPage;
2020
import org.eclipse.ui.PartInitException;
2121
import org.junit.Ignore;
22-
import org.junit.runner.RunWith;
23-
import org.junit.runners.JUnit4;
2422

2523
/**
2624
* The DecoratorTableTest is the test for decorating tables.
2725
*/
28-
@RunWith(JUnit4.class)
2926
@Ignore("Disabled due to timing issues")
3027
public class DecoratorTableTest extends DecoratorViewerTest {
3128

32-
/**
33-
* Create a new instance of the receiver.
34-
*/
35-
public DecoratorTableTest() {
36-
super(DecoratorTableTest.class.getSimpleName());
37-
}
38-
3929
@Override
4030
protected void backgroundCheck(IViewPart view) {
4131
TableItem first = ((DecoratorTableView) view).viewer.getTable().getItem(0);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorTestCase.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,30 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.decorators;
1515

16+
import static org.junit.Assert.assertTrue;
17+
1618
import org.eclipse.jface.viewers.ILabelProviderListener;
1719
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
1820
import org.eclipse.ui.internal.WorkbenchPlugin;
1921
import org.eclipse.ui.internal.decorators.DecoratorDefinition;
2022
import org.eclipse.ui.internal.decorators.DecoratorManager;
2123
import org.eclipse.ui.tests.navigator.AbstractNavigatorTest;
24+
import org.junit.After;
25+
import org.junit.Before;
2226
import org.junit.Test;
23-
import org.junit.runner.RunWith;
24-
import org.junit.runners.JUnit4;
2527

2628
/**
2729
* @version 1.0
2830
*/
29-
@RunWith(JUnit4.class)
3031
public class DecoratorTestCase extends AbstractNavigatorTest implements
3132
ILabelProviderListener {
3233

3334
private DecoratorDefinition definition;
3435

3536
private boolean updated = false;
3637

37-
/**
38-
* Constructor for DecoratorTestCase.
39-
*/
40-
public DecoratorTestCase() {
41-
super(DecoratorTestCase.class.getSimpleName());
42-
}
43-
44-
/**
45-
* Sets up the hierarchy.
46-
*/
47-
@Override
48-
protected void doSetUp() throws Exception {
49-
super.doSetUp();
38+
@Before
39+
public final void setUpHierarchy() throws Exception {
5040
createTestFile();
5141
showNav();
5242

@@ -69,9 +59,8 @@ private DecoratorManager getDecoratorManager() {
6959
/**
7060
* Remove the listener.
7161
*/
72-
@Override
73-
protected void doTearDown() throws Exception {
74-
super.doTearDown();
62+
@After
63+
public void removeListener() throws Exception {
7564
getDecoratorManager().removeListener(this);
7665
}
7766

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorTreeTest.java

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

16+
import static org.junit.Assert.assertEquals;
17+
1618
import org.eclipse.swt.widgets.TreeItem;
1719
import org.eclipse.ui.IViewPart;
1820
import org.eclipse.ui.IWorkbenchPage;
1921
import org.eclipse.ui.PartInitException;
2022
import org.junit.Ignore;
21-
import org.junit.runner.RunWith;
22-
import org.junit.runners.JUnit4;
2323

2424
/**
2525
* The DecoratorTreeTest tests the font and color support on
2626
* tree viewers.
2727
*/
28-
@RunWith(JUnit4.class)
2928
@Ignore("Disabled due to timing issues")
3029
public class DecoratorTreeTest extends DecoratorViewerTest {
3130

32-
public DecoratorTreeTest() {
33-
super(DecoratorTreeTest.class.getSimpleName());
34-
35-
}
36-
37-
@Override
38-
protected void doSetUp() throws Exception {
39-
super.doSetUp();
40-
createTestFile();
41-
42-
}
43-
4431
@Override
4532
protected void backgroundCheck(IViewPart view) {
4633
TreeItem first = ((DecoratorTreeView) view).viewer.getTree().getItems()[0];

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorViewerTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,17 @@
2525
import org.eclipse.ui.internal.WorkbenchPlugin;
2626
import org.eclipse.ui.internal.decorators.DecoratorManager;
2727
import org.eclipse.ui.tests.navigator.AbstractNavigatorTest;
28+
import org.junit.After;
29+
import org.junit.Before;
2830
import org.junit.Test;
2931

3032
/**
3133
* DecoratorViewerTest is the abstract class of the tests for the viewers.
3234
*/
3335
public abstract class DecoratorViewerTest extends AbstractNavigatorTest {
3436

35-
/**
36-
* Create a new instance of the receiver.
37-
*/
38-
public DecoratorViewerTest(String testName) {
39-
super(testName);
40-
}
41-
42-
@Override
43-
protected void doSetUp() throws Exception {
44-
super.doSetUp();
37+
@Before
38+
public final void setUp() throws Exception {
4539
createTestFile();
4640
ForegroundColorDecorator.setUpColor();
4741
BackgroundColorDecorator.setUpColor();
@@ -163,10 +157,8 @@ public void testFont() throws PartInitException, CoreException,
163157
*/
164158
protected abstract void fontCheck(IViewPart view);
165159

166-
@Override
167-
protected void doTearDown() throws Exception {
168-
169-
super.doTearDown();
160+
@After
161+
public final void tearDown() throws Exception {
170162
IDecoratorManager manager = WorkbenchPlugin.getDefault()
171163
.getDecoratorManager();
172164
manager.setEnabled(ForegroundColorDecorator.ID, false);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/ExceptionDecoratorTestCase.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,34 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.decorators;
1515

16+
import static org.junit.Assert.assertFalse;
17+
1618
import java.util.ArrayList;
1719
import java.util.Collection;
18-
import java.util.Iterator;
1920

2021
import org.eclipse.core.runtime.OperationCanceledException;
2122
import org.eclipse.core.runtime.jobs.Job;
2223
import org.eclipse.ui.internal.WorkbenchPlugin;
2324
import org.eclipse.ui.internal.decorators.DecoratorDefinition;
2425
import org.eclipse.ui.internal.decorators.DecoratorManager;
25-
import org.junit.runner.RunWith;
26-
import org.junit.runners.JUnit4;
26+
import org.junit.After;
27+
import org.junit.Before;
2728

2829
/**
2930
* @version 1.0
3031
*/
31-
@RunWith(JUnit4.class)
3232
public class ExceptionDecoratorTestCase extends DecoratorEnablementTestCase {
3333
private final Collection<DecoratorDefinition> problemDecorators = new ArrayList<>();
3434

3535
private DecoratorDefinition light;
3636

37-
/**
38-
* Constructor for DecoratorTestCase.
39-
*/
40-
public ExceptionDecoratorTestCase() {
41-
super(ExceptionDecoratorTestCase.class.getSimpleName());
37+
@Override
38+
protected String getTestDecoratorId() {
39+
return "org.eclipse.ui.tests.decorators.lightweightdecorator";
4240
}
4341

44-
/**
45-
* Sets up the hierarchy.
46-
*/
47-
@Override
48-
protected void doSetUp() throws Exception {
42+
@Before
43+
public void setUpAdditionalDecorators() throws Exception {
4944
//reset the static fields so that the decorators will fail
5045
HeavyNullImageDecorator.fail = true;
5146
HeavyNullTextDecorator.fail = true;
@@ -67,12 +62,10 @@ protected void doSetUp() throws Exception {
6762
light = definition2;
6863
}
6964
}
70-
super.doSetUp();
7165
}
7266

73-
@Override
74-
protected void doTearDown() throws Exception {
75-
super.doTearDown();
67+
@After
68+
public void tearDown() throws Exception {
7669

7770
//Need to wait for decoration to end to allow for all
7871
//errors to occur
@@ -81,11 +74,7 @@ protected void doTearDown() throws Exception {
8174
} catch (OperationCanceledException | InterruptedException e) {
8275
}
8376

84-
//Be sure that the decorators were all disabled on errors.
85-
Iterator<DecoratorDefinition> problemIterator = problemDecorators.iterator();
86-
while (problemIterator.hasNext()) {
87-
DecoratorDefinition next = problemIterator
88-
.next();
77+
for (DecoratorDefinition next : problemDecorators) {
8978
assertFalse("Enabled " + next.getName(), next.isEnabled());
9079
}
9180

0 commit comments

Comments
 (0)