Migrate codec-smtp tests to JUnit 5 (#11309)

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-smtp tests

Result:

Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
Riley Park 2021-05-26 00:44:06 -07:00 committed by GitHub
parent 078cdd2597
commit 343b5df922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View File

@ -15,9 +15,13 @@
*/ */
package io.netty.handler.codec.smtp; package io.netty.handler.codec.smtp;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SmtpCommandTest { public class SmtpCommandTest {
@Test @Test

View File

@ -20,11 +20,12 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.EncoderException; import io.netty.handler.codec.EncoderException;
import io.netty.util.CharsetUtil; 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;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SmtpRequestEncoderTest { public class SmtpRequestEncoderTest {
@ -106,12 +107,12 @@ public class SmtpRequestEncoderTest {
assertEquals("DATA\r\nSubject: Test\r\n\r\nTest\r\n.\r\n", getWrittenString(channel)); assertEquals("DATA\r\nSubject: Test\r\n\r\nTest\r\n.\r\n", getWrittenString(channel));
} }
@Test(expected = EncoderException.class) @Test
public void testThrowsIfContentExpected() { public void testThrowsIfContentExpected() {
EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder()); EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder());
try { try {
assertTrue(channel.writeOutbound(SmtpRequests.data())); assertTrue(channel.writeOutbound(SmtpRequests.data()));
channel.writeOutbound(SmtpRequests.noop()); assertThrows(EncoderException.class, () ->channel.writeOutbound(SmtpRequests.noop()));
} finally { } finally {
channel.finishAndReleaseAll(); channel.finishAndReleaseAll();
} }

View File

@ -20,11 +20,15 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.List; 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.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SmtpResponseDecoderTest { public class SmtpResponseDecoderTest {
@ -106,22 +110,22 @@ public class SmtpResponseDecoderTest {
assertNull(channel.readInbound()); assertNull(channel.readInbound());
} }
@Test(expected = DecoderException.class) @Test
public void testDecodeInvalidSeparator() { public void testDecodeInvalidSeparator() {
EmbeddedChannel channel = newChannel(); EmbeddedChannel channel = newChannel();
assertTrue(channel.writeInbound(newBuffer("200:Ok\r\n"))); assertThrows(DecoderException.class, () -> channel.writeInbound(newBuffer("200:Ok\r\n")));
} }
@Test(expected = DecoderException.class) @Test
public void testDecodeInvalidCode() { public void testDecodeInvalidCode() {
EmbeddedChannel channel = newChannel(); EmbeddedChannel channel = newChannel();
assertTrue(channel.writeInbound(newBuffer("xyz Ok\r\n"))); assertThrows(DecoderException.class, () -> channel.writeInbound(newBuffer("xyz Ok\r\n")));
} }
@Test(expected = DecoderException.class) @Test
public void testDecodeInvalidLine() { public void testDecodeInvalidLine() {
EmbeddedChannel channel = newChannel(); EmbeddedChannel channel = newChannel();
assertTrue(channel.writeInbound(newBuffer("Ok\r\n"))); assertThrows(DecoderException.class, () -> channel.writeInbound(newBuffer("Ok\r\n")));
} }
private static EmbeddedChannel newChannel() { private static EmbeddedChannel newChannel() {