Skip to content

Commit 1a217e4

Browse files
authored
Upgrade to junit5 (java-native-access#295)
Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit 5 in tests Result: Use JUnit 5
1 parent 9bf7662 commit 1a217e4

22 files changed

+150
-143
lines changed

pom.xml

+16-16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<skipTests>false</skipTests>
7373
<netty.version>4.1.65.Final</netty.version>
7474
<netty.build.version>29</netty.build.version>
75+
<junit.version>5.7.0</junit.version>
7576
<jni.classifier>${os.detected.name}-${os.detected.arch}</jni.classifier>
7677
<jniLibName>netty_quiche_${os.detected.name}_${os.detected.arch}</jniLibName>
7778
<jniUtilIncludeDir>${project.build.directory}/netty-jni-util/</jniUtilIncludeDir>
@@ -646,13 +647,6 @@
646647
<trimStackTrace>false</trimStackTrace>
647648
<argLine>${test.argLine}</argLine>
648649
</configuration>
649-
<dependencies>
650-
<dependency>
651-
<groupId>org.apache.maven.surefire</groupId>
652-
<artifactId>surefire-junit4</artifactId>
653-
<version>2.22.1</version>
654-
</dependency>
655-
</dependencies>
656650
</plugin>
657651
<!-- always produce osgi bundles -->
658652
<plugin>
@@ -882,9 +876,21 @@
882876
<scope>test</scope>
883877
</dependency>
884878
<dependency>
885-
<groupId>junit</groupId>
886-
<artifactId>junit</artifactId>
887-
<version>4.13.1</version>
879+
<groupId>org.junit.jupiter</groupId>
880+
<artifactId>junit-jupiter-api</artifactId>
881+
<version>${junit.version}</version>
882+
<scope>test</scope>
883+
</dependency>
884+
<dependency>
885+
<groupId>org.junit.jupiter</groupId>
886+
<artifactId>junit-jupiter-engine</artifactId>
887+
<version>${junit.version}</version>
888+
<scope>test</scope>
889+
</dependency>
890+
<dependency>
891+
<groupId>org.junit.jupiter</groupId>
892+
<artifactId>junit-jupiter-params</artifactId>
893+
<version>${junit.version}</version>
888894
<scope>test</scope>
889895
</dependency>
890896
<dependency>
@@ -905,12 +911,6 @@
905911
<version>1.1.7</version>
906912
<scope>test</scope>
907913
</dependency>
908-
<dependency>
909-
<groupId>org.apache.maven.surefire</groupId>
910-
<artifactId>surefire-junit4</artifactId>
911-
<version>2.22.1</version>
912-
<scope>test</scope>
913-
</dependency>
914914
<!-- Also include bouncycastle so we can use SelfSignedCertificate even on more recent JDKs during testing -->
915915
<dependency>
916916
<groupId>org.bouncycastle</groupId>

src/test/java/io/netty/incubator/codec/quic/AbstractQuicTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package io.netty.incubator.codec.quic;
1717

1818
import org.junit.Assume;
19-
import org.junit.BeforeClass;
2019
import org.junit.Rule;
20+
import org.junit.jupiter.api.BeforeAll;
2121
import org.junit.rules.Timeout;
2222

2323
public abstract class AbstractQuicTest {
@@ -28,7 +28,7 @@ public abstract class AbstractQuicTest {
2828
@Rule
2929
public final Timeout globalTimeout = Timeout.seconds(TEST_GLOBAL_TIMEOUT_VALUE);
3030

31-
@BeforeClass
31+
@BeforeAll
3232
public static void assumeTrue() {
3333
Quic.ensureAvailability();
3434
Assume.assumeTrue(Quic.isAvailable());

src/test/java/io/netty/incubator/codec/quic/FlushStrategyTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.netty.incubator.codec.quic;
1717

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
public class FlushStrategyTest {
2424

src/test/java/io/netty/incubator/codec/quic/InsecureQuicTokenHandlerTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.buffer.Unpooled;
20-
import org.junit.Test;
20+
21+
import org.junit.jupiter.api.Test;
2122

2223
import java.net.InetAddress;
2324
import java.net.InetSocketAddress;
@@ -26,8 +27,9 @@
2627

2728
import static org.hamcrest.MatcherAssert.assertThat;
2829
import static org.hamcrest.Matchers.lessThanOrEqualTo;
29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertNotEquals;
30+
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3133

3234
public class InsecureQuicTokenHandlerTest extends AbstractQuicTest {
3335

src/test/java/io/netty/incubator/codec/quic/QuicChannelConnectTest.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
import io.netty.util.concurrent.Future;
3030
import org.hamcrest.CoreMatchers;
3131
import org.hamcrest.Matchers;
32-
import org.junit.Ignore;
33-
import org.junit.Test;
32+
import org.junit.jupiter.api.Disabled;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.Timeout;
3435

3536
import javax.net.ssl.SSLEngine;
3637
import javax.net.ssl.SSLException;
@@ -49,17 +50,19 @@
4950
import java.util.concurrent.BlockingQueue;
5051
import java.util.concurrent.CountDownLatch;
5152
import java.util.concurrent.LinkedBlockingQueue;
53+
import java.util.concurrent.TimeUnit;
5254
import java.util.function.Consumer;
5355

5456
import static org.hamcrest.MatcherAssert.assertThat;
55-
import static org.junit.Assert.assertEquals;
56-
import static org.junit.Assert.assertNull;
57-
import static org.junit.Assert.assertTrue;
58-
import static org.junit.Assert.fail;
57+
import static org.junit.jupiter.api.Assertions.assertEquals;
58+
import static org.junit.jupiter.api.Assertions.assertNull;
59+
import static org.junit.jupiter.api.Assertions.assertTrue;
60+
import static org.junit.jupiter.api.Assertions.fail;
5961

6062
public class QuicChannelConnectTest extends AbstractQuicTest {
6163

62-
@Test(timeout = 5000)
64+
@Test
65+
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
6366
public void testConnectAndQLog() throws Throwable {
6467
Path path = Files.createTempFile("qlog", ".quic");
6568
assertTrue(path.toFile().delete());
@@ -75,7 +78,8 @@ public void testConnectAndQLog() throws Throwable {
7578
});
7679
}
7780

78-
@Test(timeout = 5000)
81+
@Test
82+
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
7983
public void testConnectAndQLogDir() throws Throwable {
8084
Path path = Files.createTempDirectory("qlogdir-");
8185
testQLog(path, p -> {
@@ -406,7 +410,7 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
406410
}
407411
}
408412

409-
@Ignore
413+
@Disabled
410414
@Test
411415
public void testALPNProtocolMissmatch() throws Throwable {
412416
CountDownLatch latch = new CountDownLatch(1);

src/test/java/io/netty/incubator/codec/quic/QuicChannelDatagramTest.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@
2323
import io.netty.channel.ChannelHandlerContext;
2424
import io.netty.channel.ChannelInboundHandlerAdapter;
2525
import io.netty.channel.ChannelOption;
26-
import io.netty.channel.socket.DatagramPacket;
2726
import io.netty.util.ReferenceCountUtil;
2827
import io.netty.util.concurrent.ImmediateEventExecutor;
2928
import io.netty.util.concurrent.Promise;
30-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3130

3231
import java.net.InetSocketAddress;
3332
import java.util.Random;
3433
import java.util.concurrent.CountDownLatch;
3534
import java.util.concurrent.atomic.AtomicInteger;
3635
import java.util.concurrent.atomic.AtomicReference;
3736

38-
import static org.junit.Assert.assertEquals;
39-
import static org.junit.Assert.assertNotEquals;
40-
import static org.junit.Assert.assertTrue;
37+
import static org.junit.jupiter.api.Assertions.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
4140

4241
public class QuicChannelDatagramTest extends AbstractQuicTest {
4342

@@ -257,12 +256,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
257256
// Let's add some sleep in between as this is UDP so we may loose some data otherwise.
258257
Thread.sleep(50);
259258
}
260-
assertTrue("Server received: " + serverReadCount.get() +
261-
", Client received: " + clientReadCount.get(), serverPromise.await(3000));
259+
assertTrue(serverPromise.await(3000), "Server received: " + serverReadCount.get() +
260+
", Client received: " + clientReadCount.get());
262261
serverPromise.sync();
263262

264-
assertTrue("Server received: " + serverReadCount.get() +
265-
", Client received: " + clientReadCount.get(), clientPromise.await(3000));
263+
assertTrue(clientPromise.await(3000), "Server received: " + serverReadCount.get() +
264+
", Client received: " + clientReadCount.get());
266265
ByteBuf buffer = clientPromise.get();
267266
ByteBuf expected = Unpooled.wrappedBuffer(data);
268267
assertEquals(expected, buffer);

0 commit comments

Comments
 (0)