Skip to content

Commit ec2d9bd

Browse files
committed
Stop needlessly pass TestCase instance in harness
Convert the tests to plain JUnit4 while at them too.
1 parent 9e0cb2a commit ec2d9bd

File tree

6 files changed

+66
-93
lines changed

6 files changed

+66
-93
lines changed

tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@
2323
import org.eclipse.ui.internal.WorkbenchWindow;
2424
import org.junit.Assert;
2525

26-
import junit.framework.TestCase;
27-
2826
/**
29-
* <code>ActionUtil</code> contains methods to run actions
30-
* in the workbench.
27+
* <code>ActionUtil</code> contains methods to run actions in the workbench.
3128
*/
3229
public class ActionUtil {
3330

3431
/**
3532
* Runs an action contribution.
3633
*
37-
* @param test the current test case
3834
* @param item an action contribution item
3935
*/
40-
public static void runAction(TestCase test, IContributionItem item) {
36+
public static void runAction(IContributionItem item) {
4137
Assert.assertTrue(item instanceof ActionContributionItem);
4238
((ActionContributionItem) item).getAction().run();
4339
}
@@ -46,18 +42,16 @@ public static void runAction(TestCase test, IContributionItem item) {
4642
* Runs the first action found in a menu manager with a
4743
* particular label.
4844
*
49-
* @param test the current test case
5045
* @param mgr the containing menu manager
5146
* @param label the action label
5247
*/
53-
public static void runActionWithLabel(TestCase test, IMenuManager mgr,
54-
String label) {
48+
public static void runActionWithLabel(IMenuManager mgr, String label) {
5549
IContributionItem[] items = mgr.getItems();
5650
for (IContributionItem item : items) {
57-
if (item instanceof SubContributionItem)
58-
item = ((SubContributionItem) item).getInnerItem();
59-
if (item instanceof ActionContributionItem) {
60-
IAction action = ((ActionContributionItem) item).getAction();
51+
if (item instanceof SubContributionItem subItem)
52+
item = subItem.getInnerItem();
53+
if (item instanceof ActionContributionItem actionContribItem) {
54+
IAction action = actionContribItem.getAction();
6155
if (label.equals(action.getText())) {
6256
action.run();
6357
return;
@@ -71,43 +65,37 @@ public static void runActionWithLabel(TestCase test, IMenuManager mgr,
7165
* Runs the first action found in a window with a
7266
* particular label.
7367
*
74-
* @param test the current test case
7568
* @param win the containing window
7669
* @param label the action label
7770
*/
78-
public static void runActionWithLabel(TestCase test, IWorkbenchWindow win,
79-
String label) {
71+
public static void runActionWithLabel(IWorkbenchWindow win, String label) {
8072
WorkbenchWindow realWin = (WorkbenchWindow) win;
8173
IMenuManager mgr = realWin.getMenuBarManager();
82-
runActionWithLabel(test, mgr, label);
74+
runActionWithLabel(mgr, label);
8375
}
8476

8577
/**
8678
* Runs an action identified by an id path in a
8779
* menu manager.
8880
*
89-
* @param test the current test case
9081
* @param mgr the containing menu manager
9182
*/
92-
public static void runActionUsingPath(TestCase test, IMenuManager mgr,
93-
String idPath) {
83+
public static void runActionUsingPath(IMenuManager mgr, String idPath) {
9484
IContributionItem item = mgr.findUsingPath(idPath);
9585
Assert.assertNotNull(item);
96-
runAction(test, item);
86+
runAction(item);
9787
}
9888

9989
/**
10090
* Runs an action identified by an id path in a
10191
* window.
10292
*
103-
* @param test the current test case
10493
* @param win the containing window
10594
*/
106-
public static void runActionUsingPath(TestCase test, IWorkbenchWindow win,
107-
String idPath) {
95+
public static void runActionUsingPath(IWorkbenchWindow win, String idPath) {
10896
WorkbenchWindow realWin = (WorkbenchWindow) win;
10997
IMenuManager mgr = realWin.getMenuBarManager();
110-
runActionUsingPath(test, mgr, idPath);
98+
runActionUsingPath(mgr, idPath);
11199
}
112100

113101
/**
@@ -122,10 +110,10 @@ public static void runActionUsingPath(TestCase test, IWorkbenchWindow win,
122110
public static IAction getActionWithLabel(IMenuManager mgr, String label) {
123111
IContributionItem[] items = mgr.getItems();
124112
for (IContributionItem item : items) {
125-
if (item instanceof SubContributionItem)
126-
item = ((SubContributionItem) item).getInnerItem();
127-
if (item instanceof ActionContributionItem) {
128-
IAction action = ((ActionContributionItem) item).getAction();
113+
if (item instanceof SubContributionItem subItem)
114+
item = subItem.getInnerItem();
115+
if (item instanceof ActionContributionItem actionContribItem) {
116+
IAction action = actionContribItem.getAction();
129117
if (label.equals(action.getText())) {
130118
return action;
131119
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionBarsTest.java

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

16+
import static org.eclipse.ui.tests.harness.util.UITestCase.openTestWindow;
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.Assert.assertNull;
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
22+
1623
import org.eclipse.core.commands.NotEnabledException;
1724
import org.eclipse.core.commands.NotHandledException;
1825
import org.eclipse.jface.action.Action;
@@ -28,20 +35,22 @@
2835
import org.eclipse.ui.handlers.IHandlerService;
2936
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
3037
import org.eclipse.ui.tests.harness.util.ActionUtil;
31-
import org.eclipse.ui.tests.harness.util.UITestCase;
38+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
39+
import org.junit.Before;
40+
import org.junit.Rule;
3241
import org.junit.Test;
33-
import org.junit.runner.RunWith;
34-
import org.junit.runners.JUnit4;
3542

3643
/**
3744
* Test the lifecycle of an action delegate.
3845
*/
39-
@RunWith(JUnit4.class)
40-
public class IActionBarsTest extends UITestCase {
46+
public class IActionBarsTest {
47+
48+
private IWorkbenchWindow fWindow;
4149

42-
protected IWorkbenchWindow fWindow;
50+
private IWorkbenchPage fPage;
4351

44-
protected IWorkbenchPage fPage;
52+
@Rule
53+
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
4554

4655
private static class MockAction extends Action {
4756
public boolean hasRun = false;
@@ -56,16 +65,9 @@ public void run() {
5665
}
5766
}
5867

59-
/**
60-
* Constructor for IActionDelegateTest
61-
*/
62-
public IActionBarsTest() {
63-
super(IActionBarsTest.class.getSimpleName());
64-
}
6568

66-
@Override
67-
protected void doSetUp() throws Exception {
68-
super.doSetUp();
69+
@Before
70+
public void doSetUp() throws Exception {
6971
fWindow = openTestWindow();
7072
fPage = fWindow.getActivePage();
7173
}
@@ -168,7 +170,7 @@ public void testSetGlobalActionHandler() throws Throwable {
168170
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
169171
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
170172

171-
ActionUtil.runActionUsingPath(this, fWindow,
173+
ActionUtil.runActionUsingPath(fWindow,
172174
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
173175
assertTrue(cut.hasRun);
174176
assertTrue(!copy.hasRun);
@@ -187,7 +189,7 @@ public void testSetGlobalActionHandler() throws Throwable {
187189
cut.hasRun = copy.hasRun = undo.hasRun = quit.hasRun = false;
188190
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
189191
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
190-
ActionUtil.runActionUsingPath(this, fWindow,
192+
ActionUtil.runActionUsingPath(fWindow,
191193
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
192194
assertTrue(!cut.hasRun);
193195
assertTrue(!copy.hasRun);
@@ -200,7 +202,7 @@ public void testSetGlobalActionHandler() throws Throwable {
200202
cut.hasRun = copy.hasRun = undo.hasRun = quit.hasRun = false;
201203
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
202204
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
203-
ActionUtil.runActionUsingPath(this, fWindow,
205+
ActionUtil.runActionUsingPath(fWindow,
204206
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
205207
assertTrue(cut.hasRun);
206208
assertTrue(!copy.hasRun);
@@ -219,7 +221,7 @@ private void runMatchingCommand(IWorkbenchWindow window, String actionId) {
219221
// this is not a failure, just a condition to be checked by
220222
// the test
221223
} catch (Exception e) {
222-
fail("Failed to run " + commandId, e);
224+
fail("Failed to run " + commandId);
223225
}
224226
}
225227
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionDelegateTest.java

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

16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.Assert.assertTrue;
19+
1620
import java.util.Arrays;
1721

1822
import org.eclipse.ui.IWorkbenchPage;
1923
import org.eclipse.ui.IWorkbenchWindow;
24+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
2025
import org.eclipse.ui.tests.harness.util.UITestCase;
26+
import org.junit.Before;
27+
import org.junit.Rule;
2128
import org.junit.Test;
2229

2330
/**
2431
* Test the lifecycle of an action delegate.
2532
*/
26-
public abstract class IActionDelegateTest extends UITestCase {
33+
public abstract class IActionDelegateTest {
2734

2835
protected IWorkbenchWindow fWindow;
2936

3037
protected IWorkbenchPage fPage;
3138

32-
/**
33-
* Constructor for IActionDelegateTest
34-
*/
35-
public IActionDelegateTest(String testName) {
36-
super(testName);
37-
}
39+
@Rule
40+
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
3841

39-
@Override
40-
protected void doSetUp() throws Exception {
41-
super.doSetUp();
42-
fWindow = openTestWindow();
42+
@Before
43+
public void doSetUp() throws Exception {
44+
fWindow = UITestCase.openTestWindow();
4345
fPage = fWindow.getActivePage();
4446
}
4547

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorActionDelegateTest.java

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

16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertTrue;
18+
1619
import org.eclipse.core.resources.IFile;
1720
import org.eclipse.core.resources.IProject;
1821
import org.eclipse.jface.action.IMenuManager;
@@ -21,26 +24,16 @@
2124
import org.eclipse.ui.tests.harness.util.ActionUtil;
2225
import org.eclipse.ui.tests.harness.util.FileUtil;
2326
import org.junit.Test;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.JUnit4;
2627

2728
/**
2829
* Tests the lifecycle for an editor action delegate.
2930
*/
30-
@RunWith(JUnit4.class)
3131
public class IEditorActionDelegateTest extends IActionDelegateTest {
3232

3333
public static String EDITOR_ID = "org.eclipse.ui.tests.api.IEditorActionDelegateTest";
3434

3535
private MockEditorPart editor;
3636

37-
/**
38-
* Constructor for IWorkbenchWindowActionDelegateTest
39-
*/
40-
public IEditorActionDelegateTest() {
41-
super(IEditorActionDelegateTest.class.getSimpleName());
42-
}
43-
4437
@Test
4538
public void testSetActiveEditor() throws Throwable {
4639
// When an action delegate is run the
@@ -69,7 +62,7 @@ protected void runAction(Object widget) throws Throwable {
6962
MockEditorActionBarContributor contributor = (MockEditorActionBarContributor) editor
7063
.getEditorSite().getActionBarContributor();
7164
IMenuManager mgr = contributor.getActionBars().getMenuManager();
72-
ActionUtil.runActionWithLabel(this, mgr, "Mock Action");
65+
ActionUtil.runActionWithLabel(mgr, "Mock Action");
7366
}
7467

7568
@Override

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IViewActionDelegateTest.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,20 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.api;
1515

16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertTrue;
18+
1619
import org.eclipse.jface.action.IMenuManager;
1720
import org.eclipse.ui.tests.harness.util.ActionUtil;
1821
import org.junit.Test;
19-
import org.junit.runner.RunWith;
20-
import org.junit.runners.JUnit4;
2122

2223
/**
2324
* Tests the lifecycle for a view action delegate.
2425
*/
25-
@RunWith(JUnit4.class)
2626
public class IViewActionDelegateTest extends IActionDelegateTest {
2727

2828
public static String TEST_VIEW_ID = "org.eclipse.ui.tests.api.IViewActionDelegateTest";
2929

30-
/**
31-
* Constructor for IWorkbenchWindowActionDelegateTest
32-
*/
33-
public IViewActionDelegateTest() {
34-
super(IViewActionDelegateTest.class.getSimpleName());
35-
}
36-
3730
@Test
3831
public void testInit() throws Throwable {
3932
// When an action delegate is run the
@@ -59,7 +52,7 @@ protected Object createActionWidget() throws Throwable {
5952
protected void runAction(Object widget) throws Throwable {
6053
MockViewPart view = (MockViewPart) widget;
6154
IMenuManager mgr = view.getViewSite().getActionBars().getMenuManager();
62-
ActionUtil.runActionWithLabel(this, mgr, "Mock Action");
55+
ActionUtil.runActionWithLabel(mgr, "Mock Action");
6356
}
6457

6558
@Override

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowActionDelegateTest.java

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

16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertFalse;
18+
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.Assert.assertTrue;
20+
1621
import java.util.Arrays;
1722

1823
import org.eclipse.ui.IActionDelegate2;
1924
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
2025
import org.eclipse.ui.tests.harness.util.ActionUtil;
2126
import org.junit.Ignore;
2227
import org.junit.Test;
23-
import org.junit.runner.RunWith;
24-
import org.junit.runners.JUnit4;
2528

2629
/**
2730
* Tests the lifecycle for a window action delegate.
2831
*/
29-
@RunWith(JUnit4.class)
3032
public class IWorkbenchWindowActionDelegateTest extends IActionDelegateTest {
3133

32-
/**
33-
* Constructor for IWorkbenchWindowActionDelegateTest
34-
*/
35-
public IWorkbenchWindowActionDelegateTest() {
36-
super(IWorkbenchWindowActionDelegateTest.class.getSimpleName());
37-
}
38-
3934
@Test
4035
@Override
4136
public void testRun() throws Throwable {
@@ -123,7 +118,7 @@ protected Object createActionWidget() throws Throwable {
123118

124119
@Override
125120
protected void runAction(Object widget) throws Throwable {
126-
ActionUtil.runActionWithLabel(this, fWindow, "Mock Action");
121+
ActionUtil.runActionWithLabel(fWindow, "Mock Action");
127122
}
128123

129124
@Override

0 commit comments

Comments
 (0)