diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/AbstractDnsRecordTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/AbstractDnsRecordTest.java index 082e2c6947..c5c6d8b535 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/AbstractDnsRecordTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/AbstractDnsRecordTest.java @@ -15,8 +15,10 @@ */ package io.netty.handler.codec.dns; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AbstractDnsRecordTest { @@ -24,39 +26,39 @@ public class AbstractDnsRecordTest { public void testValidDomainName() { String name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; AbstractDnsRecord record = new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; - Assert.assertEquals(name + '.', record.name()); + assertEquals(name + '.', record.name()); } @Test public void testValidDomainNameUmlaut() { String name = "ä"; AbstractDnsRecord record = new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; - Assert.assertEquals("xn--4ca.", record.name()); + assertEquals("xn--4ca.", record.name()); } @Test public void testValidDomainNameTrailingDot() { String name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."; AbstractDnsRecord record = new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; - Assert.assertEquals(name, record.name()); + assertEquals(name, record.name()); } @Test public void testValidDomainNameUmlautTrailingDot() { String name = "ä."; AbstractDnsRecord record = new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; - Assert.assertEquals("xn--4ca.", record.name()); + assertEquals("xn--4ca.", record.name()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testValidDomainNameLength() { String name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; + assertThrows(IllegalArgumentException.class, () -> new AbstractDnsRecord(name, DnsRecordType.A, 0) { }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testValidDomainNameUmlautLength() { String name = "äaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - new AbstractDnsRecord(name, DnsRecordType.A, 0) { }; + assertThrows(IllegalArgumentException.class, () -> new AbstractDnsRecord(name, DnsRecordType.A, 0) { }); } } diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoderTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoderTest.java index 090c28a70c..a8379f6d8d 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoderTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoderTest.java @@ -18,9 +18,10 @@ package io.netty.handler.codec.dns; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class DefaultDnsRecordDecoderTest { @@ -145,13 +146,13 @@ public class DefaultDnsRecordDecoderTest { try { cnameRecord = (DefaultDnsRawRecord) decoder.decodeRecord( "netty.github.io", DnsRecordType.CNAME, DnsRecord.CLASS_IN, 60, buffer, 10, 2); - assertEquals("The rdata of CNAME-type record should be decompressed in advance", - 0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), cnameRecord.content())); + assertEquals(0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), cnameRecord.content()), + "The rdata of CNAME-type record should be decompressed in advance"); assertEquals("netty.io.", DnsCodecUtil.decodeDomainName(cnameRecord.content())); nsRecord = (DefaultDnsRawRecord) decoder.decodeRecord( "netty.github.io", DnsRecordType.NS, DnsRecord.CLASS_IN, 60, buffer, 10, 2); - assertEquals("The rdata of NS-type record should be decompressed in advance", - 0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), nsRecord.content())); + assertEquals(0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), nsRecord.content()), + "The rdata of NS-type record should be decompressed in advance"); assertEquals("netty.io.", DnsCodecUtil.decodeDomainName(nsRecord.content())); } finally { buffer.release(); diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoderTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoderTest.java index c1242aef59..968718c2d1 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoderTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoderTest.java @@ -20,12 +20,12 @@ import io.netty.buffer.Unpooled; import io.netty.channel.socket.InternetProtocolFamily; import io.netty.util.internal.SocketUtils; import io.netty.util.internal.StringUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.InetAddress; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultDnsRecordEncoderTest { diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsQueryTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsQueryTest.java index 0c7a321038..8002ff2ae3 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsQueryTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsQueryTest.java @@ -19,8 +19,7 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.util.internal.SocketUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -28,6 +27,8 @@ import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DnsQueryTest { @@ -61,9 +62,9 @@ public class DnsQueryTest { embedder.writeOutbound(query); DatagramPacket packet = embedder.readOutbound(); - Assert.assertTrue(packet.content().isReadable()); + assertTrue(packet.content().isReadable()); packet.release(); - Assert.assertNull(embedder.readOutbound()); + assertNull(embedder.readOutbound()); } } } diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsRecordTypeTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsRecordTypeTest.java index dec05c4b82..2a74834ad7 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsRecordTypeTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsRecordTypeTest.java @@ -15,7 +15,7 @@ */ package io.netty.handler.codec.dns; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -23,7 +23,10 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; public class DnsRecordTypeTest { @@ -40,8 +43,8 @@ public class DnsRecordTypeTest { @Test public void testSanity() throws Exception { - assertEquals("More than one type has the same int value", - allTypes().size(), new HashSet<>(allTypes()).size()); + assertEquals(allTypes().size(), new HashSet<>(allTypes()).size(), + "More than one type has the same int value"); } /** @@ -77,7 +80,7 @@ public class DnsRecordTypeTest { DnsRecordType found = DnsRecordType.valueOf(t.intValue()); assertSame(t, found); found = DnsRecordType.valueOf(t.name()); - assertSame(t.name(), t, found); + assertSame(t, found, t.name()); } } } diff --git a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsResponseTest.java b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsResponseTest.java index 7d4e629fe0..79f405f2ce 100644 --- a/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsResponseTest.java +++ b/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsResponseTest.java @@ -21,16 +21,14 @@ import io.netty.channel.AddressedEnvelope; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.handler.codec.CorruptedFrameException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.net.InetSocketAddress; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DnsResponseTest { @@ -95,16 +93,13 @@ public class DnsResponseTest { assertFalse(embedder.finish()); } - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void readMalformedResponseTest() throws Exception { EmbeddedChannel embedder = new EmbeddedChannel(new DatagramDnsResponseDecoder()); ByteBuf packet = embedder.alloc().buffer(512).writeBytes(malformedLoopPacket); - exception.expect(CorruptedFrameException.class); try { - embedder.writeInbound(new DatagramPacket(packet, null, new InetSocketAddress(0))); + assertThrows(CorruptedFrameException.class, + () -> embedder.writeInbound(new DatagramPacket(packet, null, new InetSocketAddress(0)))); } finally { assertFalse(embedder.finish()); } @@ -114,9 +109,9 @@ public class DnsResponseTest { public void readIncompleteResponseTest() { EmbeddedChannel embedder = new EmbeddedChannel(new DatagramDnsResponseDecoder()); ByteBuf packet = embedder.alloc().buffer(512); - exception.expect(CorruptedFrameException.class); try { - embedder.writeInbound(new DatagramPacket(packet, null, new InetSocketAddress(0))); + assertThrows(CorruptedFrameException.class, + () -> embedder.writeInbound(new DatagramPacket(packet, null, new InetSocketAddress(0)))); } finally { assertFalse(embedder.finish()); }