diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
index 463fc20734d..de37498d2b2 100644
--- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
+++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
@@ -23,21 +23,17 @@
import org.eclipse.ui.internal.WorkbenchWindow;
import org.junit.Assert;
-import junit.framework.TestCase;
-
/**
- * ActionUtil
contains methods to run actions
- * in the workbench.
+ * ActionUtil
contains methods to run actions in the workbench.
*/
public class ActionUtil {
/**
* Runs an action contribution.
*
- * @param test the current test case
* @param item an action contribution item
*/
- public static void runAction(TestCase test, IContributionItem item) {
+ public static void runAction(IContributionItem item) {
Assert.assertTrue(item instanceof ActionContributionItem);
((ActionContributionItem) item).getAction().run();
}
@@ -46,18 +42,16 @@ public static void runAction(TestCase test, IContributionItem item) {
* Runs the first action found in a menu manager with a
* particular label.
*
- * @param test the current test case
* @param mgr the containing menu manager
* @param label the action label
*/
- public static void runActionWithLabel(TestCase test, IMenuManager mgr,
- String label) {
+ public static void runActionWithLabel(IMenuManager mgr, String label) {
IContributionItem[] items = mgr.getItems();
for (IContributionItem item : items) {
- if (item instanceof SubContributionItem)
- item = ((SubContributionItem) item).getInnerItem();
- if (item instanceof ActionContributionItem) {
- IAction action = ((ActionContributionItem) item).getAction();
+ if (item instanceof SubContributionItem subItem)
+ item = subItem.getInnerItem();
+ if (item instanceof ActionContributionItem actionContribItem) {
+ IAction action = actionContribItem.getAction();
if (label.equals(action.getText())) {
action.run();
return;
@@ -71,43 +65,37 @@ public static void runActionWithLabel(TestCase test, IMenuManager mgr,
* Runs the first action found in a window with a
* particular label.
*
- * @param test the current test case
* @param win the containing window
* @param label the action label
*/
- public static void runActionWithLabel(TestCase test, IWorkbenchWindow win,
- String label) {
+ public static void runActionWithLabel(IWorkbenchWindow win, String label) {
WorkbenchWindow realWin = (WorkbenchWindow) win;
IMenuManager mgr = realWin.getMenuBarManager();
- runActionWithLabel(test, mgr, label);
+ runActionWithLabel(mgr, label);
}
/**
* Runs an action identified by an id path in a
* menu manager.
*
- * @param test the current test case
* @param mgr the containing menu manager
*/
- public static void runActionUsingPath(TestCase test, IMenuManager mgr,
- String idPath) {
+ public static void runActionUsingPath(IMenuManager mgr, String idPath) {
IContributionItem item = mgr.findUsingPath(idPath);
Assert.assertNotNull(item);
- runAction(test, item);
+ runAction(item);
}
/**
* Runs an action identified by an id path in a
* window.
*
- * @param test the current test case
* @param win the containing window
*/
- public static void runActionUsingPath(TestCase test, IWorkbenchWindow win,
- String idPath) {
+ public static void runActionUsingPath(IWorkbenchWindow win, String idPath) {
WorkbenchWindow realWin = (WorkbenchWindow) win;
IMenuManager mgr = realWin.getMenuBarManager();
- runActionUsingPath(test, mgr, idPath);
+ runActionUsingPath(mgr, idPath);
}
/**
@@ -122,10 +110,10 @@ public static void runActionUsingPath(TestCase test, IWorkbenchWindow win,
public static IAction getActionWithLabel(IMenuManager mgr, String label) {
IContributionItem[] items = mgr.getItems();
for (IContributionItem item : items) {
- if (item instanceof SubContributionItem)
- item = ((SubContributionItem) item).getInnerItem();
- if (item instanceof ActionContributionItem) {
- IAction action = ((ActionContributionItem) item).getAction();
+ if (item instanceof SubContributionItem subItem)
+ item = subItem.getInnerItem();
+ if (item instanceof ActionContributionItem actionContribItem) {
+ IAction action = actionContribItem.getAction();
if (label.equals(action.getText())) {
return action;
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionBarsTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionBarsTest.java
index 0e140470dd3..5f448ff67d7 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionBarsTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionBarsTest.java
@@ -13,6 +13,13 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.eclipse.ui.tests.harness.util.UITestCase.openTestWindow;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.jface.action.Action;
@@ -28,20 +35,22 @@
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
import org.eclipse.ui.tests.harness.util.ActionUtil;
-import org.eclipse.ui.tests.harness.util.UITestCase;
+import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Test the lifecycle of an action delegate.
*/
-@RunWith(JUnit4.class)
-public class IActionBarsTest extends UITestCase {
+public class IActionBarsTest {
+
+ private IWorkbenchWindow fWindow;
- protected IWorkbenchWindow fWindow;
+ private IWorkbenchPage fPage;
- protected IWorkbenchPage fPage;
+ @Rule
+ public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
private static class MockAction extends Action {
public boolean hasRun = false;
@@ -56,16 +65,9 @@ public void run() {
}
}
- /**
- * Constructor for IActionDelegateTest
- */
- public IActionBarsTest() {
- super(IActionBarsTest.class.getSimpleName());
- }
- @Override
- protected void doSetUp() throws Exception {
- super.doSetUp();
+ @Before
+ public void doSetUp() throws Exception {
fWindow = openTestWindow();
fPage = fWindow.getActivePage();
}
@@ -168,7 +170,7 @@ public void testSetGlobalActionHandler() throws Throwable {
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
- ActionUtil.runActionUsingPath(this, fWindow,
+ ActionUtil.runActionUsingPath(fWindow,
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
assertTrue(cut.hasRun);
assertTrue(!copy.hasRun);
@@ -187,7 +189,7 @@ public void testSetGlobalActionHandler() throws Throwable {
cut.hasRun = copy.hasRun = undo.hasRun = quit.hasRun = false;
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
- ActionUtil.runActionUsingPath(this, fWindow,
+ ActionUtil.runActionUsingPath(fWindow,
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
assertTrue(!cut.hasRun);
assertTrue(!copy.hasRun);
@@ -200,7 +202,7 @@ public void testSetGlobalActionHandler() throws Throwable {
cut.hasRun = copy.hasRun = undo.hasRun = quit.hasRun = false;
runMatchingCommand(fWindow, ActionFactory.CUT.getId());
runMatchingCommand(fWindow, ActionFactory.UNDO.getId());
- ActionUtil.runActionUsingPath(this, fWindow,
+ ActionUtil.runActionUsingPath(fWindow,
IWorkbenchActionConstants.M_FILE + '/' + IWorkbenchActionConstants.QUIT);
assertTrue(cut.hasRun);
assertTrue(!copy.hasRun);
@@ -219,7 +221,7 @@ private void runMatchingCommand(IWorkbenchWindow window, String actionId) {
// this is not a failure, just a condition to be checked by
// the test
} catch (Exception e) {
- fail("Failed to run " + commandId, e);
+ fail("Failed to run " + commandId);
}
}
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionDelegateTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionDelegateTest.java
index 853c3cc5ffc..e932ab85c4f 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionDelegateTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IActionDelegateTest.java
@@ -13,33 +13,35 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Arrays;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
import org.eclipse.ui.tests.harness.util.UITestCase;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
/**
* Test the lifecycle of an action delegate.
*/
-public abstract class IActionDelegateTest extends UITestCase {
+public abstract class IActionDelegateTest {
protected IWorkbenchWindow fWindow;
protected IWorkbenchPage fPage;
- /**
- * Constructor for IActionDelegateTest
- */
- public IActionDelegateTest(String testName) {
- super(testName);
- }
+ @Rule
+ public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
- @Override
- protected void doSetUp() throws Exception {
- super.doSetUp();
- fWindow = openTestWindow();
+ @Before
+ public void doSetUp() throws Exception {
+ fWindow = UITestCase.openTestWindow();
fPage = fWindow.getActivePage();
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorActionDelegateTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorActionDelegateTest.java
index d5d841e8965..c3060b4ff8a 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorActionDelegateTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorActionDelegateTest.java
@@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IMenuManager;
@@ -21,26 +24,16 @@
import org.eclipse.ui.tests.harness.util.ActionUtil;
import org.eclipse.ui.tests.harness.util.FileUtil;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Tests the lifecycle for an editor action delegate.
*/
-@RunWith(JUnit4.class)
public class IEditorActionDelegateTest extends IActionDelegateTest {
public static String EDITOR_ID = "org.eclipse.ui.tests.api.IEditorActionDelegateTest";
private MockEditorPart editor;
- /**
- * Constructor for IWorkbenchWindowActionDelegateTest
- */
- public IEditorActionDelegateTest() {
- super(IEditorActionDelegateTest.class.getSimpleName());
- }
-
@Test
public void testSetActiveEditor() throws Throwable {
// When an action delegate is run the
@@ -69,7 +62,7 @@ protected void runAction(Object widget) throws Throwable {
MockEditorActionBarContributor contributor = (MockEditorActionBarContributor) editor
.getEditorSite().getActionBarContributor();
IMenuManager mgr = contributor.getActionBars().getMenuManager();
- ActionUtil.runActionWithLabel(this, mgr, "Mock Action");
+ ActionUtil.runActionWithLabel(mgr, "Mock Action");
}
@Override
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IViewActionDelegateTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IViewActionDelegateTest.java
index d5bcbb517f2..5cfcaeac7a4 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IViewActionDelegateTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IViewActionDelegateTest.java
@@ -13,27 +13,20 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.tests.harness.util.ActionUtil;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Tests the lifecycle for a view action delegate.
*/
-@RunWith(JUnit4.class)
public class IViewActionDelegateTest extends IActionDelegateTest {
public static String TEST_VIEW_ID = "org.eclipse.ui.tests.api.IViewActionDelegateTest";
- /**
- * Constructor for IWorkbenchWindowActionDelegateTest
- */
- public IViewActionDelegateTest() {
- super(IViewActionDelegateTest.class.getSimpleName());
- }
-
@Test
public void testInit() throws Throwable {
// When an action delegate is run the
@@ -59,7 +52,7 @@ protected Object createActionWidget() throws Throwable {
protected void runAction(Object widget) throws Throwable {
MockViewPart view = (MockViewPart) widget;
IMenuManager mgr = view.getViewSite().getActionBars().getMenuManager();
- ActionUtil.runActionWithLabel(this, mgr, "Mock Action");
+ ActionUtil.runActionWithLabel(mgr, "Mock Action");
}
@Override
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowActionDelegateTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowActionDelegateTest.java
index 5c6ba6bbb0e..f82ca14b3e5 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowActionDelegateTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowActionDelegateTest.java
@@ -13,6 +13,11 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Arrays;
import org.eclipse.ui.IActionDelegate2;
@@ -20,22 +25,12 @@
import org.eclipse.ui.tests.harness.util.ActionUtil;
import org.junit.Ignore;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Tests the lifecycle for a window action delegate.
*/
-@RunWith(JUnit4.class)
public class IWorkbenchWindowActionDelegateTest extends IActionDelegateTest {
- /**
- * Constructor for IWorkbenchWindowActionDelegateTest
- */
- public IWorkbenchWindowActionDelegateTest() {
- super(IWorkbenchWindowActionDelegateTest.class.getSimpleName());
- }
-
@Test
@Override
public void testRun() throws Throwable {
@@ -123,7 +118,7 @@ protected Object createActionWidget() throws Throwable {
@Override
protected void runAction(Object widget) throws Throwable {
- ActionUtil.runActionWithLabel(this, fWindow, "Mock Action");
+ ActionUtil.runActionWithLabel(fWindow, "Mock Action");
}
@Override