From bad51c5e363eceedb7161f7d335ebfb0b7a1d3e3 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Wed, 26 May 2021 23:57:28 -0700 Subject: [PATCH] Migrate codec-redis tests to JUnit 5 (#11318) Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit5 in tests Result: Related to https://github.com/netty/netty/issues/10757 --- .../handler/codec/redis/RedisDecoderTest.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/codec-redis/src/test/java/io/netty/handler/codec/redis/RedisDecoderTest.java b/codec-redis/src/test/java/io/netty/handler/codec/redis/RedisDecoderTest.java index 7e9183f362..90b04cf7df 100644 --- a/codec-redis/src/test/java/io/netty/handler/codec/redis/RedisDecoderTest.java +++ b/codec-redis/src/test/java/io/netty/handler/codec/redis/RedisDecoderTest.java @@ -22,16 +22,19 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.DecoderException; import io.netty.util.IllegalReferenceCountException; import io.netty.util.ReferenceCountUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; import static io.netty.handler.codec.redis.RedisCodecTestUtil.*; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Verifies the correct functionality of the {@link RedisDecoder} and {@link RedisArrayAggregator}. @@ -40,7 +43,7 @@ public class RedisDecoderTest { private EmbeddedChannel channel; - @Before + @BeforeEach public void setup() throws Exception { channel = newChannel(false); } @@ -52,7 +55,7 @@ public class RedisDecoderTest { new RedisArrayAggregator()); } - @After + @AfterEach public void teardown() throws Exception { assertFalse(channel.finish()); } @@ -67,15 +70,17 @@ public class RedisDecoderTest { ReferenceCountUtil.release(msg); } - @Test(expected = DecoderException.class) + @Test public void shouldNotDecodeInlineCommandByDefault() { - assertFalse(channel.writeInbound(byteBufOf("P"))); - assertFalse(channel.writeInbound(byteBufOf("I"))); - assertFalse(channel.writeInbound(byteBufOf("N"))); - assertFalse(channel.writeInbound(byteBufOf("G"))); - assertTrue(channel.writeInbound(byteBufOf("\r\n"))); + assertThrows(DecoderException.class, () -> { + assertFalse(channel.writeInbound(byteBufOf("P"))); + assertFalse(channel.writeInbound(byteBufOf("I"))); + assertFalse(channel.writeInbound(byteBufOf("N"))); + assertFalse(channel.writeInbound(byteBufOf("G"))); + assertTrue(channel.writeInbound(byteBufOf("\r\n"))); - channel.readInbound(); + channel.readInbound(); + }); } @Test @@ -264,8 +269,8 @@ public class RedisDecoderTest { ReferenceCountUtil.release(msg); } - @Test(expected = IllegalReferenceCountException.class) - public void shouldErrorOnDoubleReleaseArrayReferenceCounted() throws Exception { + @Test + public void shouldErrorOnDoubleReleaseArrayReferenceCounted() { ByteBuf buf = Unpooled.buffer(); buf.writeBytes(byteBufOf("*2\r\n")); buf.writeBytes(byteBufOf("*3\r\n:1\r\n:2\r\n:3\r\n")); @@ -275,11 +280,11 @@ public class RedisDecoderTest { ArrayRedisMessage msg = channel.readInbound(); ReferenceCountUtil.release(msg); - ReferenceCountUtil.release(msg); + assertThrows(IllegalReferenceCountException.class, () -> ReferenceCountUtil.release(msg)); } - @Test(expected = IllegalReferenceCountException.class) - public void shouldErrorOnReleaseArrayChildReferenceCounted() throws Exception { + @Test + public void shouldErrorOnReleaseArrayChildReferenceCounted() { ByteBuf buf = Unpooled.buffer(); buf.writeBytes(byteBufOf("*2\r\n")); buf.writeBytes(byteBufOf("*3\r\n:1\r\n:2\r\n:3\r\n")); @@ -290,10 +295,10 @@ public class RedisDecoderTest { List children = msg.children(); ReferenceCountUtil.release(msg); - ReferenceCountUtil.release(children.get(1)); + assertThrows(IllegalReferenceCountException.class, () -> ReferenceCountUtil.release(children.get(1))); } - @Test(expected = IllegalReferenceCountException.class) + @Test public void shouldErrorOnReleasecontentOfArrayChildReferenceCounted() throws Exception { ByteBuf buf = Unpooled.buffer(); buf.writeBytes(byteBufOf("*2\r\n")); @@ -305,7 +310,7 @@ public class RedisDecoderTest { List children = msg.children(); ByteBuf childBuf = ((FullBulkStringRedisMessage) children.get(0)).content(); ReferenceCountUtil.release(msg); - ReferenceCountUtil.release(childBuf); + assertThrows(IllegalReferenceCountException.class, () -> ReferenceCountUtil.release(childBuf)); } @Test