Migrate codec-memcache tests to JUnit 5 (#11310)

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 codec-memcache tests

Result:

Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
Riley Park 2021-05-26 01:14:27 -07:00 committed by Norman Maurer
parent 7be16c549b
commit c6aaaffec2
8 changed files with 53 additions and 44 deletions

View File

@ -22,15 +22,15 @@ import io.netty.handler.codec.memcache.LastMemcacheContent;
import io.netty.handler.codec.memcache.MemcacheContent;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCounted;
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 static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Verifies the correct functionality of the {@link AbstractBinaryMemcacheDecoder}.
@ -69,12 +69,12 @@ public class BinaryMemcacheDecoderTest {
private EmbeddedChannel channel;
@Before
@BeforeEach
public void setup() throws Exception {
channel = new EmbeddedChannel(new BinaryMemcacheRequestDecoder());
}
@After
@AfterEach
public void teardown() throws Exception {
channel.finishAndReleaseAll();
}

View File

@ -22,13 +22,15 @@ import io.netty.handler.codec.EncoderException;
import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
import io.netty.util.CharsetUtil;
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 org.junit.jupiter.api.function.Executable;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Verifies the correct functionality of the {@link AbstractBinaryMemcacheEncoder}.
@ -39,13 +41,13 @@ public class BinaryMemcacheEncoderTest {
private EmbeddedChannel channel;
@Before
public void setup() throws Exception {
@BeforeEach
public void setup() {
channel = new EmbeddedChannel(new BinaryMemcacheRequestEncoder());
}
@After
public void teardown() throws Exception {
@AfterEach
public void teardown() {
channel.finishAndReleaseAll();
}
@ -153,9 +155,14 @@ public class BinaryMemcacheEncoderTest {
written.release();
}
@Test(expected = EncoderException.class)
@Test
public void shouldFailWithoutLastContent() {
channel.writeOutbound(new DefaultMemcacheContent(Unpooled.EMPTY_BUFFER));
channel.writeOutbound(new DefaultBinaryMemcacheRequest());
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() {
channel.writeOutbound(new DefaultBinaryMemcacheRequest());
}
});
}
}

View File

@ -18,9 +18,9 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class BinaryMemcacheMessageTest {

View File

@ -21,14 +21,14 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
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;
/**
* Verifies the correct functionality of the {@link BinaryMemcacheObjectAggregator}.

View File

@ -18,17 +18,17 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
public class DefaultFullBinaryMemcacheRequestTest {
private DefaultFullBinaryMemcacheRequest request;
@Before
@BeforeEach
public void setUp() {
request = new DefaultFullBinaryMemcacheRequest(
Unpooled.copiedBuffer("key", CharsetUtil.UTF_8),

View File

@ -18,17 +18,17 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
public class DefaultFullBinaryMemcacheResponseTest {
private DefaultFullBinaryMemcacheResponse response;
@Before
@BeforeEach
public void setUp() {
response = new DefaultFullBinaryMemcacheResponse(
Unpooled.copiedBuffer("key", CharsetUtil.UTF_8),

View File

@ -19,17 +19,19 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
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 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.assertTrue;
public class FullMemcacheMessageRequestTest {
private EmbeddedChannel channel;
@Before
@BeforeEach
public void setup() throws Exception {
channel = new EmbeddedChannel(
new BinaryMemcacheRequestEncoder(),
@ -37,7 +39,7 @@ public class FullMemcacheMessageRequestTest {
new BinaryMemcacheObjectAggregator(1024));
}
@After
@AfterEach
public void teardown() throws Exception {
assertFalse(channel.finish());
}

View File

@ -19,19 +19,19 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class FullMemcacheMessageResponseTest {
private EmbeddedChannel channel;
@Before
@BeforeEach
public void setup() throws Exception {
channel = new EmbeddedChannel(
new BinaryMemcacheResponseEncoder(),
@ -39,7 +39,7 @@ public class FullMemcacheMessageResponseTest {
new BinaryMemcacheObjectAggregator(1024));
}
@After
@AfterEach
public void teardown() throws Exception {
assertFalse(channel.finish());
}