Skip to content

Commit 730daf6

Browse files
vogellaakurtakov
authored andcommitted
Migrate org.eclipse.jface.tests to JUnit 5
1 parent 5c89bb8 commit 730daf6

20 files changed

+190
-269
lines changed

tests/org.eclipse.jface.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Bundle-SymbolicName: org.eclipse.jface.tests
55
Bundle-Version: 1.5.0.qualifier
66
Automatic-Module-Name: org.eclipse.jface.tests
77
Bundle-RequiredExecutionEnvironment: JavaSE-21
8-
Require-Bundle: org.junit;bundle-version="4.12.0",
9-
org.eclipse.jface,
8+
Require-Bundle: org.eclipse.jface,
109
org.eclipse.equinox.registry,
1110
org.eclipse.core.runtime,
1211
org.eclipse.ui,
1312
org.eclipse.ui.tests.harness
1413
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
1514
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
1615
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
16+
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
1717
org.junit.platform.commons.function;version="[1.14.0,2.0.0)",
1818
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
1919
org.opentest4j;version="1.3.0",

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/AllActionTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.tests.action;
1515

16-
import org.junit.runner.JUnitCore;
16+
1717

1818
import org.junit.platform.suite.api.SelectClasses;
1919
import org.junit.platform.suite.api.Suite;
@@ -23,8 +23,6 @@
2323
MenuManagerTest.class })
2424
public class AllActionTests {
2525

26-
public static void main(String[] args) {
27-
JUnitCore.main(AllActionTests.class.getName());
28-
}
26+
2927

3028
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/JFaceActionRule.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/dialogs/AllDialogTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.tests.dialogs;
1515

16-
import org.junit.runner.JUnitCore;
16+
1717

1818
import org.junit.platform.suite.api.SelectClasses;
1919
import org.junit.platform.suite.api.Suite;
@@ -24,7 +24,5 @@
2424
ProgressMonitorDialogTest.class, PlainMessageDialogTest.class })
2525
public class AllDialogTests {
2626

27-
public static void main(String[] args) {
28-
JUnitCore.main(AllDialogTests.class.getName());
29-
}
27+
3028
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
******************************************************************************/
1515
package org.eclipse.jface.tests.fieldassist;
1616

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import org.eclipse.jface.bindings.keys.KeyStroke;
2222
import org.eclipse.swt.SWT;
@@ -25,15 +25,12 @@
2525
import org.eclipse.swt.widgets.Shell;
2626
import org.eclipse.swt.widgets.Text;
2727
import org.eclipse.ui.tests.harness.util.TestRunLogUtil;
28-
import org.junit.After;
29-
import org.junit.Before;
30-
import org.junit.Rule;
31-
import org.junit.rules.TestWatcher;
28+
import org.junit.jupiter.api.AfterEach;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.TestInfo;
3231

3332
public abstract class AbstractFieldAssistTestCase {
34-
@Rule
35-
public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN;
36-
33+
3734
/**
3835
* The window that is being tested.
3936
*/
@@ -49,8 +46,9 @@ public abstract class AbstractFieldAssistTestCase {
4946
*/
5047
private int originalShellCount;
5148

52-
@Before
53-
public final void setUp() throws Exception {
49+
@BeforeEach
50+
public final void setUp(TestInfo testInfo) throws Exception {
51+
System.out.println(TestRunLogUtil.formatTestStartMessage(testInfo.getTestMethod().get().getName()));
5452
Display display = getDisplay();
5553
anotherShell = new Shell(display);
5654
new Text(anotherShell, SWT.SINGLE);
@@ -61,13 +59,14 @@ public final void setUp() throws Exception {
6159
assertNotNull(window);
6260
}
6361

64-
@After
65-
public final void tearDown() throws Exception {
62+
@AfterEach
63+
public final void tearDown(TestInfo testInfo) throws Exception {
6664
if (window != null) {
6765
spinEventLoop();
6866
}
6967
closeFieldAssistWindow();
7068
anotherShell.close();
69+
System.out.println(TestRunLogUtil.formatTestFinishedMessage(testInfo.getTestMethod().get().getName()));
7170
}
7271

7372
protected Display getDisplay() {
@@ -171,7 +170,7 @@ protected void sendKeyDownToControl(char character) {
171170
Event event = new Event();
172171
event.type = SWT.KeyDown;
173172
event.character = character;
174-
assertTrue("unable to post event to display queue for test case", window.getDisplay().post(event));
173+
assertTrue(window.getDisplay().post(event), "unable to post event to display queue for test case");
175174
spinEventLoop();
176175
}
177176

@@ -186,7 +185,7 @@ protected void sendKeyDownToControl(KeyStroke keystroke) {
186185
Event event = new Event();
187186
event.type = SWT.KeyDown;
188187
event.keyCode = keystroke.getNaturalKey();
189-
assertTrue("unable to post event to display queue for test case", window.getDisplay().post(event));
188+
assertTrue(window.getDisplay().post(event), "unable to post event to display queue for test case");
190189
spinEventLoop();
191190
}
192191

@@ -195,8 +194,8 @@ protected void sendKeyDownToControl(KeyStroke keystroke) {
195194
*/
196195
protected void assertOneShellUp() {
197196
spinEventLoop();
198-
assertEquals("There should only be one shell up, the dialog", originalShellCount + 1,
199-
window.getDisplay().getShells().length);
197+
assertEquals(originalShellCount + 1,
198+
window.getDisplay().getShells().length, "There should only be one shell up, the dialog");
200199
}
201200

202201
/**
@@ -205,8 +204,8 @@ protected void assertOneShellUp() {
205204
*/
206205
protected void assertTwoShellsUp() {
207206
spinEventLoop();
208-
assertEquals("There should two shells up, the dialog and the proposals dialog", originalShellCount + 2,
209-
window.getDisplay().getShells().length);
207+
assertEquals(originalShellCount + 2,
208+
window.getDisplay().getShells().length, "There should two shells up, the dialog and the proposals dialog");
210209
}
211210

212211
protected void setControlContent(String text) {
@@ -219,4 +218,4 @@ protected String getControlContent() {
219218

220219
}
221220

222-
}
221+
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.tests.fieldassist;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertNotNull;
18-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

2020
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
2121
import org.eclipse.jface.fieldassist.IContentProposalProvider;
@@ -28,15 +28,12 @@
2828
import org.eclipse.swt.widgets.Shell;
2929
import org.eclipse.swt.widgets.Text;
3030
import org.eclipse.ui.tests.harness.util.TestRunLogUtil;
31-
import org.junit.After;
32-
import org.junit.Before;
33-
import org.junit.Rule;
34-
import org.junit.Test;
35-
import org.junit.rules.TestWatcher;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.TestInfo;
3635

3736
public class ContentProposalAdapterTest {
38-
@Rule
39-
public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN;
4037

4138
/**
4239
* A shell that hosts the decorated text control
@@ -121,8 +118,9 @@ public void testBug520372AutoActivationDelayESC() throws Exception {
121118

122119
// most of the following code is copied from AbstractFieldAssistTestCase
123120

124-
@Before
125-
public final void setUp() throws Exception {
121+
@BeforeEach
122+
public final void setUp(TestInfo testInfo) throws Exception {
123+
System.out.println(TestRunLogUtil.formatTestStartMessage(testInfo.getTestMethod().get().getName()));
126124
Display display = getDisplay();
127125
originalShellCount = display.getShells().length;
128126
controlShell = new Shell(display);
@@ -133,8 +131,8 @@ public final void setUp() throws Exception {
133131
assertNotNull(contentProposalAdapter);
134132
}
135133

136-
@After
137-
public final void tearDown() throws Exception {
134+
@AfterEach
135+
public final void tearDown(TestInfo testInfo) throws Exception {
138136
if (controlShell != null) {
139137
spinEventLoop();
140138
controlShell.close();
@@ -145,6 +143,7 @@ public final void tearDown() throws Exception {
145143
}
146144
this.display = null;
147145
}
146+
System.out.println(TestRunLogUtil.formatTestFinishedMessage(testInfo.getTestMethod().get().getName()));
148147
}
149148

150149
private Display getDisplay() {
@@ -179,7 +178,7 @@ private void sendKeyDownToControl(char character) {
179178
Event event = new Event();
180179
event.type = SWT.KeyDown;
181180
event.character = character;
182-
assertTrue("unable to post event to display queue for test case", text.getDisplay().post(event));
181+
assertTrue(text.getDisplay().post(event), "unable to post event to display queue for test case");
183182
spinEventLoop();
184183
}
185184

@@ -233,7 +232,7 @@ private void ensurePopupIsUp() {
233232
*/
234233
private void assertOneShellUp() {
235234
spinEventLoop();
236-
assertEquals("There should only be one shell up, the dialog", originalShellCount + 1,
237-
text.getDisplay().getShells().length);
235+
assertEquals(originalShellCount + 1,
236+
text.getDisplay().getShells().length, "There should only be one shell up, the dialog");
238237
}
239-
}
238+
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ControlDecorationTests.java

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

16-
import static org.junit.Assert.assertFalse;
17-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1818

1919
import org.eclipse.jface.fieldassist.ControlDecoration;
2020
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.widgets.Composite;
2323
import org.eclipse.swt.widgets.Text;
24-
import org.junit.Ignore;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.Disabled;
25+
import org.junit.jupiter.api.Test;
2626

2727
public class ControlDecorationTests extends AbstractFieldAssistTestCase {
2828

@@ -37,15 +37,15 @@ public void testDecorationIsVisible() {
3737
.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
3838
decoration.setDescriptionText("foo");
3939
window.open();
40-
assertTrue("1.0", decoration.isVisible());
40+
assertTrue(decoration.isVisible(), "1.0");
4141
decoration.hide();
42-
assertFalse("1.1", decoration.isVisible());
42+
assertFalse(decoration.isVisible(), "1.1");
4343
decoration.show();
44-
assertTrue("1.2", decoration.isVisible());
44+
assertTrue(decoration.isVisible(), "1.2");
4545
window.getFieldAssistControl().setVisible(false);
46-
assertFalse("1.3", decoration.isVisible());
46+
assertFalse(decoration.isVisible(), "1.3");
4747
window.getFieldAssistControl().setVisible(true);
48-
assertTrue("1.4", decoration.isVisible());
48+
assertTrue(decoration.isVisible(), "1.4");
4949

5050
// focus related tests. Comment out for now.
5151
// see bug 275393
@@ -71,7 +71,7 @@ public void testHoverVisibility() {
7171
decoration.setImage(FieldDecorationRegistry.getDefault()
7272
.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
7373
decoration.setDescriptionText("foo");
74-
assertTrue("1.0", decoration.isVisible());
74+
assertTrue(decoration.isVisible(), "1.0");
7575
assertOneShellUp();
7676
decoration.hide();
7777
decoration.showHoverText("Show me");
@@ -87,7 +87,7 @@ public void testHoverVisibility() {
8787

8888
// focus related tests
8989
@Test
90-
@Ignore("Disabled see Bug 418420 and bug 275393")
90+
@Disabled("Disabled see Bug 418420 and bug 275393")
9191
public void testBug418420() {
9292
AbstractFieldAssistWindow window = getFieldAssistWindow();
9393
window.open();

0 commit comments

Comments
 (0)