Skip to content

Commit 2ebbbe9

Browse files
committed
Convert o.e.ui.tests to plain JUnit (part 2)
Reduce inheritance, simplify setup/teardown, improve assertions, etc.
1 parent 68e6337 commit 2ebbbe9

30 files changed

+269
-471
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/activities/ImagesTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@
2929
import org.eclipse.ui.tests.harness.util.ImageTests;
3030
import org.junit.After;
3131
import org.junit.Test;
32-
import org.junit.runner.RunWith;
33-
import org.junit.runners.JUnit4;
3432

3533
/**
3634
* @since 3.1
3735
*/
38-
@RunWith(JUnit4.class)
3936
public class ImagesTest {
4037

4138
private Image defaultImage;

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/activities/MenusTest.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertFalse;
19+
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.assertTrue;
21+
1722
import java.util.Collections;
1823
import java.util.Set;
1924

@@ -25,16 +30,12 @@
2530
import org.eclipse.ui.menus.IMenuService;
2631
import org.eclipse.ui.services.IServiceLocator;
2732
import org.eclipse.ui.tests.harness.util.UITestCase;
33+
import org.junit.After;
34+
import org.junit.Before;
2835
import org.junit.Ignore;
2936
import org.junit.Test;
30-
import org.junit.runner.RunWith;
31-
import org.junit.runners.JUnit4;
3237

33-
/**
34-
* @since 3.3
35-
*/
36-
@RunWith(JUnit4.class)
37-
public class MenusTest extends UITestCase {
38+
public class MenusTest {
3839

3940
private TestFactory factory;
4041
private IWorkbenchWindow window;
@@ -81,22 +82,17 @@ public CommandContributionItem getBarItemWithNoVisibilityClause() {
8182
}
8283
}
8384

84-
public MenusTest() {
85-
super(MenusTest.class.getSimpleName());
86-
}
87-
88-
@Override
89-
protected void doSetUp() throws Exception {
90-
super.doSetUp();
91-
window = openTestWindow();
85+
@Before
86+
public void doSetUp() throws Exception {
87+
window = UITestCase.openTestWindow();
9288
enabledActivities = window.getWorkbench().getActivitySupport()
9389
.getActivityManager().getEnabledActivityIds();
9490
service = window.getService(IMenuService.class);
9591
assertNotNull(service);
9692
}
9793

98-
@Override
99-
protected void doTearDown() throws Exception {
94+
@After
95+
public void doTearDown() throws Exception {
10096
window.getWorkbench().getActivitySupport().setEnabledActivityIds(
10197
enabledActivities);
10298
assertEquals(enabledActivities, window.getWorkbench()
@@ -105,7 +101,6 @@ protected void doTearDown() throws Exception {
105101
if (factory != null) {
106102
service.removeContributionFactory(factory);
107103
}
108-
super.doTearDown();
109104
}
110105

111106
@Test

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/activities/StaticTest.java

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

16+
import static org.junit.Assert.assertTrue;
17+
1618
import java.util.ArrayList;
1719
import java.util.List;
1820
import java.util.Set;
@@ -26,18 +28,14 @@
2628
import org.eclipse.ui.activities.NotDefinedException;
2729
import org.eclipse.ui.internal.activities.ActivityRequirementBinding;
2830
import org.eclipse.ui.internal.activities.CategoryActivityBinding;
29-
import org.eclipse.ui.tests.harness.util.UITestCase;
3031
import org.junit.Test;
31-
import org.junit.runner.RunWith;
32-
import org.junit.runners.JUnit4;
3332

3433
/**
3534
*
3635
* The static test reads activity definitions from the plugin.xml (in
3736
* org.eclipse.ui.tests) file and valides its content.
3837
*/
39-
@RunWith(JUnit4.class)
40-
public class StaticTest extends UITestCase {
38+
public class StaticTest {
4139
private final IActivityManager activityManager;
4240

4341
private List<String> categoryIds;
@@ -47,7 +45,6 @@ public class StaticTest extends UITestCase {
4745
private List<Object> patternActivityIds;
4846

4947
public StaticTest() {
50-
super(StaticTest.class.getSimpleName());
5148
activityManager = PlatformUI.getWorkbench().getActivitySupport()
5249
.getActivityManager();
5350
populateIds();

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/adaptable/MarkerImageProviderTest.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,49 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.adaptable;
1515

16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertTrue;
18+
1619
import org.eclipse.core.resources.IMarker;
1720
import org.eclipse.core.resources.IWorkspace;
1821
import org.eclipse.core.resources.ResourcesPlugin;
1922
import org.eclipse.core.runtime.CoreException;
2023
import org.eclipse.jface.resource.ImageDescriptor;
2124
import org.eclipse.ui.model.IWorkbenchAdapter;
22-
import org.eclipse.ui.tests.harness.util.UITestCase;
2325
import org.junit.Test;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.JUnit4;
2626

2727
/**
2828
* Tests the markerImageProviders extension point.
2929
*/
30-
@RunWith(JUnit4.class)
31-
public class MarkerImageProviderTest extends UITestCase {
32-
33-
public MarkerImageProviderTest() {
34-
super(MarkerImageProviderTest.class.getSimpleName());
35-
}
30+
public class MarkerImageProviderTest {
3631

3732
/**
3833
* Tests the static form of the extension, where just a file path is given.
34+
*
35+
* @throws CoreException
3936
*/
4037
@Test
41-
public void testStatic() {
38+
public void testStatic() throws CoreException {
4239
IWorkspace workspace = ResourcesPlugin.getWorkspace();
43-
IMarker marker = null;
44-
try {
45-
marker = workspace.getRoot().createMarker(
40+
IMarker marker = workspace.getRoot().createMarker(
4641
"org.eclipse.ui.tests.testmarker"); //$NON-NLS-1$
47-
} catch (CoreException e) {
48-
fail(e.getMessage());
49-
}
5042
IWorkbenchAdapter adapter = marker.getAdapter(IWorkbenchAdapter.class);
5143
ImageDescriptor imageDesc = adapter.getImageDescriptor(marker);
5244
assertNotNull(imageDesc);
5345
assertTrue(imageDesc.toString().contains("anything")); //$NON-NLS-1$
5446
}
5547

5648
/**
57-
* Tests the dynamic form of the extension, where an IMarkerImageProvider class is given.
49+
* Tests the dynamic form of the extension, where an IMarkerImageProvider class
50+
* is given.
51+
*
52+
* @throws CoreException
5853
*/
5954
@Test
60-
public void testDynamic() {
55+
public void testDynamic() throws CoreException {
6156
IWorkspace workspace = ResourcesPlugin.getWorkspace();
62-
IMarker marker = null;
63-
try {
64-
marker = workspace.getRoot().createMarker(
57+
IMarker marker = workspace.getRoot().createMarker(
6558
"org.eclipse.ui.tests.testmarker2"); //$NON-NLS-1$
66-
} catch (CoreException e) {
67-
fail(e.getMessage());
68-
}
6959
IWorkbenchAdapter adapter = marker.getAdapter(IWorkbenchAdapter.class);
7060
ImageDescriptor imageDesc = adapter.getImageDescriptor(marker);
7161
assertNotNull(imageDesc);

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414

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

17+
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.Assert.assertNull;
19+
1720
import java.net.URL;
1821

1922
import org.eclipse.core.runtime.FileLocator;
2023
import org.eclipse.jface.resource.ImageDescriptor;
2124
import org.eclipse.jface.resource.ResourceLocator;
2225
import org.eclipse.swt.graphics.Image;
26+
import org.eclipse.ui.PlatformUI;
2327
import org.eclipse.ui.tests.harness.util.ImageTests;
24-
import org.eclipse.ui.tests.harness.util.UITestCase;
2528
import org.junit.Test;
26-
import org.junit.runner.RunWith;
27-
import org.junit.runners.JUnit4;
2829

2930
/**
3031
* Tests to ensure that various icon scenarios work. These are tested on editors
@@ -33,20 +34,15 @@
3334
*
3435
* @since 3.0
3536
*/
36-
@RunWith(JUnit4.class)
37-
public class EditorIconTest extends UITestCase {
38-
39-
public EditorIconTest() {
40-
super(EditorIconTest.class.getSimpleName());
41-
}
37+
public class EditorIconTest {
4238

4339
@Test
4440
public void testDependantBundleIcon() {
4541
Image i1 = null;
4642
Image i2 = null;
4743

4844
try {
49-
i1 = fWorkbench.getEditorRegistry().getDefaultEditor(
45+
i1 = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(
5046
"foo.icontest1").getImageDescriptor().createImage();
5147
i2 = ResourceLocator.imageDescriptorFromBundle("org.eclipse.ui", "icons/full/obj16/font.png")
5248
.orElseThrow(AssertionError::new).createImage();
@@ -67,7 +63,8 @@ public void testNonDependantBundleIcon() {
6763
Image i1 = null;
6864
Image i2 = null;
6965
try {
70-
i1 = fWorkbench.getEditorRegistry().getDefaultEditor(
66+
i1 = PlatformUI.getWorkbench().getEditorRegistry()
67+
.getDefaultEditor(
7168
"foo.icontest2").getImageDescriptor().createImage();
7269
i2 = ResourceLocator.imageDescriptorFromBundle(
7370
"org.eclipse.jdt.ui", "icons/full/obj16/class_obj.png") // layer breaker!
@@ -90,7 +87,7 @@ public void testBadIcon() {
9087
Image i2 = null;
9188

9289
try {
93-
i1 = fWorkbench.getEditorRegistry().getDefaultEditor(
90+
i1 = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(
9491
"foo.icontest3").getImageDescriptor().createImage();
9592
i2 = ResourceLocator.imageDescriptorFromBundle("org.eclipse.ui", "icons/full/obj16/file_obj.png")
9693
.orElseThrow(AssertionError::new).createImage();

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

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

16+
import static org.junit.Assert.assertTrue;
17+
18+
import org.eclipse.ui.PlatformUI;
1619
import org.eclipse.ui.tests.TestPlugin;
17-
import org.eclipse.ui.tests.harness.util.UITestCase;
20+
import org.junit.After;
21+
import org.junit.Before;
1822
import org.junit.Test;
19-
import org.junit.runner.RunWith;
20-
import org.junit.runners.JUnit4;
21-
22-
@RunWith(JUnit4.class)
23-
public class StartupTest extends UITestCase {
2423

25-
/**
26-
* Construct an instance.
27-
*/
28-
public StartupTest() {
29-
super(StartupTest.class.getSimpleName());
30-
}
24+
public class StartupTest {
3125

3226
@Test
3327
public void testStartup() {
@@ -36,9 +30,13 @@ public void testStartup() {
3630
assertTrue("Startup - completed before tests", StartupClass.getEarlyStartupCompleted());
3731
}
3832

39-
@Override
40-
protected void doTearDown() throws Exception {
41-
super.doTearDown();
33+
@Before
34+
public void doSetUp() {
35+
PlatformUI.getWorkbench();
36+
}
37+
38+
@After
39+
public void doTearDown() throws Exception {
4240
// NOTE: tearDown will run after each test. Therefore, we
4341
// only want one test in this suite (or the values set when
4442
// this plugin started up will be lost).

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/ActionDelegateProxyTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@
4141
import org.junit.Ignore;
4242
import org.junit.Rule;
4343
import org.junit.Test;
44-
import org.junit.runner.RunWith;
45-
import org.junit.runners.JUnit4;
4644

47-
/**
48-
* @since 3.3
49-
*/
50-
@RunWith(JUnit4.class)
5145
@Ignore("broke during e4 transition and still need adjustments")
5246
public class ActionDelegateProxyTest {
5347

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandEnablementTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@
7474
import org.junit.Ignore;
7575
import org.junit.Rule;
7676
import org.junit.Test;
77-
import org.junit.runner.RunWith;
78-
import org.junit.runners.JUnit4;
7977

8078
/**
8179
* @since 3.3
8280
*/
83-
@RunWith(JUnit4.class)
8481
@Ignore("broke during e4 transition and still need adjustments")
8582
public class CommandEnablementTest {
8683

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HelpContextIdTest.java

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

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

17+
import static org.junit.Assert.assertEquals;
18+
1719
import org.eclipse.core.commands.AbstractHandler;
1820
import org.eclipse.core.commands.Command;
1921
import org.eclipse.core.commands.ExecutionEvent;
@@ -23,20 +25,17 @@
2325
import org.eclipse.core.expressions.ExpressionInfo;
2426
import org.eclipse.core.expressions.IEvaluationContext;
2527
import org.eclipse.ui.ISources;
28+
import org.eclipse.ui.PlatformUI;
2629
import org.eclipse.ui.commands.ICommandService;
2730
import org.eclipse.ui.handlers.IHandlerService;
28-
import org.eclipse.ui.tests.harness.util.UITestCase;
2931
import org.junit.Test;
30-
import org.junit.runner.RunWith;
31-
import org.junit.runners.JUnit4;
3232

3333
/**
3434
* Tests the new help context identifier support on commands and handlers.
3535
*
3636
* @since 3.2
3737
*/
38-
@RunWith(JUnit4.class)
39-
public final class HelpContextIdTest extends UITestCase {
38+
public final class HelpContextIdTest {
4039

4140
private static final String COMMAND_HELP_ID = "org.eclipse.ui.tests.commandHelp";
4241

@@ -46,13 +45,6 @@ public final class HelpContextIdTest extends UITestCase {
4645

4746
private static final String NEW_HELP_ID = "new_help_id";
4847

49-
/**
50-
* Constructs a new instance of <code>HelpContextIdTest</code>
51-
*/
52-
public HelpContextIdTest() {
53-
super(HelpContextIdTest.class.getSimpleName());
54-
}
55-
5648
/**
5749
* Tests the reading of the help context identifier of the registry, as well
5850
* as programmatic changes. It does not test whether there is notification.
@@ -63,9 +55,9 @@ public HelpContextIdTest() {
6355
*/
6456
@Test
6557
public final void testHelpContextId() throws NotDefinedException {
66-
final ICommandService commandService = fWorkbench
58+
final ICommandService commandService = PlatformUI.getWorkbench()
6759
.getService(ICommandService.class);
68-
final IHandlerService handlerService = fWorkbench
60+
final IHandlerService handlerService = PlatformUI.getWorkbench()
6961
.getService(IHandlerService.class);
7062
String helpContextId = null;
7163

0 commit comments

Comments
 (0)