Skip to content

Commit 676351a

Browse files
committed
Migrate org.eclipse.jface.tests to JUnit 5
- Migrated all tests in org.eclipse.jface.tests to JUnit 5. - Updated MANIFEST.MF to use org.junit.jupiter.api and removed JUnit 4. - Replaced JUnit 4 Rules with JUnit 5 Extensions or @tempdir. - Fixed assertion and assumption parameter order for JUnit 5. - Removed unused JFaceActionRule. - Replaced JUnit 3 AssertionFailedError with IllegalStateException in TestLazyModelContentProvider.
1 parent de0e232 commit 676351a

17 files changed

+36
-79
lines changed

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

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

16-
17-
1816
import org.junit.platform.suite.api.SelectClasses;
1917
import org.junit.platform.suite.api.Suite;
2018

@@ -23,6 +21,4 @@
2321
MenuManagerTest.class })
2422
public class AllActionTests {
2523

26-
27-
2824
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ToolBarManagerTest {
5252
@RegisterExtension
5353
public JFaceActionExtension rule = new JFaceActionExtension();
5454

55+
@Test
5556
public void testSetStyleWhenToolBarDoesNotExist() {
5657
Composite parent = createComposite();
5758
ToolBarManager manager = new ToolBarManager(DEFAULT_STYLE | SWT.HORIZONTAL);

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

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

16-
17-
1816
import org.junit.platform.suite.api.SelectClasses;
1917
import org.junit.platform.suite.api.Suite;
2018

@@ -24,5 +22,4 @@
2422
ProgressMonitorDialogTest.class, PlainMessageDialogTest.class })
2523
public class AllDialogTests {
2624

27-
2825
}

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
import org.eclipse.swt.widgets.Event;
2525
import org.eclipse.swt.widgets.Shell;
2626
import org.eclipse.swt.widgets.Text;
27-
import org.eclipse.ui.tests.harness.util.TestRunLogUtil;
2827
import org.junit.jupiter.api.AfterEach;
2928
import org.junit.jupiter.api.BeforeEach;
30-
import org.junit.jupiter.api.TestInfo;
3129

3230
public abstract class AbstractFieldAssistTestCase {
33-
31+
32+
3433
/**
3534
* The window that is being tested.
3635
*/
@@ -47,8 +46,7 @@ public abstract class AbstractFieldAssistTestCase {
4746
private int originalShellCount;
4847

4948
@BeforeEach
50-
public final void setUp(TestInfo testInfo) throws Exception {
51-
System.out.println(TestRunLogUtil.formatTestStartMessage(testInfo.getTestMethod().get().getName()));
49+
public final void setUp() throws Exception {
5250
Display display = getDisplay();
5351
anotherShell = new Shell(display);
5452
new Text(anotherShell, SWT.SINGLE);
@@ -60,13 +58,12 @@ public final void setUp(TestInfo testInfo) throws Exception {
6058
}
6159

6260
@AfterEach
63-
public final void tearDown(TestInfo testInfo) throws Exception {
61+
public final void tearDown() throws Exception {
6462
if (window != null) {
6563
spinEventLoop();
6664
}
6765
closeFieldAssistWindow();
6866
anotherShell.close();
69-
System.out.println(TestRunLogUtil.formatTestFinishedMessage(testInfo.getTestMethod().get().getName()));
7067
}
7168

7269
protected Display getDisplay() {
@@ -194,8 +191,7 @@ protected void sendKeyDownToControl(KeyStroke keystroke) {
194191
*/
195192
protected void assertOneShellUp() {
196193
spinEventLoop();
197-
assertEquals(originalShellCount + 1,
198-
window.getDisplay().getShells().length, "There should only be one shell up, the dialog");
194+
assertEquals(originalShellCount + 1, window.getDisplay().getShells().length, "There should only be one shell up, the dialog");
199195
}
200196

201197
/**
@@ -204,8 +200,7 @@ protected void assertOneShellUp() {
204200
*/
205201
protected void assertTwoShellsUp() {
206202
spinEventLoop();
207-
assertEquals(originalShellCount + 2,
208-
window.getDisplay().getShells().length, "There should two shells up, the dialog and the proposals dialog");
203+
assertEquals(originalShellCount + 2, window.getDisplay().getShells().length, "There should two shells up, the dialog and the proposals dialog");
209204
}
210205

211206
protected void setControlContent(String text) {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
import org.eclipse.swt.widgets.Event;
2828
import org.eclipse.swt.widgets.Shell;
2929
import org.eclipse.swt.widgets.Text;
30-
import org.eclipse.ui.tests.harness.util.TestRunLogUtil;
3130
import org.junit.jupiter.api.AfterEach;
3231
import org.junit.jupiter.api.BeforeEach;
3332
import org.junit.jupiter.api.Test;
34-
import org.junit.jupiter.api.TestInfo;
3533

3634
public class ContentProposalAdapterTest {
3735

@@ -119,8 +117,7 @@ public void testBug520372AutoActivationDelayESC() throws Exception {
119117
// most of the following code is copied from AbstractFieldAssistTestCase
120118

121119
@BeforeEach
122-
public final void setUp(TestInfo testInfo) throws Exception {
123-
System.out.println(TestRunLogUtil.formatTestStartMessage(testInfo.getTestMethod().get().getName()));
120+
public final void setUp() throws Exception {
124121
Display display = getDisplay();
125122
originalShellCount = display.getShells().length;
126123
controlShell = new Shell(display);
@@ -132,7 +129,7 @@ public final void setUp(TestInfo testInfo) throws Exception {
132129
}
133130

134131
@AfterEach
135-
public final void tearDown(TestInfo testInfo) throws Exception {
132+
public final void tearDown() throws Exception {
136133
if (controlShell != null) {
137134
spinEventLoop();
138135
controlShell.close();
@@ -143,7 +140,6 @@ public final void tearDown(TestInfo testInfo) throws Exception {
143140
}
144141
this.display = null;
145142
}
146-
System.out.println(TestRunLogUtil.formatTestFinishedMessage(testInfo.getTestMethod().get().getName()));
147143
}
148144

149145
private Display getDisplay() {
@@ -232,7 +228,6 @@ private void ensurePopupIsUp() {
232228
*/
233229
private void assertOneShellUp() {
234230
spinEventLoop();
235-
assertEquals(originalShellCount + 1,
236-
text.getDisplay().getShells().length, "There should only be one shell up, the dialog");
231+
assertEquals(originalShellCount + 1, text.getDisplay().getShells().length, "There should only be one shell up, the dialog");
237232
}
238233
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public void testDecorationIsVisible() {
5454
spinEventLoop();
5555

5656
/*
57-
assertFalse("1.5", decoration.isVisible());
57+
assertFalse(decoration.isVisible(), "1.5");
5858
window.getFieldAssistControl().setFocus();
5959
spinEventLoop();
60-
assertTrue("1.6", decoration.isVisible());
60+
assertTrue(decoration.isVisible(), "1.6");
6161
decoration.setShowOnlyOnFocus(false);
6262
*/
6363

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void testContentProposalWithDescription() {
6565
assertEquals(content.length(), proposal.getCursorPosition(), "2.3");
6666
}
6767

68+
@Test
6869
public void testInitializationWithInvalidCursor() {
6970
try {
7071
proposal = new ContentProposal(content, label, description, 100);

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/images/AllImagesTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*******************************************************************************/
1515
package org.eclipse.jface.tests.images;
1616

17-
18-
1917
import org.junit.platform.suite.api.SelectClasses;
2018
import org.junit.platform.suite.api.Suite;
2119

@@ -24,5 +22,4 @@
2422
UrlImageDescriptorTest.class, DecorationOverlayIconTest.class, DeferredImageDescriptorTest.class })
2523
public class AllImagesTests {
2624

27-
2825
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/images/UrlImageDescriptorTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
import static org.junit.jupiter.api.Assertions.assertNotSame;
2222
import static org.junit.jupiter.api.Assertions.assertNull;
2323

24-
import java.io.File;
2524
import java.io.IOException;
2625
import java.net.URL;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
2728

2829
import org.eclipse.core.runtime.Adapters;
2930
import org.eclipse.core.runtime.IPath;
@@ -38,7 +39,7 @@
3839
public class UrlImageDescriptorTest {
3940

4041
@TempDir
41-
public File tempFolder;
42+
public Path tempFolder;
4243

4344
/**
4445
* Test that individually created images of a given descriptor are not equal
@@ -92,13 +93,13 @@ public void testImageFileNameProviderGetxPath() {
9293
assertNotSame(fileNameProvider, fileNameProvider2nd, "URLImageDescriptor does return identical ImageFileNameProvider");
9394
String imagePath100 = fileNameProvider.getImagePath(100);
9495
assertNotNull(imagePath100, "URLImageDescriptor ImageFileNameProvider does not return the 100% path");
95-
assertEquals(IPath.fromOSString(imagePath100).lastSegment(), "rectangular-57x16.png");
96+
assertEquals("rectangular-57x16.png", IPath.fromOSString(imagePath100).lastSegment());
9697
String imagePath200 = fileNameProvider.getImagePath(200);
9798
assertNotNull(imagePath200, "URLImageDescriptor ImageFileNameProvider does not return the 200% path");
98-
assertEquals(IPath.fromOSString(imagePath200).lastSegment(), "rectangular-114x32.png");
99+
assertEquals("rectangular-114x32.png", IPath.fromOSString(imagePath200).lastSegment());
99100
String imagePath150 = fileNameProvider.getImagePath(150);
100101
assertNotNull(imagePath150, "URLImageDescriptor ImageFileNameProvider does not return the 150% path");
101-
assertEquals(IPath.fromOSString(imagePath150).lastSegment(), "rectangular-86x24.png");
102+
assertEquals("rectangular-86x24.png", IPath.fromOSString(imagePath150).lastSegment());
102103
String imagePath250 = fileNameProvider.getImagePath(250);
103104
assertNull(imagePath250, "URLImageDescriptor's ImageFileNameProvider does return a 250% path");
104105
}
@@ -112,10 +113,10 @@ public void testImageFileNameProviderGetxName() {
112113
assertNotNull(fileNameProvider, "URLImageDescriptor does not adapt to ImageFileNameProvider");
113114
String imagePath100 = fileNameProvider.getImagePath(100);
114115
assertNotNull(imagePath100, "URLImageDescriptor ImageFileNameProvider does not return the 100% path");
115-
assertEquals(IPath.fromOSString(imagePath100).lastSegment(), "zoomIn.png");
116+
assertEquals("zoomIn.png", IPath.fromOSString(imagePath100).lastSegment());
116117
String imagePath200 = fileNameProvider.getImagePath(200);
117118
assertNotNull(imagePath200, "URLImageDescriptor ImageFileNameProvider does not return the @2x path");
118-
assertEquals(IPath.fromOSString(imagePath200).lastSegment(), "[email protected]");
119+
assertEquals("[email protected]", IPath.fromOSString(imagePath200).lastSegment());
119120
String imagePath150 = fileNameProvider.getImagePath(150);
120121
assertNull(imagePath150, "URLImageDescriptor's ImageFileNameProvider does return a @1.5x path");
121122
}
@@ -134,20 +135,20 @@ private void testImageFileNameProviderGetxName_forFileURL(boolean osgiAvailable)
134135
boolean oldOsgiAvailable = InternalPolicy.OSGI_AVAILABLE;
135136
InternalPolicy.OSGI_AVAILABLE = osgiAvailable;
136137
try {
137-
File file = new File(tempFolder, "image.png");
138-
file.createNewFile();
139-
URL imageFileURL = file.toURI().toURL();
140-
new File(tempFolder, "[email protected]").createNewFile();
138+
Path imagePath = tempFolder.resolve("image.png");
139+
Files.createFile(imagePath);
140+
URL imageFileURL = imagePath.toUri().toURL();
141+
Files.createFile(tempFolder.resolve("[email protected]"));
141142
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageFileURL);
142143

143144
ImageFileNameProvider fileNameProvider = Adapters.adapt(descriptor, ImageFileNameProvider.class);
144145
assertNotNull(fileNameProvider, "URLImageDescriptor does not adapt to ImageFileNameProvider");
145146
String imagePath100 = fileNameProvider.getImagePath(100);
146147
assertNotNull(imagePath100, "URLImageDescriptor ImageFileNameProvider does not return the 100% path");
147-
assertEquals(IPath.fromOSString(imagePath100).lastSegment(), "image.png");
148+
assertEquals("image.png", IPath.fromOSString(imagePath100).lastSegment());
148149
String imagePath200 = fileNameProvider.getImagePath(200);
149150
assertNotNull(imagePath200, "URLImageDescriptor ImageFileNameProvider does not return the @2x path");
150-
assertEquals(IPath.fromOSString(imagePath200).lastSegment(), "[email protected]");
151+
assertEquals("[email protected]", IPath.fromOSString(imagePath200).lastSegment());
151152
String imagePath150 = fileNameProvider.getImagePath(150);
152153
assertNull(imagePath150, "URLImageDescriptor's ImageFileNameProvider does return a @1.5x path");
153154
} finally {
@@ -157,15 +158,15 @@ private void testImageFileNameProviderGetxName_forFileURL(boolean osgiAvailable)
157158

158159
@Test
159160
public void testImageFileNameProviderGetxName_forFileURL_WhiteSpace() throws IOException {
160-
File imageFolder = new File(tempFolder, "folder with spaces");
161-
imageFolder.mkdir();
162-
File imageFile = new File(imageFolder, "image with spaces.png");
163-
imageFile.createNewFile();
161+
Path imageFolder = tempFolder.resolve("folder with spaces");
162+
Files.createDirectories(imageFolder);
163+
Path imagePath = imageFolder.resolve("image with spaces.png");
164+
Files.createFile(imagePath);
164165

165166
// This is an invalid URL because the whitespace characters are not properly
166167
// encoded
167168
@SuppressWarnings("deprecation")
168-
URL imageFileURL = new URL("file", null, imageFile.getPath());
169+
URL imageFileURL = new URL("file", null, imagePath.toString());
169170
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageFileURL);
170171

171172
ImageFileNameProvider fileNameProvider = Adapters.adapt(descriptor, ImageFileNameProvider.class);

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/layout/AllLayoutTests.java

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

16-
17-
1816
import org.junit.platform.suite.api.SelectClasses;
1917
import org.junit.platform.suite.api.Suite;
2018

@@ -23,6 +21,4 @@
2321
GridLayoutFactoryTest.class, TreeColumnLayoutTest.class })
2422
public class AllLayoutTests {
2523

26-
27-
2824
}

0 commit comments

Comments
 (0)