Skip to content

Commit 4cc0209

Browse files
committed
Fix #139: convert JUnit4 to JUnit5
1 parent fb2b197 commit 4cc0209

15 files changed

+537
-688
lines changed

pom.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@ JUG supports 3 original official UUID generation methods as well as later additi
7474
<scope>runtime</scope>
7575
<optional>true</optional>
7676
</dependency>
77-
<!-- For testing, JUnit is needed -->
77+
<!-- For testing, JUnit 5 is needed -->
7878
<dependency>
79-
<groupId>junit</groupId>
80-
<artifactId>junit</artifactId>
81-
<version>${version.junit}</version>
79+
<groupId>org.junit.jupiter</groupId>
80+
<artifactId>junit-jupiter</artifactId>
81+
<version>${version.junit5}</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<!-- For JUnit 4 parameterized tests migration -->
85+
<dependency>
86+
<groupId>org.junit.jupiter</groupId>
87+
<artifactId>junit-jupiter-params</artifactId>
88+
<version>${version.junit5}</version>
89+
<scope>test</scope>
90+
</dependency>
91+
<!-- For Hamcrest matchers used in tests -->
92+
<dependency>
93+
<groupId>org.hamcrest</groupId>
94+
<artifactId>hamcrest</artifactId>
95+
<version>2.2</version>
8296
<scope>test</scope>
8397
</dependency>
8498
</dependencies>

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Releases
88

99
#124: TimeBasedEpochGenerator should prevent overflow
1010
(Chad P)
11+
#139: Upgrade tests from JUnit 4 to JUnit 5
1112
- Update to `oss-parent` v69
1213

1314
5.1.1 (26-Sep-2025)

src/test/java/com/fasterxml/uuid/EgressInterfaceFinderTest.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,61 @@
22

33
import com.fasterxml.uuid.EgressInterfaceFinder.EgressResolutionException;
44
import com.fasterxml.uuid.EgressInterfaceFinder.Finder;
5-
import junit.framework.TestCase;
5+
import org.junit.jupiter.api.Test;
66

77
import java.net.InetAddress;
88
import java.net.InetSocketAddress;
99
import java.net.NetworkInterface;
1010
import java.net.UnknownHostException;
1111

1212
import static com.fasterxml.uuid.EgressInterfaceFinder.DEFAULT_TIMEOUT_MILLIS;
13+
import static org.junit.jupiter.api.Assertions.*;
1314

14-
public class EgressInterfaceFinderTest extends TestCase {
15+
public class EgressInterfaceFinderTest {
1516

1617
private final EgressInterfaceFinder finder = new EgressInterfaceFinder();
1718

19+
@Test
1820
public void testUnspecifiedIPv4LocalAddress() throws UnknownHostException {
1921
EgressResolutionException ex = null;
2022
try {
2123
finder.fromLocalAddress(InetAddress.getByName("0.0.0.0"));
2224
} catch (EgressResolutionException e) {
2325
ex = e;
2426
}
25-
assertNotNull("EgressResolutionException was not thrown", ex);
27+
assertNotNull(ex, "EgressResolutionException was not thrown");
2628
String message = ex.getMessage();
27-
assertTrue(String.format(
29+
assertTrue(message.startsWith("local address"), String.format(
2830
"message [%s] does not begin with \"local address\"",
29-
message),
30-
message.startsWith("local address"));
31+
message));
3132
assertEquals(1, ex.getMessages().size());
3233
}
3334

35+
@Test
3436
public void testUnspecifiedIPv6LocalAddress() throws Exception {
3537
EgressResolutionException ex = null;
3638
try {
3739
finder.fromLocalAddress(InetAddress.getByName("::"));
3840
} catch (EgressResolutionException e) {
3941
ex = e;
4042
}
41-
assertNotNull("EgressResolutionException was not thrown", ex);
43+
assertNotNull(ex, "EgressResolutionException was not thrown");
4244
String message = ex.getMessage();
43-
assertTrue(String.format(
45+
assertTrue(message.startsWith("local address"), String.format(
4446
"message [%s] does not begin with \"local address\"",
45-
message),
46-
message.startsWith("local address"));
47+
message));
4748
assertEquals(1, ex.getMessages().size());
4849
}
4950

51+
@Test
5052
public void testFromLocalAddress() throws Exception {
5153
NetworkInterface anInterface =
5254
NetworkInterface.getNetworkInterfaces().nextElement();
5355
InetAddress anAddress = anInterface.getInetAddresses().nextElement();
5456
assertEquals(anInterface, finder.fromLocalAddress(anAddress));
5557
}
5658

59+
@Test
5760
public void testFromIncorrectLocalAddress() throws Exception {
5861
EgressResolutionException ex = null;
5962
try {
@@ -62,15 +65,15 @@ public void testFromIncorrectLocalAddress() throws Exception {
6265
} catch (EgressResolutionException e) {
6366
ex = e;
6467
}
65-
assertNotNull("EgressResolutionException was not thrown", ex);
68+
assertNotNull(ex, "EgressResolutionException was not thrown");
6669
String message = ex.getMessage();
67-
assertTrue(String.format(
70+
assertTrue(message.startsWith("no interface found"), String.format(
6871
"message [%s] does not begin with \"no interface found\"",
69-
message),
70-
message.startsWith("no interface found"));
72+
message));
7173
assertEquals(1, ex.getMessages().size());
7274
}
7375

76+
@Test
7477
public void testFromRemoteDatagramSocketConnection() throws Exception {
7578
if (!System.getProperty("os.name").startsWith("Mac")) {
7679
String name = EgressInterfaceFinder.randomRootServerName();
@@ -79,22 +82,26 @@ public void testFromRemoteDatagramSocketConnection() throws Exception {
7982
}
8083
}
8184

85+
@Test
8286
public void testFromRemoteSocketConnection() throws Exception {
8387
String name = EgressInterfaceFinder.randomRootServerName();
8488
InetSocketAddress address = new InetSocketAddress(name, 53);
8589
finder.fromRemoteSocketConnection(DEFAULT_TIMEOUT_MILLIS, address);
8690
}
8791

92+
@Test
8893
public void testFromRemoteConnection() throws Exception {
8994
String name = EgressInterfaceFinder.randomRootServerName();
9095
InetSocketAddress address = new InetSocketAddress(name, 53);
9196
finder.fromRemoteConnection(DEFAULT_TIMEOUT_MILLIS, address);
9297
}
9398

99+
@Test
94100
public void testFromRootNameServerConnection() throws Exception {
95101
finder.fromRootNameserverConnection(DEFAULT_TIMEOUT_MILLIS);
96102
}
97103

104+
@Test
98105
public void testAggregateExceptions() {
99106
EgressResolutionException ex = null;
100107
final int[] counter = {0};
@@ -112,10 +119,11 @@ public NetworkInterface egressInterface()
112119
} catch (EgressResolutionException e) {
113120
ex = e;
114121
}
115-
assertNotNull("EgressResolutionException was not thrown", ex);
122+
assertNotNull(ex, "EgressResolutionException was not thrown");
116123
assertEquals(9, ex.getMessages().size());
117124
}
118125

126+
@Test
119127
public void testDefaultMechanisms() throws Exception {
120128
try {
121129
finder.egressInterface();

0 commit comments

Comments
 (0)