Skip to content

Commit 741c334

Browse files
vogellaakurtakov
authored andcommitted
Migrate org.eclipse.tests.urischeme to JUnit 5
1 parent beaeb6f commit 741c334

11 files changed

+190
-211
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Bundle-Version: 1.2.800.qualifier
77
Bundle-Localization: plugin
88
Fragment-Host: org.eclipse.urischeme;bundle-version="1.1.100"
99
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
10-
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
10+
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
11+
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
12+
org.opentest4j;version="[1.2.0,2.0.0)"
1113
Automatic-Module-Name: org.eclipse.urischeme.tests
1214
Bundle-RequiredExecutionEnvironment: JavaSE-17
13-
Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)"

tests/org.eclipse.tests.urischeme/src/org/eclipse/urischeme/TestUnitAutoRegisterSchemeHandlersJob.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.urischeme;
1515

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

2121
import java.util.ArrayList;
2222
import java.util.Arrays;
@@ -28,7 +28,7 @@
2828
import org.eclipse.core.runtime.NullProgressMonitor;
2929
import org.eclipse.urischeme.internal.registration.Scheme;
3030
import org.eclipse.urischeme.internal.registration.SchemeInformation;
31-
import org.junit.Test;
31+
import org.junit.jupiter.api.Test;
3232
import org.osgi.service.prefs.BackingStoreException;
3333

3434
@SuppressWarnings("restriction")
@@ -50,10 +50,10 @@ public void noSchemeDoesNothing() throws Exception {
5050

5151
job.run(new NullProgressMonitor());
5252

53-
assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
54-
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
55-
assertNull("No schemes should be registered", osRegistration.addedSchemes);
56-
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
53+
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
54+
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
55+
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
56+
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
5757

5858
}
5959

@@ -64,10 +64,10 @@ public void noNewSchemeDoesNothing() throws Exception {
6464

6565
job.run(new NullProgressMonitor());
6666

67-
assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
68-
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
69-
assertNull("No schemes should be registered", osRegistration.addedSchemes);
70-
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
67+
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
68+
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
69+
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
70+
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
7171

7272
}
7373

@@ -85,12 +85,12 @@ public void newSchemeRegistersNewScheme() throws Exception {
8585

8686
job.run(new NullProgressMonitor());
8787

88-
assertEquals("Wrong values written to preferences", helloScheme.getName() + "," + hello1Scheme.getName(),
89-
preferenceNode.writtenValue);
90-
assertTrue("Preferences not flushed", preferenceNode.flushed);
91-
assertEquals("Wrong schemes have been registered", hello1SchemeInfo,
92-
osRegistration.addedSchemes.iterator().next());
93-
assertTrue("No schemes should be un-registered", osRegistration.removedSchemes.isEmpty());
88+
assertEquals(helloScheme.getName() + "," + hello1Scheme.getName(),
89+
preferenceNode.writtenValue, "Wrong values written to preferences");
90+
assertTrue(preferenceNode.flushed, "Preferences not flushed");
91+
assertEquals(hello1SchemeInfo,
92+
osRegistration.addedSchemes.iterator().next(), "Wrong schemes have been registered");
93+
assertTrue(osRegistration.removedSchemes.isEmpty(), "No schemes should be un-registered");
9494
}
9595

9696
@Test
@@ -107,10 +107,10 @@ public void newAlreadyRegisteredSchemeDoesNoting() throws Exception {
107107

108108
job.run(new NullProgressMonitor());
109109

110-
assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
111-
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
112-
assertNull("No schemes should be registered", osRegistration.addedSchemes);
113-
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
110+
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
111+
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
112+
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
113+
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
114114
}
115115

116116
@Test
@@ -127,17 +127,17 @@ public void unregisteredSchemeThatWasAutoregisterdOnceDoesNotAutoregisterAgain()
127127

128128
job.run(new NullProgressMonitor());
129129

130-
assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
131-
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
132-
assertNull("No schemes should be registered", osRegistration.addedSchemes);
133-
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
130+
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
131+
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
132+
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
133+
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
134134
}
135135

136136
@Test
137137
public void registrationOnUnsupportedRegistrationDoesNothing() throws Exception {
138138
AutoRegisterSchemeHandlersJob job = createJob(new ArrayList<>(), "dontCare", new ArrayList<>(),
139139
DOESNT_SUPPORT_REGISTRATION);
140-
assertFalse("Job should not run on OSes that don't support registration", job.shouldSchedule());
140+
assertFalse(job.shouldSchedule(), "Job should not run on OSes that don't support registration");
141141
}
142142

143143
private AutoRegisterSchemeHandlersJob createJob(Collection<IScheme> installedSchemes,

tests/org.eclipse.tests.urischeme/src/org/eclipse/urischeme/internal/UriSchemeExtensionReaderUnitTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
*******************************************************************************/
1111
package org.eclipse.urischeme.internal;
1212

13-
import static org.junit.Assert.assertEquals;
14-
import static org.junit.Assert.assertNull;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertNull;
15+
import static org.junit.jupiter.api.Assertions.assertThrows;
1516

1617
import java.util.Collection;
1718

@@ -21,16 +22,16 @@
2122
import org.eclipse.core.runtime.IExtension;
2223
import org.eclipse.core.runtime.InvalidRegistryObjectException;
2324
import org.eclipse.urischeme.IScheme;
24-
import org.junit.Before;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2627

2728
public class UriSchemeExtensionReaderUnitTest {
2829

2930
private UriSchemeHandlerSpy abcHandler;
3031
private ConfigurationElementMock configElementForAbc;
3132
private UriSchemeExtensionReader extensionReader;
3233

33-
@Before
34+
@BeforeEach
3435
public void setup() throws Exception {
3536
abcHandler = new UriSchemeHandlerSpy();
3637
configElementForAbc = new ConfigurationElementMock("abc", "abc Scheme", abcHandler);
@@ -58,12 +59,12 @@ public void callsFirstOfTwoHandlersForSameScheme() throws Exception {
5859
assertEquals(abcHandler, extensionReader.getHandlerFromExtensionPoint("abc"));
5960
}
6061

61-
@Test(expected = CoreException.class)
62+
@Test
6263
public void throwExceptionOnWrongRegisteredType() throws Exception {
6364
ConfigurationElementMock element = new ConfigurationElementMock("abc", "abc Scheme", new Object());
6465
setExtensionsInReader(element);
6566

66-
extensionReader.getHandlerFromExtensionPoint("abc");
67+
assertThrows(CoreException.class, () -> extensionReader.getHandlerFromExtensionPoint("abc"));
6768
}
6869

6970
@Test

tests/org.eclipse.tests.urischeme/src/org/eclipse/urischeme/internal/UriSchemeProcessorUnitTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.urischeme.internal;
1515

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

1920
import java.util.Collection;
2021
import java.util.HashMap;
@@ -25,16 +26,16 @@
2526
import org.eclipse.urischeme.IScheme;
2627
import org.eclipse.urischeme.IUriSchemeExtensionReader;
2728
import org.eclipse.urischeme.IUriSchemeHandler;
28-
import org.junit.Before;
29-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3031

3132
public class UriSchemeProcessorUnitTest {
3233

3334
private UriSchemeHandlerSpy abcHandler;
3435
private UriSchemeProcessor schemeProcessor;
3536
private UriSchemeExtensionReaderMock extensionReader;
3637

37-
@Before
38+
@BeforeEach
3839
public void setup() throws Exception {
3940
abcHandler = new UriSchemeHandlerSpy();
4041
extensionReader = new UriSchemeExtensionReaderMock();
@@ -49,7 +50,7 @@ public void callsRegisteredUriSchemeHandler() throws Exception {
4950
schemeProcessor.handleUri("abc", "abc://test");
5051

5152
String errorMsg = "Registered handler was not called for '" + "abc://test" + "'";
52-
assertTrue(errorMsg, abcHandler.uris.contains("abc://test"));
53+
assertTrue(abcHandler.uris.contains("abc://test"), errorMsg);
5354
}
5455

5556
@Test
@@ -65,13 +66,13 @@ public void buffersExtensionAndCreatesThemOnlyOnce() throws Exception {
6566
schemeProcessor.handleUri("abc", "abc://test");
6667

6768
assertEquals(2, abcHandler.uris.size());
68-
assertEquals("Extension created more than once", 1, (int) extensionReader.readCount.get("abc"));
69+
assertEquals(1, (int) extensionReader.readCount.get("abc"), "Extension created more than once");
6970
}
7071

71-
@Test(expected = CoreException.class)
72+
@Test
7273
public void passesException() throws Exception {
7374
extensionReader.exception = new CoreException(Status.CANCEL_STATUS);
74-
schemeProcessor.handleUri("abc", "abc://test");
75+
assertThrows(CoreException.class, () -> schemeProcessor.handleUri("abc", "abc://test"));
7576
}
7677

7778
private static class UriSchemeExtensionReaderMock implements IUriSchemeExtensionReader {

0 commit comments

Comments
 (0)