Skip to content

Commit 68e6337

Browse files
committed
Convert some o.e.ui.tests to plain JUnit
Reduce inheritance, simplify setup/teardown, improve assertions, etc.
1 parent 98da4d9 commit 68e6337

20 files changed

+181
-356
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/StyledStringHighlighterTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,34 @@
1515

1616
package org.eclipse.ui.tests;
1717

18+
import static org.junit.Assert.assertEquals;
19+
1820
import org.eclipse.jface.text.contentassist.BoldStylerProvider;
1921
import org.eclipse.jface.viewers.StyledString;
2022
import org.eclipse.swt.SWT;
2123
import org.eclipse.swt.custom.StyleRange;
2224
import org.eclipse.swt.graphics.Font;
25+
import org.eclipse.swt.widgets.Display;
2326
import org.eclipse.ui.dialogs.StyledStringHighlighter;
24-
import org.eclipse.ui.tests.harness.util.UITestCase;
27+
import org.junit.After;
28+
import org.junit.Before;
2529
import org.junit.Test;
26-
import org.junit.runner.RunWith;
27-
import org.junit.runners.JUnit4;
28-
29-
@RunWith(JUnit4.class)
30-
public class StyledStringHighlighterTest extends UITestCase {
3130

32-
public StyledStringHighlighterTest() {
33-
super(StyledStringHighlighterTest.class.getSimpleName());
34-
}
31+
public class StyledStringHighlighterTest {
3532

3633
private StyledStringHighlighter cut;
3734
private static Font font;
3835
private static BoldStylerProvider boldStyler;
3936

40-
@Override
37+
@Before
4138
public void doSetUp() {
42-
font = new Font(fWorkbench.getDisplay(), "Arial", 14, SWT.BOLD);
39+
font = new Font(Display.getDefault(), "Arial", 14, SWT.BOLD);
4340
boldStyler = new BoldStylerProvider(font);
4441
cut = new StyledStringHighlighter();
4542
}
4643

47-
@Override
48-
protected void doTearDown() {
44+
@After
45+
public void doTearDown() {
4946
if (boldStyler != null) {
5047
boldStyler.dispose();
5148
boldStyler = null;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
import org.eclipse.ui.activities.IActivityManager;
2424
import org.eclipse.ui.internal.WorkbenchPlugin;
2525
import org.junit.Test;
26-
import org.junit.runner.RunWith;
27-
import org.junit.runners.JUnit4;
2826

29-
/**
30-
* @since 3.1
31-
*/
32-
@RunWith(JUnit4.class)
3327
public class ActivityPreferenceTest {
3428
/**
3529
* Preference prefix - must match the one specified in ActivityPreferenceHelper

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

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

16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertNotSame;
18+
import static org.junit.Assert.assertSame;
19+
import static org.junit.Assert.assertTrue;
20+
1621
import org.eclipse.jface.resource.ImageDescriptor;
1722
import org.eclipse.swt.graphics.Image;
1823
import org.eclipse.ui.PlatformUI;
@@ -22,7 +27,7 @@
2227
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
2328
import org.eclipse.ui.internal.WorkbenchImages;
2429
import org.eclipse.ui.tests.harness.util.ImageTests;
25-
import org.eclipse.ui.tests.harness.util.UITestCase;
30+
import org.junit.After;
2631
import org.junit.Test;
2732
import org.junit.runner.RunWith;
2833
import org.junit.runners.JUnit4;
@@ -31,16 +36,12 @@
3136
* @since 3.1
3237
*/
3338
@RunWith(JUnit4.class)
34-
public class ImagesTest extends UITestCase {
39+
public class ImagesTest {
3540

3641
private Image defaultImage;
3742
private Image image1;
3843
private Image image2;
3944

40-
public ImagesTest() {
41-
super(ImagesTest.class.getSimpleName());
42-
}
43-
4445
@Test
4546
public void testActivityImages() {
4647
IWorkbenchActivitySupport support = PlatformUI.getWorkbench().getActivitySupport();
@@ -95,9 +96,8 @@ public void testCategoryImages() {
9596
}
9697

9798

98-
@Override
99-
protected void doTearDown() throws Exception {
100-
super.doTearDown();
99+
@After
100+
public void doTearDown() throws Exception {
101101
if (defaultImage != null) {
102102
defaultImage.dispose();
103103
}

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

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,77 @@
1414

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

17+
import static org.junit.Assert.assertFalse;
18+
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.Assert.assertTrue;
20+
import static org.junit.Assert.fail;
21+
22+
import org.eclipse.ui.PlatformUI;
1723
import org.eclipse.ui.activities.IActivity;
1824
import org.eclipse.ui.activities.IActivityManager;
1925
import org.eclipse.ui.activities.ICategory;
2026
import org.eclipse.ui.activities.NotDefinedException;
21-
import org.eclipse.ui.tests.harness.util.UITestCase;
2227
import org.junit.Test;
23-
import org.junit.runner.RunWith;
24-
import org.junit.runners.JUnit4;
2528

2629
/**
2730
* Tests that the Persistance class is catching malformed registry entries.
2831
*
2932
* @since 3.1
3033
*/
31-
@RunWith(JUnit4.class)
32-
public class PersistanceTest extends UITestCase {
33-
34-
public PersistanceTest() {
35-
super(PersistanceTest.class.getSimpleName());
36-
}
34+
public class PersistanceTest {
3735

3836
@Test
39-
public void testCategoryPermutations() {
40-
try {
41-
IActivityManager manager = fWorkbench.getActivitySupport().getActivityManager();
42-
ICategory category = manager.getCategory("org.eclipse.ui.PT.C1"); // should not be defined - missing name
43-
assertFalse(category.isDefined());
37+
public void testCategoryPermutations() throws NotDefinedException {
38+
IActivityManager manager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
39+
ICategory category = manager.getCategory("org.eclipse.ui.PT.C1"); // should not be defined - missing name
40+
assertFalse(category.isDefined());
4441

45-
category = manager.getCategory("org.eclipse.ui.PT.C2"); // should be defined - missing desc
46-
assertTrue(category.isDefined());
47-
assertNotNull(category.getDescription());
42+
category = manager.getCategory("org.eclipse.ui.PT.C2"); // should be defined - missing desc
43+
assertTrue(category.isDefined());
44+
assertNotNull(category.getDescription());
4845

49-
for (String string : manager.getDefinedCategoryIds()) {
50-
if (manager.getCategory(string).getName().equals("org.eclipse.ui.PT.C3")) {
51-
fail("Found category that should not be.");
52-
}
46+
for (String string : manager.getDefinedCategoryIds()) {
47+
if (manager.getCategory(string).getName().equals("org.eclipse.ui.PT.C3")) {
48+
fail("Found category that should not be.");
5349
}
5450
}
55-
catch (NotDefinedException e) {
56-
fail(e.getMessage());
57-
}
5851
}
5952

6053
@Test
6154
public void testActivityRequirementBindings() {
62-
IActivityManager manager = fWorkbench.getActivitySupport().getActivityManager();
55+
IActivityManager manager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
6356
IActivity activity = manager.getActivity("org.eclipse.ui.PT.A2");
6457
assertTrue(activity.getActivityRequirementBindings().isEmpty());
6558
}
6659

6760
@Test
6861
public void testActivityPatternBindings() {
69-
IActivityManager manager = fWorkbench.getActivitySupport().getActivityManager();
62+
IActivityManager manager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
7063
IActivity activity = manager.getActivity("org.eclipse.ui.PT.A2");
7164
assertTrue(activity.getActivityPatternBindings().isEmpty());
7265
}
7366

7467
@Test
7568
public void testCategoryActivityBindings() {
76-
IActivityManager manager = fWorkbench.getActivitySupport().getActivityManager();
69+
IActivityManager manager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
7770
ICategory category = manager.getCategory("org.eclipse.ui.PT.C2");
7871
assertTrue(category.getCategoryActivityBindings().isEmpty());
7972
}
8073

8174
@Test
82-
public void testActivityPermutations() {
83-
try {
84-
IActivityManager manager = fWorkbench.getActivitySupport().getActivityManager();
85-
IActivity activity = manager.getActivity("org.eclipse.ui.PT.A1"); // should not be defined - missing name
86-
assertFalse(activity.isDefined());
75+
public void testActivityPermutations() throws NotDefinedException {
76+
IActivityManager manager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
77+
IActivity activity = manager.getActivity("org.eclipse.ui.PT.A1"); // should not be defined - missing name
78+
assertFalse(activity.isDefined());
8779

88-
activity = manager.getActivity("org.eclipse.ui.PT.A2"); // should be defined - missing desc
89-
assertTrue(activity.isDefined());
90-
assertNotNull(activity.getDescription());
80+
activity = manager.getActivity("org.eclipse.ui.PT.A2"); // should be defined - missing desc
81+
assertTrue(activity.isDefined());
82+
assertNotNull(activity.getDescription());
9183

92-
for (String string : manager.getDefinedActivityIds()) {
93-
if (manager.getActivity(string).getName().equals("org.eclipse.ui.PT.A3")) {
94-
fail("Found activity that should not be.");
95-
}
84+
for (String string : manager.getDefinedActivityIds()) {
85+
if (manager.getActivity(string).getName().equals("org.eclipse.ui.PT.A3")) {
86+
fail("Found activity that should not be.");
9687
}
9788
}
98-
catch (NotDefinedException e) {
99-
fail(e.getMessage());
100-
}
10189
}
10290
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java

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

16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertTrue;
18+
import static org.junit.Assert.fail;
19+
1620
import java.io.ByteArrayInputStream;
1721
import java.io.InputStream;
1822

@@ -31,33 +35,22 @@
3135
import org.eclipse.ui.PlatformUI;
3236
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
3337
import org.eclipse.ui.tests.harness.util.DisplayHelper;
34-
import org.eclipse.ui.tests.harness.util.UITestCase;
38+
import org.junit.After;
39+
import org.junit.Before;
3540
import org.junit.Test;
36-
import org.junit.runner.RunWith;
37-
import org.junit.runners.JUnit4;
3841

3942
/**
4043
* Tests that resources are highlighted to match user search input. See Bug
4144
* 519525, 520250, and 520251 for references.
4245
*
4346
* @since 3.14
4447
*/
45-
@RunWith(JUnit4.class)
46-
public class ResourceItemLabelTest extends UITestCase {
47-
48-
/**
49-
* Constructs a new instance of <code>ResourceItemlLabelTest</code>.
50-
*/
51-
52-
public ResourceItemLabelTest() {
53-
super(ResourceItemLabelTest.class.getSimpleName());
54-
}
48+
public class ResourceItemLabelTest {
5549

5650
private IProject project;
5751

58-
@Override
59-
protected void doSetUp() throws Exception {
60-
super.doSetUp();
52+
@Before
53+
public void doSetUp() throws Exception {
6154
project = ResourcesPlugin.getWorkspace().getRoot()
6255
.getProject(getClass().getName() + "_" + System.currentTimeMillis());
6356
project.create(new NullProgressMonitor());
@@ -357,14 +350,13 @@ private String printStyleRanges(StyleRange[] styleRanges) {
357350
return builder.toString();
358351
}
359352

360-
@Override
361-
protected void doTearDown() throws Exception {
353+
@After
354+
public void doTearDown() throws Exception {
362355
if (dialog != null) {
363356
dialog.close();
364357
}
365358
if (project != null) {
366359
project.delete(true, null);
367360
}
368-
super.doTearDown();
369361
}
370362
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceSelectionFilteringDialogTest.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@
2424
import org.eclipse.ui.PlatformUI;
2525
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
2626
import org.eclipse.ui.tests.harness.util.DisplayHelper;
27-
import org.eclipse.ui.tests.harness.util.UITestCase;
27+
import org.junit.After;
2828
import org.junit.Assert;
29+
import org.junit.Before;
2930
import org.junit.Test;
30-
import org.junit.runner.RunWith;
31-
import org.junit.runners.JUnit4;
3231

33-
@RunWith(JUnit4.class)
34-
public class ResourceSelectionFilteringDialogTest extends UITestCase {
35-
36-
public ResourceSelectionFilteringDialogTest() {
37-
super(ResourceSelectionFilteringDialogTest.class.getSimpleName());
38-
}
32+
public class ResourceSelectionFilteringDialogTest {
3933

4034
private static SeeThroughFilteredResourcesSelectionDialog createDialog() {
4135
SeeThroughFilteredResourcesSelectionDialog dialog = new SeeThroughFilteredResourcesSelectionDialog(
@@ -47,9 +41,8 @@ private static SeeThroughFilteredResourcesSelectionDialog createDialog() {
4741

4842
private IProject project;
4943

50-
@Override
44+
@Before
5145
public void doSetUp() throws Exception {
52-
super.doSetUp();
5346
project = ResourcesPlugin.getWorkspace().getRoot()
5447
.getProject(getClass().getSimpleName() + System.currentTimeMillis());
5548
project.create(null);
@@ -76,9 +69,8 @@ public void testMatch() throws CoreException {
7669
}
7770
}
7871

79-
@Override
72+
@After
8073
public void doTearDown() throws Exception {
81-
super.doTearDown();
8274
project.delete(true, null);
8375
}
8476

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/encoding/EncodingTestCase.java

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

16+
import static org.junit.Assert.assertTrue;
17+
import static org.junit.Assert.fail;
18+
1619
import java.nio.charset.Charset;
1720
import java.nio.charset.IllegalCharsetNameException;
1821
import java.util.List;
1922

20-
import org.eclipse.core.runtime.Assert;
2123
import org.eclipse.ui.WorkbenchEncoding;
22-
import org.eclipse.ui.tests.harness.util.UITestCase;
2324
import org.junit.Test;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.JUnit4;
2625

2726
/**
2827
* The EncodingTestCase is the suite that tests the 3.1
2928
* encoding support.
3029
*/
31-
@RunWith(JUnit4.class)
32-
public class EncodingTestCase extends UITestCase {
33-
34-
/**
35-
* Create a new instance of the receiver.
36-
*/
37-
public EncodingTestCase() {
38-
super(EncodingTestCase.class.getSimpleName());
39-
}
30+
public class EncodingTestCase {
4031

4132
/**
4233
* Test that the workbench encodings are all valid. The
@@ -48,10 +39,10 @@ public void testWorkbenchEncodings() {
4839

4940
for (String encoding : encodings) {
5041
try {
51-
Assert.isTrue(Charset.isSupported(encoding), "Unsupported charset " + encoding);
42+
assertTrue("Unsupported charset " + encoding, Charset.isSupported(encoding));
5243

5344
} catch (IllegalCharsetNameException e) {
54-
Assert.isTrue(false, "Unsupported charset " + encoding);
45+
fail("Unsupported charset " + encoding);
5546
}
5647
}
5748
}

0 commit comments

Comments
 (0)