Skip to content

Commit

Permalink
Upgrade to junit5 (java-native-access#295)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
normanmaurer authored May 27, 2021
1 parent 9bf7662 commit 1a217e4
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 143 deletions.
32 changes: 16 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<skipTests>false</skipTests>
<netty.version>4.1.65.Final</netty.version>
<netty.build.version>29</netty.build.version>
<junit.version>5.7.0</junit.version>
<jni.classifier>${os.detected.name}-${os.detected.arch}</jni.classifier>
<jniLibName>netty_quiche_${os.detected.name}_${os.detected.arch}</jniLibName>
<jniUtilIncludeDir>${project.build.directory}/netty-jni-util/</jniUtilIncludeDir>
Expand Down Expand Up @@ -646,13 +647,6 @@
<trimStackTrace>false</trimStackTrace>
<argLine>${test.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.1</version>
</dependency>
</dependencies>
</plugin>
<!-- always produce osgi bundles -->
<plugin>
Expand Down Expand Up @@ -882,9 +876,21 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -905,12 +911,6 @@
<version>1.1.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.1</version>
<scope>test</scope>
</dependency>
<!-- Also include bouncycastle so we can use SelfSignedCertificate even on more recent JDKs during testing -->
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.netty.incubator.codec.quic;

import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.jupiter.api.BeforeAll;
import org.junit.rules.Timeout;

public abstract class AbstractQuicTest {
Expand All @@ -28,7 +28,7 @@ public abstract class AbstractQuicTest {
@Rule
public final Timeout globalTimeout = Timeout.seconds(TEST_GLOBAL_TIMEOUT_VALUE);

@BeforeClass
@BeforeAll
public static void assumeTrue() {
Quic.ensureAvailability();
Assume.assumeTrue(Quic.isAvailable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.netty.incubator.codec.quic;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class FlushStrategyTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;

import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand All @@ -26,8 +27,9 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class InsecureQuicTokenHandlerTest extends AbstractQuicTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import io.netty.util.concurrent.Future;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
Expand All @@ -49,17 +50,19 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class QuicChannelConnectTest extends AbstractQuicTest {

@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testConnectAndQLog() throws Throwable {
Path path = Files.createTempFile("qlog", ".quic");
assertTrue(path.toFile().delete());
Expand All @@ -75,7 +78,8 @@ public void testConnectAndQLog() throws Throwable {
});
}

@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testConnectAndQLogDir() throws Throwable {
Path path = Files.createTempDirectory("qlogdir-");
testQLog(path, p -> {
Expand Down Expand Up @@ -406,7 +410,7 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
}
}

@Ignore
@Disabled
@Test
public void testALPNProtocolMissmatch() throws Throwable {
CountDownLatch latch = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.net.InetSocketAddress;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class QuicChannelDatagramTest extends AbstractQuicTest {

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

assertTrue("Server received: " + serverReadCount.get() +
", Client received: " + clientReadCount.get(), clientPromise.await(3000));
assertTrue(clientPromise.await(3000), "Server received: " + serverReadCount.get() +
", Client received: " + clientReadCount.get());
ByteBuf buffer = clientPromise.get();
ByteBuf expected = Unpooled.wrappedBuffer(data);
assertEquals(expected, buffer);
Expand Down
Loading

0 comments on commit 1a217e4

Please sign in to comment.