Remove rest of junit4 usage (#11484)

Motivation:

We did migrate all these modules to junit5 before but missed a few usages of junit4

Modifications:

Replace all junit4 imports by junit5 apis

Result:

Part of  https://github.com/netty/netty/issues/10757
This commit is contained in:
Norman Maurer 2021-07-13 20:59:57 +02:00 committed by GitHub
parent 7ec198ddf9
commit 043e9e309e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 35 deletions

View File

@ -32,7 +32,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel; import io.netty.channel.local.LocalServerChannel;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -124,7 +124,7 @@ public class Http2MultiplexCodecBuilderTest {
assertTrue(serverChannelLatch.await(5, SECONDS)); assertTrue(serverChannelLatch.await(5, SECONDS));
} }
@AfterClass @AfterAll
public static void shutdown() { public static void shutdown() {
group.shutdownGracefully(0, 5, SECONDS); group.shutdownGracefully(0, 5, SECONDS);
} }

View File

@ -44,8 +44,8 @@ import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_HEADER_LIST_SIZE;
import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_HEADER_TABLE_SIZE; import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_HEADER_TABLE_SIZE;
import static io.netty.util.ReferenceCountUtil.release; import static io.netty.util.ReferenceCountUtil.release;
import static java.lang.Math.min; import static java.lang.Math.min;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyByte; import static org.mockito.ArgumentMatchers.anyByte;

View File

@ -22,10 +22,10 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public final class MqttTestUtils { public final class MqttTestUtils {
private MqttTestUtils() { private MqttTestUtils() {
@ -48,7 +48,7 @@ public final class MqttTestUtils {
case SHARED_SUBSCRIPTION_AVAILABLE: { case SHARED_SUBSCRIPTION_AVAILABLE: {
final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value; final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value;
final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value; final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value;
assertEquals("one byte property doesn't match", expectedValue, actualValue); assertEquals(expectedValue, actualValue, "one byte property doesn't match");
break; break;
} }
// two byte value integer property // two byte value integer property
@ -58,7 +58,7 @@ public final class MqttTestUtils {
case TOPIC_ALIAS: { case TOPIC_ALIAS: {
final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value; final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value;
final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value; final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value;
assertEquals("two byte property doesn't match", expectedValue, actualValue); assertEquals(expectedValue, actualValue, "two byte property doesn't match");
break; break;
} }
// four byte value integer property // four byte value integer property
@ -68,7 +68,7 @@ public final class MqttTestUtils {
case MAXIMUM_PACKET_SIZE: { case MAXIMUM_PACKET_SIZE: {
final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value; final Integer expectedValue = ((MqttProperties.IntegerProperty) expectedProperty).value;
final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value; final Integer actualValue = ((MqttProperties.IntegerProperty) actualProperty).value;
assertEquals("four byte property doesn't match", expectedValue, actualValue); assertEquals(expectedValue, actualValue, "four byte property doesn't match");
break; break;
} }
// four byte value integer property // four byte value integer property
@ -87,7 +87,7 @@ public final class MqttTestUtils {
case REASON_STRING: { case REASON_STRING: {
final String expectedValue = ((MqttProperties.StringProperty) expectedProperty).value; final String expectedValue = ((MqttProperties.StringProperty) expectedProperty).value;
final String actualValue = ((MqttProperties.StringProperty) actualProperty).value; final String actualValue = ((MqttProperties.StringProperty) actualProperty).value;
assertEquals("String property doesn't match", expectedValue, actualValue); assertEquals(expectedValue, actualValue, "String property doesn't match");
break; break;
} }
// User property // User property
@ -96,9 +96,9 @@ public final class MqttTestUtils {
((MqttProperties.UserProperties) expectedProperty).value; ((MqttProperties.UserProperties) expectedProperty).value;
final List<MqttProperties.StringPair> actualPairs = final List<MqttProperties.StringPair> actualPairs =
((MqttProperties.UserProperties) actualProperty).value; ((MqttProperties.UserProperties) actualProperty).value;
assertEquals("User properties count doesn't match", expectedPairs, actualPairs); assertEquals(expectedPairs, actualPairs, "User properties count doesn't match");
for (int i = 0; i < expectedPairs.size(); i++) { for (int i = 0; i < expectedPairs.size(); i++) {
assertEquals("User property mismatch", expectedPairs.get(i), actualPairs.get(i)); assertEquals(expectedPairs.get(i), actualPairs.get(i), "User property mismatch");
} }
break; break;
} }
@ -109,7 +109,7 @@ public final class MqttTestUtils {
final byte[] actualValue = ((MqttProperties.BinaryProperty) actualProperty).value; final byte[] actualValue = ((MqttProperties.BinaryProperty) actualProperty).value;
final String expectedHexDump = ByteBufUtil.hexDump(expectedValue); final String expectedHexDump = ByteBufUtil.hexDump(expectedValue);
final String actualHexDump = ByteBufUtil.hexDump(actualValue); final String actualHexDump = ByteBufUtil.hexDump(actualValue);
assertEquals("byte[] property doesn't match", expectedHexDump, actualHexDump); assertEquals(expectedHexDump, actualHexDump, "byte[] property doesn't match");
break; break;
} }
default: default:
@ -118,7 +118,7 @@ public final class MqttTestUtils {
} }
for (MqttProperties.MqttProperty actualProperty : actual.listAll()) { for (MqttProperties.MqttProperty actualProperty : actual.listAll()) {
MqttProperties.MqttProperty expectedProperty = expected.getProperty(actualProperty.propertyId); MqttProperties.MqttProperty expectedProperty = expected.getProperty(actualProperty.propertyId);
assertNotNull("Property " + actualProperty.propertyId + " not expected", expectedProperty); assertNotNull(expectedProperty, "Property " + actualProperty.propertyId + " not expected");
} }
} }
@ -139,9 +139,9 @@ public final class MqttTestUtils {
List<MqttTopicSubscription> actualTopicSubscriptions = actual.topicSubscriptions(); List<MqttTopicSubscription> actualTopicSubscriptions = actual.topicSubscriptions();
assertEquals( assertEquals(
"MqttSubscribePayload TopicSubscriptionList size mismatch ",
expectedTopicSubscriptions.size(), expectedTopicSubscriptions.size(),
actualTopicSubscriptions.size()); actualTopicSubscriptions.size(),
"MqttSubscribePayload TopicSubscriptionList size mismatch");
for (int i = 0; i < expectedTopicSubscriptions.size(); i++) { for (int i = 0; i < expectedTopicSubscriptions.size(); i++) {
validateTopicSubscription(expectedTopicSubscriptions.get(i), actualTopicSubscriptions.get(i)); validateTopicSubscription(expectedTopicSubscriptions.get(i), actualTopicSubscriptions.get(i));
} }
@ -150,21 +150,21 @@ public final class MqttTestUtils {
public static void validateTopicSubscription( public static void validateTopicSubscription(
MqttTopicSubscription expected, MqttTopicSubscription expected,
MqttTopicSubscription actual) { MqttTopicSubscription actual) {
assertEquals("MqttTopicSubscription TopicName mismatch ", expected.topicName(), actual.topicName()); assertEquals(expected.topicName(), actual.topicName(), "MqttTopicSubscription TopicName mismatch");
assertEquals( assertEquals(
"MqttTopicSubscription Qos mismatch ",
expected.qualityOfService(), expected.qualityOfService(),
actual.qualityOfService()); actual.qualityOfService(),
"MqttTopicSubscription Qos mismatch");
assertEquals( assertEquals(
"MqttTopicSubscription options mismatch ",
expected.option(), expected.option(),
actual.option()); actual.option(),
"MqttTopicSubscription options mismatch");
} }
public static void validateUnsubscribePayload(MqttUnsubscribePayload expected, MqttUnsubscribePayload actual) { public static void validateUnsubscribePayload(MqttUnsubscribePayload expected, MqttUnsubscribePayload actual) {
assertArrayEquals( assertArrayEquals(
"MqttUnsubscribePayload TopicList mismatch ",
expected.topics().toArray(), expected.topics().toArray(),
actual.topics().toArray()); actual.topics().toArray(),
"MqttUnsubscribePayload TopicList mismatch");
} }
} }

View File

@ -34,7 +34,6 @@ import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import static io.netty.handler.codec.ByteToMessageDecoder.COMPOSITE_CUMULATOR; import static io.netty.handler.codec.ByteToMessageDecoder.COMPOSITE_CUMULATOR;
import static org.junit.Assert.assertNull;
public class AbstractSslHandlerBenchmark extends AbstractMicrobenchmark { public class AbstractSslHandlerBenchmark extends AbstractMicrobenchmark {
private static final String PROTOCOL_TLS_V1_2 = "TLSv1.2"; private static final String PROTOCOL_TLS_V1_2 = "TLSv1.2";
@ -176,6 +175,8 @@ public class AbstractSslHandlerBenchmark extends AbstractMicrobenchmark {
} }
public static void handleUnexpectedException(Throwable t) { public static void handleUnexpectedException(Throwable t) {
assertNull(t); if (t != null) {
throw new IllegalStateException(t);
}
} }
} }

View File

@ -15,7 +15,6 @@
*/ */
package io.netty.microbench.util; package io.netty.microbench.util;
import static org.junit.Assert.assertNull;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.util.concurrent.AbstractEventExecutor; import io.netty.util.concurrent.AbstractEventExecutor;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
@ -154,6 +153,8 @@ public class AbstractSharedExecutorMicrobenchmark extends AbstractMicrobenchmark
} }
public static void handleUnexpectedException(Throwable t) { public static void handleUnexpectedException(Throwable t) {
assertNull(t); if (t != null) {
throw new IllegalStateException(t);
}
} }
} }

View File

@ -18,7 +18,7 @@ package io.netty.testsuite.transport.socket;
import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement; import io.netty.util.internal.SuppressJava6Requirement;
import org.junit.Assume; import org.junit.AssumptionViolatedException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import java.io.IOException; import java.io.IOException;
@ -38,7 +38,7 @@ public class DatagramUnicastIPv6Test extends DatagramUnicastInetTest {
Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6); Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6);
channel.close(); channel.close();
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
Assume.assumeNoException("IPv6 not supported", e); throw new AssumptionViolatedException("IPv6 not supported", e);
} catch (IOException ignore) { } catch (IOException ignore) {
// Ignore // Ignore
} }

View File

@ -37,7 +37,7 @@ import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
public class SocketSpdyEchoTest extends AbstractSocketTest { public class SocketSpdyEchoTest extends AbstractSocketTest {

View File

@ -17,9 +17,9 @@
package io.netty.test.udt.nio; package io.netty.test.udt.nio;
import io.netty.test.udt.util.UnitHelp; import io.netty.test.udt.util.UnitHelp;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assume.*; import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* Base for UDT tests. * Base for UDT tests.
@ -29,7 +29,7 @@ public abstract class AbstractUdtTest {
/** /**
* UDT test assumptions. * UDT test assumptions.
*/ */
@BeforeClass @BeforeAll
public static void assumeConditions() { public static void assumeConditions() {
assumeTrue(UnitHelp.canLoadAndInitClass("com.barchart.udt.SocketUDT")); assumeTrue(UnitHelp.canLoadAndInitClass("com.barchart.udt.SocketUDT"));
} }