diff --git a/common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java b/common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java index 8d5387543b..5030c3ef47 100644 --- a/common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java +++ b/common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java @@ -16,7 +16,9 @@ package io.netty.util; import io.netty.util.internal.ThreadLocalRandom; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.function.Executable; import java.util.ArrayDeque; import java.util.Queue; @@ -24,35 +26,52 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class AbstractReferenceCountedTest { - @Test(expected = IllegalReferenceCountException.class) + @Test public void testRetainOverflow() { - AbstractReferenceCounted referenceCounted = newReferenceCounted(); + final AbstractReferenceCounted referenceCounted = newReferenceCounted(); referenceCounted.setRefCnt(Integer.MAX_VALUE); assertEquals(Integer.MAX_VALUE, referenceCounted.refCnt()); - referenceCounted.retain(); + assertThrows(IllegalReferenceCountException.class, new Executable() { + @Override + public void execute() { + referenceCounted.retain(); + } + }); } - @Test(expected = IllegalReferenceCountException.class) + @Test public void testRetainOverflow2() { - AbstractReferenceCounted referenceCounted = newReferenceCounted(); + final AbstractReferenceCounted referenceCounted = newReferenceCounted(); assertEquals(1, referenceCounted.refCnt()); - referenceCounted.retain(Integer.MAX_VALUE); + assertThrows(IllegalReferenceCountException.class, new Executable() { + @Override + public void execute() { + referenceCounted.retain(Integer.MAX_VALUE); + } + }); } - @Test(expected = IllegalReferenceCountException.class) + @Test public void testReleaseOverflow() { - AbstractReferenceCounted referenceCounted = newReferenceCounted(); + final AbstractReferenceCounted referenceCounted = newReferenceCounted(); referenceCounted.setRefCnt(0); assertEquals(0, referenceCounted.refCnt()); - referenceCounted.release(Integer.MAX_VALUE); + assertThrows(IllegalReferenceCountException.class, new Executable() { + @Override + public void execute() { + referenceCounted.release(Integer.MAX_VALUE); + } + }); } @Test @@ -67,23 +86,34 @@ public class AbstractReferenceCountedTest { } } - @Test(expected = IllegalReferenceCountException.class) + @Test public void testRetainResurrect() { - AbstractReferenceCounted referenceCounted = newReferenceCounted(); + final AbstractReferenceCounted referenceCounted = newReferenceCounted(); assertTrue(referenceCounted.release()); assertEquals(0, referenceCounted.refCnt()); - referenceCounted.retain(); + assertThrows(IllegalReferenceCountException.class, new Executable() { + @Override + public void execute() { + referenceCounted.retain(); + } + }); } - @Test(expected = IllegalReferenceCountException.class) + @Test public void testRetainResurrect2() { - AbstractReferenceCounted referenceCounted = newReferenceCounted(); + final AbstractReferenceCounted referenceCounted = newReferenceCounted(); assertTrue(referenceCounted.release()); assertEquals(0, referenceCounted.refCnt()); - referenceCounted.retain(2); + assertThrows(IllegalReferenceCountException.class, new Executable() { + @Override + public void execute() { + referenceCounted.retain(2); + } + }); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception { int threads = 4; Queue> futures = new ArrayDeque>(threads); @@ -131,7 +161,8 @@ public class AbstractReferenceCountedTest { } } - @Test(timeout = 30000) + @Test + @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void testReleaseFromMultipleThreadsThrowsReferenceCountException() throws Exception { int threads = 4; Queue> futures = new ArrayDeque>(threads); diff --git a/common/src/test/java/io/netty/util/AsciiStringCharacterTest.java b/common/src/test/java/io/netty/util/AsciiStringCharacterTest.java index 0ddc951cda..15ad923267 100644 --- a/common/src/test/java/io/netty/util/AsciiStringCharacterTest.java +++ b/common/src/test/java/io/netty/util/AsciiStringCharacterTest.java @@ -15,7 +15,7 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -25,11 +25,11 @@ import static io.netty.util.AsciiString.contains; import static io.netty.util.AsciiString.containsIgnoreCase; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test character encoding and case insensitivity for the {@link AsciiString} class @@ -58,7 +58,7 @@ public class AsciiStringCharacterTest { final Charset charset = charsets[i]; byte[] expected = bString.getBytes(charset); byte[] actual = new AsciiString(b, charset).toByteArray(); - assertArrayEquals("failure for " + charset, expected, actual); + assertArrayEquals(expected, actual, "failure for " + charset); } } @@ -74,7 +74,7 @@ public class AsciiStringCharacterTest { final Charset charset = charsets[i]; byte[] expected = bString.getBytes(charset); byte[] actual = new AsciiString(bString, charset).toByteArray(); - assertArrayEquals("failure for " + charset, expected, actual); + assertArrayEquals(expected, actual, "failure for " + charset); } } @@ -197,29 +197,29 @@ public class AsciiStringCharacterTest { final String errorString = "len: " + len; // Test upper case hash codes are equal final int upperCaseExpected = upperCaseAscii.hashCode(); - assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseBuilder)); - assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseString)); - assertEquals(errorString, upperCaseExpected, upperCaseAscii.hashCode()); + assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseBuilder), errorString); + assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseString), errorString); + assertEquals(upperCaseExpected, upperCaseAscii.hashCode(), errorString); // Test lower case hash codes are equal final int lowerCaseExpected = lowerCaseAscii.hashCode(); - assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii)); - assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseString)); - assertEquals(errorString, lowerCaseExpected, lowerCaseAscii.hashCode()); + assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii), errorString); + assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseString), errorString); + assertEquals(lowerCaseExpected, lowerCaseAscii.hashCode(), errorString); // Test case insensitive hash codes are equal final int expectedCaseInsensitive = lowerCaseAscii.hashCode(); - assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder)); - assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseString)); - assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString)); - assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii)); - assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii)); - assertEquals(errorString, expectedCaseInsensitive, lowerCaseAscii.hashCode()); - assertEquals(errorString, expectedCaseInsensitive, upperCaseAscii.hashCode()); + assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder), errorString); + assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseString), errorString); + assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString), errorString); + assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii), errorString); + assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii), errorString); + assertEquals(expectedCaseInsensitive, lowerCaseAscii.hashCode(), errorString); + assertEquals(expectedCaseInsensitive, upperCaseAscii.hashCode(), errorString); // Test that opposite cases are equal - assertEquals(errorString, lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString)); - assertEquals(errorString, upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString)); + assertEquals(lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString), errorString); + assertEquals(upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString), errorString); } @Test diff --git a/common/src/test/java/io/netty/util/AsciiStringMemoryTest.java b/common/src/test/java/io/netty/util/AsciiStringMemoryTest.java index 3399b29aab..438f4c65d3 100644 --- a/common/src/test/java/io/netty/util/AsciiStringMemoryTest.java +++ b/common/src/test/java/io/netty/util/AsciiStringMemoryTest.java @@ -15,15 +15,15 @@ */ package io.netty.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import io.netty.util.ByteProcessor.IndexOfProcessor; import java.util.Random; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test the underlying memory methods for the {@link AsciiString} class. @@ -38,7 +38,7 @@ public class AsciiStringMemoryTest { private AsciiString bAsciiString; private Random r = new Random(); - @Before + @BeforeEach public void setup() { a = new byte[128]; b = new byte[256]; @@ -84,8 +84,8 @@ public class AsciiStringMemoryTest { aAsciiString.forEachByte(new ByteProcessor() { int i; @Override - public boolean process(byte value) throws Exception { - assertEquals("failed at index: " + i, value, bAsciiString.byteAt(i++)); + public boolean process(byte value) { + assertEquals(value, bAsciiString.byteAt(i++), "failed at index: " + i); aCount.set(aCount.get() + 1); return true; } @@ -93,8 +93,8 @@ public class AsciiStringMemoryTest { bAsciiString.forEachByte(new ByteProcessor() { int i; @Override - public boolean process(byte value) throws Exception { - assertEquals("failed at index: " + i, value, aAsciiString.byteAt(i++)); + public boolean process(byte value) { + assertEquals(value, aAsciiString.byteAt(i++), "failed at index: " + i); bCount.set(bCount.get() + 1); return true; } @@ -122,8 +122,8 @@ public class AsciiStringMemoryTest { aAsciiString.forEachByteDesc(new ByteProcessor() { int i = 1; @Override - public boolean process(byte value) throws Exception { - assertEquals("failed at index: " + i, value, bAsciiString.byteAt(bAsciiString.length() - (i++))); + public boolean process(byte value) { + assertEquals(value, bAsciiString.byteAt(bAsciiString.length() - (i++)), "failed at index: " + i); aCount.set(aCount.get() + 1); return true; } @@ -131,8 +131,8 @@ public class AsciiStringMemoryTest { bAsciiString.forEachByteDesc(new ByteProcessor() { int i = 1; @Override - public boolean process(byte value) throws Exception { - assertEquals("failed at index: " + i, value, aAsciiString.byteAt(aAsciiString.length() - (i++))); + public boolean process(byte value) { + assertEquals(value, aAsciiString.byteAt(aAsciiString.length() - (i++)), "failed at index: " + i); bCount.set(bCount.get() + 1); return true; } diff --git a/common/src/test/java/io/netty/util/AttributeKeyTest.java b/common/src/test/java/io/netty/util/AttributeKeyTest.java index 502f115c85..0024671e88 100644 --- a/common/src/test/java/io/netty/util/AttributeKeyTest.java +++ b/common/src/test/java/io/netty/util/AttributeKeyTest.java @@ -15,9 +15,13 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class AttributeKeyTest { diff --git a/common/src/test/java/io/netty/util/ConstantPoolTest.java b/common/src/test/java/io/netty/util/ConstantPoolTest.java index 8fbef68370..5bcafb042f 100644 --- a/common/src/test/java/io/netty/util/ConstantPoolTest.java +++ b/common/src/test/java/io/netty/util/ConstantPoolTest.java @@ -15,7 +15,8 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.Arrays; import java.util.Comparator; @@ -24,6 +25,7 @@ import java.util.TreeSet; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class ConstantPoolTest { @@ -40,9 +42,14 @@ public class ConstantPoolTest { } }; - @Test(expected = NullPointerException.class) + @Test public void testCannotProvideNullName() { - pool.valueOf(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + pool.valueOf(null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java index e3a87ab3e5..cb70c4062b 100644 --- a/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java +++ b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java @@ -15,16 +15,22 @@ */ package io.netty.util; -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.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultAttributeMapTest { private DefaultAttributeMap map; - @Before + @BeforeEach public void setup() { map = new DefaultAttributeMap(); } diff --git a/common/src/test/java/io/netty/util/DomainNameMappingTest.java b/common/src/test/java/io/netty/util/DomainNameMappingTest.java index 7cd75a0e88..f5a85ca3af 100644 --- a/common/src/test/java/io/netty/util/DomainNameMappingTest.java +++ b/common/src/test/java/io/netty/util/DomainNameMappingTest.java @@ -16,30 +16,47 @@ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @SuppressWarnings("deprecation") public class DomainNameMappingTest { // Deprecated API - @Test(expected = NullPointerException.class) + @Test public void testNullDefaultValueInDeprecatedApi() { - new DomainNameMapping(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMapping(null); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() { - new DomainNameMapping("NotFound").add(null, "Some value"); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMapping("NotFound").add(null, "Some value"); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullValuesAreForbiddenInDeprecatedApi() { - new DomainNameMapping("NotFound").add("Some key", null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMapping("NotFound").add("Some key", null); + } + }); } @Test @@ -105,19 +122,35 @@ public class DomainNameMappingTest { // Immutable DomainNameMapping Builder API - @Test(expected = NullPointerException.class) + @Test public void testNullDefaultValue() { - new DomainNameMappingBuilder(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMappingBuilder(null); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullDomainNamePatternsAreForbidden() { - new DomainNameMappingBuilder("NotFound").add(null, "Some value"); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMappingBuilder("NotFound").add(null, "Some value"); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullValuesAreForbidden() { - new DomainNameMappingBuilder("NotFound").add("Some key", null); + + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainNameMappingBuilder("NotFound").add("Some key", null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/DomainWildcardMappingBuilderTest.java b/common/src/test/java/io/netty/util/DomainWildcardMappingBuilderTest.java index 489b2b2ebb..06ab1a692b 100644 --- a/common/src/test/java/io/netty/util/DomainWildcardMappingBuilderTest.java +++ b/common/src/test/java/io/netty/util/DomainWildcardMappingBuilderTest.java @@ -16,27 +16,44 @@ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DomainWildcardMappingBuilderTest { - @Test(expected = NullPointerException.class) + @Test public void testNullDefaultValue() { - new DomainWildcardMappingBuilder(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainWildcardMappingBuilder(null); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullDomainNamePatternsAreForbidden() { - new DomainWildcardMappingBuilder("NotFound").add(null, "Some value"); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainWildcardMappingBuilder("NotFound").add(null, "Some value"); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testNullValuesAreForbidden() { - new DomainWildcardMappingBuilder("NotFound").add("Some key", null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new DomainWildcardMappingBuilder("NotFound").add("Some key", null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/HashedWheelTimerTest.java b/common/src/test/java/io/netty/util/HashedWheelTimerTest.java index b720f3ceff..047c033ee6 100644 --- a/common/src/test/java/io/netty/util/HashedWheelTimerTest.java +++ b/common/src/test/java/io/netty/util/HashedWheelTimerTest.java @@ -15,7 +15,7 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; @@ -24,10 +24,10 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HashedWheelTimerTest { @@ -43,7 +43,7 @@ public class HashedWheelTimerTest { } }, 10, TimeUnit.SECONDS); assertFalse(barrier.await(3, TimeUnit.SECONDS)); - assertFalse("timer should not expire", timeout.isExpired()); + assertFalse(timeout.isExpired(), "timer should not expire"); timer.stop(); } @@ -58,11 +58,12 @@ public class HashedWheelTimerTest { } }, 2, TimeUnit.SECONDS); assertTrue(barrier.await(3, TimeUnit.SECONDS)); - assertTrue("timer should expire", timeout.isExpired()); + assertTrue(timeout.isExpired(), "timer should expire"); timer.stop(); } - @Test(timeout = 3000) + @Test + @org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testStopTimer() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(3); final Timer timerProcessed = new HashedWheelTimer(); @@ -76,7 +77,7 @@ public class HashedWheelTimerTest { } latch.await(); - assertEquals("Number of unprocessed timeouts should be 0", 0, timerProcessed.stop().size()); + assertEquals(0, timerProcessed.stop().size(), "Number of unprocessed timeouts should be 0"); final Timer timerUnprocessed = new HashedWheelTimer(); for (int i = 0; i < 5; i ++) { @@ -87,10 +88,11 @@ public class HashedWheelTimerTest { }, 5, TimeUnit.SECONDS); } Thread.sleep(1000L); // sleep for a second - assertFalse("Number of unprocessed timeouts should be greater than 0", timerUnprocessed.stop().isEmpty()); + assertFalse(timerUnprocessed.stop().isEmpty(), "Number of unprocessed timeouts should be greater than 0"); } - @Test(timeout = 3000) + @Test + @org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testTimerShouldThrowExceptionAfterShutdownForNewTimeouts() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(3); final Timer timer = new HashedWheelTimer(); @@ -114,7 +116,8 @@ public class HashedWheelTimerTest { } } - @Test(timeout = 5000) + @Test + @org.junit.jupiter.api.Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testTimerOverflowWheelLength() throws InterruptedException { final HashedWheelTimer timer = new HashedWheelTimer( Executors.defaultThreadFactory(), 100, TimeUnit.MILLISECONDS, 32); @@ -153,8 +156,8 @@ public class HashedWheelTimerTest { for (int i = 0; i < scheduledTasks; i++) { long delay = queue.take(); - assertTrue("Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout, - delay >= timeout && delay < maxTimeout); + assertTrue(delay >= timeout && delay < maxTimeout, + "Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout); } timer.stop(); @@ -195,7 +198,8 @@ public class HashedWheelTimerTest { timer.stop(); } - @Test(timeout = 3000) + @Test + @org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testNewTimeoutShouldStopThrowingRejectedExecutionExceptionWhenExistingTimeoutIsExecuted() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); diff --git a/common/src/test/java/io/netty/util/NetUtilTest.java b/common/src/test/java/io/netty/util/NetUtilTest.java index 78b2532064..c7663c497e 100644 --- a/common/src/test/java/io/netty/util/NetUtilTest.java +++ b/common/src/test/java/io/netty/util/NetUtilTest.java @@ -16,7 +16,7 @@ package io.netty.util; import io.netty.util.internal.StringUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.Inet4Address; import java.net.Inet6Address; @@ -28,11 +28,11 @@ import java.util.Map; import java.util.Map.Entry; import static io.netty.util.NetUtil.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class NetUtilTest { @@ -611,72 +611,72 @@ public class NetUtilTest { @Test public void testIsValidIpV4Address() { for (String host : validIpV4Hosts.keySet()) { - assertTrue(host, isValidIpV4Address(host)); + assertTrue(isValidIpV4Address(host), host); } for (String host : invalidIpV4Hosts.keySet()) { - assertFalse(host, isValidIpV4Address(host)); + assertFalse(isValidIpV4Address(host), host); } } @Test public void testIsValidIpV6Address() { for (String host : validIpV6Hosts.keySet()) { - assertTrue(host, isValidIpV6Address(host)); + assertTrue(isValidIpV6Address(host), host); if (host.charAt(0) != '[' && !host.contains("%")) { - assertNotNull(host, getByName(host, true)); + assertNotNull(getByName(host, true), host); String hostMod = '[' + host + ']'; - assertTrue(hostMod, isValidIpV6Address(hostMod)); + assertTrue(isValidIpV6Address(hostMod), hostMod); hostMod = host + '%'; - assertTrue(hostMod, isValidIpV6Address(hostMod)); + assertTrue(isValidIpV6Address(hostMod), hostMod); hostMod = host + "%eth1"; - assertTrue(hostMod, isValidIpV6Address(hostMod)); + assertTrue(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "%]"; - assertTrue(hostMod, isValidIpV6Address(hostMod)); + assertTrue(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "%1]"; - assertTrue(hostMod, isValidIpV6Address(hostMod)); + assertTrue(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "]%"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "]%1"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); } } for (String host : invalidIpV6Hosts.keySet()) { - assertFalse(host, isValidIpV6Address(host)); - assertNull(host, getByName(host)); + assertFalse(isValidIpV6Address(host), host); + assertNull(getByName(host), host); String hostMod = '[' + host + ']'; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = host + '%'; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = host + "%eth1"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "%]"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "%1]"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "]%"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host + "]%1"; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = host + ']'; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); hostMod = '[' + host; - assertFalse(hostMod, isValidIpV6Address(hostMod)); + assertFalse(isValidIpV6Address(hostMod), hostMod); } } @@ -737,19 +737,19 @@ public class NetUtilTest { String srcIp = testEntry.getKey(); String dstIp = testEntry.getValue(); Inet6Address inet6Address = getByName(srcIp, true); - assertNotNull(srcIp + ", " + dstIp, inet6Address); - assertEquals(srcIp, dstIp, toAddressString(inet6Address, true)); + assertNotNull(inet6Address, srcIp + ", " + dstIp); + assertEquals(dstIp, toAddressString(inet6Address, true), srcIp); } } @Test public void testInvalidIpv4MappedIp6GetByName() { for (String host : invalidIpV4Hosts.keySet()) { - assertNull(host, getByName(host, true)); + assertNull(getByName(host, true), host); } for (String host : invalidIpV6Hosts.keySet()) { - assertNull(host, getByName(host, true)); + assertNull(getByName(host, true), host); } } @@ -770,7 +770,7 @@ public class NetUtilTest { } private static void assertHexDumpEquals(String expected, byte[] actual, String message) { - assertEquals(message, expected, hex(actual)); + assertEquals(expected, hex(actual), message); } private static String hex(byte[] value) { diff --git a/common/src/test/java/io/netty/util/NettyRuntimeTests.java b/common/src/test/java/io/netty/util/NettyRuntimeTests.java index 60374b8711..9024c19ebc 100644 --- a/common/src/test/java/io/netty/util/NettyRuntimeTests.java +++ b/common/src/test/java/io/netty/util/NettyRuntimeTests.java @@ -17,7 +17,7 @@ package io.netty.util; import io.netty.util.internal.SystemPropertyUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; @@ -27,9 +27,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class NettyRuntimeTests { diff --git a/common/src/test/java/io/netty/util/RecyclerTest.java b/common/src/test/java/io/netty/util/RecyclerTest.java index 0c2d070560..a06523fcec 100644 --- a/common/src/test/java/io/netty/util/RecyclerTest.java +++ b/common/src/test/java/io/netty/util/RecyclerTest.java @@ -15,15 +15,24 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.function.Executable; import java.util.Random; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RecyclerTest { @@ -44,7 +53,8 @@ public class RecyclerTest { }; } - @Test(timeout = 5000L) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() throws Exception { final Recycler recycler = newRecycler(1024); final AtomicBoolean collected = new AtomicBoolean(); @@ -81,15 +91,20 @@ public class RecyclerTest { reference.getAndSet(null).recycle(); } - @Test(expected = IllegalStateException.class) + @Test public void testMultipleRecycle() { Recycler recycler = newRecycler(1024); - HandledObject object = recycler.get(); - object.recycle(); + final HandledObject object = recycler.get(); object.recycle(); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + object.recycle(); + } + }); } - @Test(expected = IllegalStateException.class) + @Test public void testMultipleRecycleAtDifferentThread() throws InterruptedException { Recycler recycler = newRecycler(1024); final HandledObject object = recycler.get(); @@ -119,9 +134,7 @@ public class RecyclerTest { HandledObject b = recycler.get(); assertNotSame(a, b); IllegalStateException exception = exceptionStore.get(); - if (exception != null) { - throw exception; - } + assertNotNull(exception); } @Test @@ -307,9 +320,9 @@ public class RecyclerTest { objects[i] = null; } - assertTrue("The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity (" - + maxCapacity + ") as we not pool all new handles internally", - maxCapacity >= recycler.threadLocalCapacity()); + assertTrue(maxCapacity >= recycler.threadLocalCapacity(), + "The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity (" + + maxCapacity + ") as we not pool all new handles internally"); } @Test @@ -416,9 +429,10 @@ public class RecyclerTest { } // The implementation uses maxCapacity / 2 as limit per WeakOrderQueue - assertTrue("The instances count (" + instancesCount.get() + ") must be <= array.length (" + array.length + assertTrue(array.length - maxCapacity / 2 <= instancesCount.get(), + "The instances count (" + instancesCount.get() + ") must be <= array.length (" + array.length + ") - maxCapacity (" + maxCapacity + ") / 2 as we not pool all new handles" + - " internally", array.length - maxCapacity / 2 <= instancesCount.get()); + " internally"); } static final class HandledObject { diff --git a/common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java b/common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java index 6d080cf46c..d98584627c 100644 --- a/common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java +++ b/common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java @@ -15,17 +15,20 @@ */ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; public class ResourceLeakDetectorTest { - @Test(timeout = 60000) + @Test + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) public void testConcurrentUsage() throws Throwable { final AtomicBoolean finished = new AtomicBoolean(); final AtomicReference error = new AtomicReference(); diff --git a/common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java b/common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java index 769ac0b5c5..9a0609a5e4 100644 --- a/common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java +++ b/common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java @@ -16,7 +16,8 @@ package io.netty.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -25,12 +26,13 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ThreadDeathWatcherTest { - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void testWatch() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final Thread t = new Thread() { @@ -75,7 +77,8 @@ public class ThreadDeathWatcherTest { latch.await(); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void testUnwatch() throws Exception { final AtomicBoolean run = new AtomicBoolean(); final Thread t = new Thread() { @@ -117,7 +120,8 @@ public class ThreadDeathWatcherTest { assertThat(run.get(), is(false)); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testThreadGroup() throws InterruptedException { final ThreadGroup group = new ThreadGroup("group"); final AtomicReference capturedGroup = new AtomicReference(); diff --git a/common/src/test/java/io/netty/util/concurrent/AbstractScheduledEventExecutorTest.java b/common/src/test/java/io/netty/util/concurrent/AbstractScheduledEventExecutorTest.java index b9f5875ddb..fca6ad2d27 100644 --- a/common/src/test/java/io/netty/util/concurrent/AbstractScheduledEventExecutorTest.java +++ b/common/src/test/java/io/netty/util/concurrent/AbstractScheduledEventExecutorTest.java @@ -15,15 +15,17 @@ */ package io.netty.util.concurrent; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AbstractScheduledEventExecutorTest { private static final Runnable TEST_RUNNABLE = new Runnable() { @@ -71,28 +73,48 @@ public class AbstractScheduledEventExecutorTest { assertNull(executor.pollScheduledTask()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testScheduleAtFixedRateRunnableZero() { - TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); - executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS); + final TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testScheduleAtFixedRateRunnableNegative() { - TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); - executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + final TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testScheduleWithFixedDelayZero() { - TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); - executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + final TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testScheduleWithFixedDelayNegative() { - TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); - executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + final TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); + } + }); } private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor { diff --git a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java index e323215c30..f442276c0a 100644 --- a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java +++ b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java @@ -19,8 +19,10 @@ package io.netty.util.concurrent; import io.netty.util.Signal; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.function.Executable; import org.mockito.Mockito; import java.util.HashMap; @@ -40,14 +42,19 @@ import static java.lang.Math.max; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.lessThan; -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.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("unchecked") public class DefaultPromiseTest { private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultPromiseTest.class); private static int stackOverflowDepth; - @BeforeClass + @BeforeAll public static void beforeClass() { try { findStackOverflowDepth(); @@ -101,24 +108,32 @@ public class DefaultPromiseTest { assertSame(cause, promise.cause()); } - @Test(expected = CancellationException.class) - public void testCancellationExceptionIsThrownWhenBlockingGet() throws InterruptedException, ExecutionException { + @Test + public void testCancellationExceptionIsThrownWhenBlockingGet() { final Promise promise = new DefaultPromise(ImmediateEventExecutor.INSTANCE); assertTrue(promise.cancel(false)); - promise.get(); - } - - @Test(expected = CancellationException.class) - public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() throws InterruptedException, - ExecutionException, TimeoutException { - final Promise promise = new DefaultPromise(ImmediateEventExecutor.INSTANCE); - assertTrue(promise.cancel(false)); - promise.get(1, TimeUnit.SECONDS); + assertThrows(CancellationException.class, new Executable() { + @Override + public void execute() throws Throwable { + promise.get(); + } + }); } @Test - public void testCancellationExceptionIsReturnedAsCause() throws InterruptedException, - ExecutionException, TimeoutException { + public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() { + final Promise promise = new DefaultPromise(ImmediateEventExecutor.INSTANCE); + assertTrue(promise.cancel(false)); + assertThrows(CancellationException.class, new Executable() { + @Override + public void execute() throws Throwable { + promise.get(1, TimeUnit.SECONDS); + } + }); + } + + @Test + public void testCancellationExceptionIsReturnedAsCause() { final Promise promise = new DefaultPromise(ImmediateEventExecutor.INSTANCE); assertTrue(promise.cancel(false)); assertThat(promise.cause(), instanceOf(CancellationException.class)); @@ -212,11 +227,11 @@ public class DefaultPromiseTest { promise.addListener(listener1).addListener(listener2).addListener(listener3); - assertSame("Fail 1 during run " + i + " / " + runs, listener1, listeners.take()); - assertSame("Fail 2 during run " + i + " / " + runs, listener2, listeners.take()); - assertSame("Fail 3 during run " + i + " / " + runs, listener3, listeners.take()); - assertSame("Fail 4 during run " + i + " / " + runs, listener4, listeners.take()); - assertTrue("Fail during run " + i + " / " + runs, listeners.isEmpty()); + assertSame(listener1, listeners.take(), "Fail 1 during run " + i + " / " + runs); + assertSame(listener2, listeners.take(), "Fail 2 during run " + i + " / " + runs); + assertSame(listener3, listeners.take(), "Fail 3 during run " + i + " / " + runs); + assertSame(listener4, listeners.take(), "Fail 4 during run " + i + " / " + runs); + assertTrue(listeners.isEmpty(), "Fail during run " + i + " / " + runs); } } finally { executor.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync(); @@ -232,22 +247,26 @@ public class DefaultPromiseTest { testListenerNotifyLater(2); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testPromiseListenerAddWhenCompleteFailure() throws Exception { testPromiseListenerAddWhenComplete(fakeException()); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testPromiseListenerAddWhenCompleteSuccess() throws Exception { testPromiseListenerAddWhenComplete(null); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testLateListenerIsOrderedCorrectlySuccess() throws InterruptedException { testLateListenerIsOrderedCorrectly(null); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testLateListenerIsOrderedCorrectlyFailure() throws InterruptedException { testLateListenerIsOrderedCorrectly(fakeException()); } @@ -336,7 +355,7 @@ public class DefaultPromiseTest { assertTrue(latch.await(2, TimeUnit.SECONDS)); for (int i = 0; i < p.length; ++i) { - assertTrue("index " + i, p[i].isSuccess()); + assertTrue(p[i].isSuccess(), "index " + i); } } @@ -378,7 +397,7 @@ public class DefaultPromiseTest { assertTrue(latch.await(2, TimeUnit.SECONDS)); for (int i = 0; i < p.length; ++i) { - assertTrue("index " + i, p[i].isSuccess()); + assertTrue(p[i].isSuccess(), "index " + i); } } @@ -534,8 +553,8 @@ public class DefaultPromiseTest { } }); - assertTrue("Should have notified " + expectedCount + " listeners", - latch.await(5, TimeUnit.SECONDS)); + assertTrue(latch.await(5, TimeUnit.SECONDS), + "Should have notified " + expectedCount + " listeners"); executor.shutdownGracefully().sync(); } diff --git a/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java b/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java index b338a8fded..c1e231b9e3 100644 --- a/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java +++ b/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java @@ -16,20 +16,23 @@ package io.netty.util.concurrent; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.security.Permission; import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultThreadFactoryTest { - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testDescendantThreadGroups() throws InterruptedException { final SecurityManager current = System.getSecurityManager(); @@ -117,7 +120,8 @@ public class DefaultThreadFactoryTest { // test that when DefaultThreadFactory is constructed with a sticky thread group, threads // created by it have the sticky thread group - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testDefaultThreadFactoryStickyThreadGroupConstructor() throws InterruptedException { final ThreadGroup sticky = new ThreadGroup("sticky"); runStickyThreadGroupTest( @@ -132,7 +136,8 @@ public class DefaultThreadFactoryTest { // test that when a security manager is installed that provides a ThreadGroup, DefaultThreadFactory inherits from // the security manager - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testDefaultThreadFactoryInheritsThreadGroupFromSecurityManager() throws InterruptedException { final SecurityManager current = System.getSecurityManager(); @@ -196,7 +201,8 @@ public class DefaultThreadFactoryTest { // test that when DefaultThreadFactory is constructed without a sticky thread group, threads // created by it inherit the correct thread group - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testDefaultThreadFactoryNonStickyThreadGroupConstructor() throws InterruptedException { final AtomicReference factory = new AtomicReference(); @@ -242,7 +248,8 @@ public class DefaultThreadFactoryTest { // test that when DefaultThreadFactory is constructed without a sticky thread group, threads // created by it inherit the correct thread group - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testCurrentThreadGroupIsUsed() throws InterruptedException { final AtomicReference factory = new AtomicReference(); final AtomicReference firstCaptured = new AtomicReference(); diff --git a/common/src/test/java/io/netty/util/concurrent/FastThreadLocalTest.java b/common/src/test/java/io/netty/util/concurrent/FastThreadLocalTest.java index 1948b12a73..8d8820c916 100644 --- a/common/src/test/java/io/netty/util/concurrent/FastThreadLocalTest.java +++ b/common/src/test/java/io/netty/util/concurrent/FastThreadLocalTest.java @@ -17,22 +17,24 @@ package io.netty.util.concurrent; import io.netty.util.internal.ObjectCleaner; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FastThreadLocalTest { - @Before + @BeforeEach public void setUp() { FastThreadLocal.removeAll(); assertThat(FastThreadLocal.size(), is(0)); @@ -55,7 +57,8 @@ public class FastThreadLocalTest { assertNull(threadLocal.getIfExists()); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void testRemoveAll() throws Exception { final AtomicBoolean removed = new AtomicBoolean(); final FastThreadLocal var = new FastThreadLocal() { @@ -75,7 +78,8 @@ public class FastThreadLocalTest { assertThat(FastThreadLocal.size(), is(0)); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void testRemoveAllFromFTLThread() throws Throwable { final AtomicReference throwable = new AtomicReference(); final Thread thread = new FastThreadLocalThread() { @@ -157,24 +161,28 @@ public class FastThreadLocalTest { assertEquals(0, ObjectCleaner.getLiveSetCount() - sizeWhenStart); } - @Test(timeout = 4000) + @Test + @Timeout(value = 4000, unit = TimeUnit.MILLISECONDS) public void testOnRemoveCalledForFastThreadLocalGet() throws Exception { testOnRemoveCalled(true, true); } - @Ignore("onRemoval(...) not called with non FastThreadLocal") - @Test(timeout = 4000) + @Disabled("onRemoval(...) not called with non FastThreadLocal") + @Test + @Timeout(value = 4000, unit = TimeUnit.MILLISECONDS) public void testOnRemoveCalledForNonFastThreadLocalGet() throws Exception { testOnRemoveCalled(false, true); } - @Test(timeout = 4000) + @Test + @Timeout(value = 4000, unit = TimeUnit.MILLISECONDS) public void testOnRemoveCalledForFastThreadLocalSet() throws Exception { testOnRemoveCalled(true, false); } - @Ignore("onRemoval(...) not called with non FastThreadLocal") - @Test(timeout = 4000) + @Disabled("onRemoval(...) not called with non FastThreadLocal") + @Test + @Timeout(value = 4000, unit = TimeUnit.MILLISECONDS) public void testOnRemoveCalledForNonFastThreadLocalSet() throws Exception { testOnRemoveCalled(false, false); } diff --git a/common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java b/common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java index 18638b5790..19e63d2959 100644 --- a/common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java +++ b/common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java @@ -16,8 +16,9 @@ package io.netty.util.concurrent; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -28,13 +29,13 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class GlobalEventExecutorTest { private static final GlobalEventExecutor e = GlobalEventExecutor.INSTANCE; - @Before + @BeforeEach public void setUp() throws Exception { // Wait until the global executor is stopped (just in case there is a task running due to previous test cases) for (;;) { @@ -46,7 +47,8 @@ public class GlobalEventExecutorTest { } } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testAutomaticStartStop() throws Exception { final TestRunnable task = new TestRunnable(500); e.execute(task); @@ -70,7 +72,8 @@ public class GlobalEventExecutorTest { assertThat(task.ran.get(), is(true)); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testScheduledTasks() throws Exception { TestRunnable task = new TestRunnable(0); ScheduledFuture f = e.schedule(task, 1500, TimeUnit.MILLISECONDS); @@ -87,7 +90,8 @@ public class GlobalEventExecutorTest { // ensure that when a task submission causes a new thread to be created, the thread inherits the thread group of the // submitting thread - @Test(timeout = 2000) + @Test + @Timeout(value = 2000, unit = TimeUnit.MILLISECONDS) public void testThreadGroup() throws InterruptedException { final ThreadGroup group = new ThreadGroup("group"); final AtomicReference capturedGroup = new AtomicReference(); @@ -108,7 +112,8 @@ public class GlobalEventExecutorTest { assertEquals(group, capturedGroup.get()); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testTakeTask() throws Exception { //add task TestRunnable beforeTask = new TestRunnable(0); @@ -129,7 +134,8 @@ public class GlobalEventExecutorTest { assertThat(afterTask.ran.get(), is(true)); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testTakeTaskAlwaysHasTask() throws Exception { //for https://github.com/netty/netty/issues/1614 //add scheduled task diff --git a/common/src/test/java/io/netty/util/concurrent/ImmediateExecutorTest.java b/common/src/test/java/io/netty/util/concurrent/ImmediateExecutorTest.java index 31ebee3c49..8b9eb307fd 100644 --- a/common/src/test/java/io/netty/util/concurrent/ImmediateExecutorTest.java +++ b/common/src/test/java/io/netty/util/concurrent/ImmediateExecutorTest.java @@ -16,19 +16,26 @@ package io.netty.util.concurrent; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +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; import java.util.concurrent.FutureTask; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; public class ImmediateExecutorTest { - @Test(expected = NullPointerException.class) + @Test public void testExecuteNullRunnable() { - ImmediateExecutor.INSTANCE.execute(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + ImmediateExecutor.INSTANCE.execute(null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/concurrent/NonStickyEventExecutorGroupTest.java b/common/src/test/java/io/netty/util/concurrent/NonStickyEventExecutorGroupTest.java index 7e54192e23..4654b28ec5 100644 --- a/common/src/test/java/io/netty/util/concurrent/NonStickyEventExecutorGroupTest.java +++ b/common/src/test/java/io/netty/util/concurrent/NonStickyEventExecutorGroupTest.java @@ -16,10 +16,11 @@ package io.netty.util.concurrent; import io.netty.util.NettyRuntime; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; import java.util.Collection; @@ -29,22 +30,27 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -@RunWith(Parameterized.class) +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class NonStickyEventExecutorGroupTest { + private static final String PARAMETERIZED_NAME = "{index}: maxTaskExecutePerRun = {0}"; - private final int maxTaskExecutePerRun; - - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidGroup() { - EventExecutorGroup group = new DefaultEventExecutorGroup(1); + final EventExecutorGroup group = new DefaultEventExecutorGroup(1); try { - new NonStickyEventExecutorGroup(group); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + new NonStickyEventExecutorGroup(group); + } + }); } finally { group.shutdownGracefully(); } } - @Parameterized.Parameters(name = "{index}: maxTaskExecutePerRun = {0}") public static Collection data() throws Exception { List params = new ArrayList(); params.add(new Object[] {64}); @@ -54,12 +60,10 @@ public class NonStickyEventExecutorGroupTest { return params; } - public NonStickyEventExecutorGroupTest(int maxTaskExecutePerRun) { - this.maxTaskExecutePerRun = maxTaskExecutePerRun; - } - - @Test(timeout = 10000) - public void testOrdering() throws Throwable { + @ParameterizedTest(name = PARAMETERIZED_NAME) + @MethodSource("data") + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) + public void testOrdering(int maxTaskExecutePerRun) throws Throwable { final int threads = NettyRuntime.availableProcessors() * 2; final EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(threads); final NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun); @@ -94,8 +98,9 @@ public class NonStickyEventExecutorGroupTest { } } - @Test - public void testRaceCondition() throws InterruptedException { + @ParameterizedTest(name = PARAMETERIZED_NAME) + @MethodSource("data") + public void testRaceCondition(int maxTaskExecutePerRun) throws InterruptedException { EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(1); NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun); @@ -113,10 +118,10 @@ public class NonStickyEventExecutorGroupTest { latch.countDown(); } }); - Assert.assertTrue(firstCompleted.await(1, TimeUnit.SECONDS)); + assertTrue(firstCompleted.await(1, TimeUnit.SECONDS)); } - Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + assertTrue(latch.await(5, TimeUnit.SECONDS)); } } finally { nonStickyGroup.shutdownGracefully(); @@ -125,7 +130,7 @@ public class NonStickyEventExecutorGroupTest { private static void execute(EventExecutorGroup group, CountDownLatch startLatch) throws Throwable { EventExecutor executor = group.next(); - Assert.assertTrue(executor instanceof OrderedEventExecutor); + assertTrue(executor instanceof OrderedEventExecutor); final AtomicReference cause = new AtomicReference(); final AtomicInteger last = new AtomicInteger(); int tasks = 10000; diff --git a/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java b/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java index d7c0dabbe0..532d9c2560 100644 --- a/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java +++ b/common/src/test/java/io/netty/util/concurrent/PromiseAggregatorTest.java @@ -16,39 +16,47 @@ package io.netty.util.concurrent; +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.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - public class PromiseAggregatorTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Test public void testNullAggregatePromise() { - expectedException.expect(NullPointerException.class); - new PromiseAggregator>(null); + assertThrows(NullPointerException.class, new Executable() { + @SuppressWarnings("deprecation") + @Override + public void execute() { + new PromiseAggregator>(null); + } + }); } @Test public void testAddNullFuture() { @SuppressWarnings("unchecked") Promise p = mock(Promise.class); - PromiseAggregator> a = + @SuppressWarnings("deprecation") + final PromiseAggregator> a = new PromiseAggregator>(p); - expectedException.expect(NullPointerException.class); - a.add((Promise[]) null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + a.add((Promise[]) null); + } + }); } @SuppressWarnings("unchecked") @Test public void testSuccessfulNoPending() throws Exception { Promise p = mock(Promise.class); + @SuppressWarnings("deprecation") PromiseAggregator> a = new PromiseAggregator>(p); diff --git a/common/src/test/java/io/netty/util/concurrent/PromiseCombinerTest.java b/common/src/test/java/io/netty/util/concurrent/PromiseCombinerTest.java index 360c3ee466..eb86af4a5c 100644 --- a/common/src/test/java/io/netty/util/concurrent/PromiseCombinerTest.java +++ b/common/src/test/java/io/netty/util/concurrent/PromiseCombinerTest.java @@ -15,14 +15,16 @@ */ package io.netty.util.concurrent; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.doAnswer; @@ -54,7 +56,7 @@ public class PromiseCombinerTest { private Promise p3; private PromiseCombiner combiner; - @Before + @BeforeEach public void setup() { MockitoAnnotations.initMocks(this); combiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE); @@ -64,7 +66,7 @@ public class PromiseCombinerTest { public void testNullArgument() { try { combiner.finish(null); - Assert.fail(); + fail(); } catch (NullPointerException expected) { // expected } @@ -78,34 +80,59 @@ public class PromiseCombinerTest { verify(p1).trySuccess(null); } - @Test(expected = NullPointerException.class) + @Test public void testAddNullPromise() { - combiner.add(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + combiner.add(null); + } + }); } - @Test(expected = NullPointerException.class) + @Test public void testAddAllNullPromise() { - combiner.addAll(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + combiner.addAll(null); + } + }); } - @Test(expected = IllegalStateException.class) + @Test public void testAddAfterFinish() { combiner.finish(p1); - combiner.add(p2); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + combiner.add(p2); + } + }); } @SuppressWarnings("unchecked") - @Test(expected = IllegalStateException.class) + @Test public void testAddAllAfterFinish() { combiner.finish(p1); - combiner.addAll(p2); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + combiner.addAll(p2); + } + }); } @SuppressWarnings("unchecked") - @Test(expected = IllegalStateException.class) + @Test public void testFinishCalledTwiceThrows() { combiner.finish(p1); - combiner.finish(p1); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + combiner.finish(p1); + } + }); } @Test @@ -172,14 +199,14 @@ public class PromiseCombinerTest { try { combiner.add(future); - Assert.fail(); + fail(); } catch (IllegalStateException expected) { // expected } try { combiner.addAll(future); - Assert.fail(); + fail(); } catch (IllegalStateException expected) { // expected } @@ -188,7 +215,7 @@ public class PromiseCombinerTest { Promise promise = (Promise) mock(Promise.class); try { combiner.finish(promise); - Assert.fail(); + fail(); } catch (IllegalStateException expected) { // expected } diff --git a/common/src/test/java/io/netty/util/concurrent/PromiseNotifierTest.java b/common/src/test/java/io/netty/util/concurrent/PromiseNotifierTest.java index d800bb4eb3..14b5ec9aff 100644 --- a/common/src/test/java/io/netty/util/concurrent/PromiseNotifierTest.java +++ b/common/src/test/java/io/netty/util/concurrent/PromiseNotifierTest.java @@ -16,28 +16,33 @@ package io.netty.util.concurrent; -import static org.mockito.Mockito.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.*; public class PromiseNotifierTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Test public void testNullPromisesArray() { - expectedException.expect(NullPointerException.class); - new PromiseNotifier>((Promise[]) null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + new PromiseNotifier>((Promise[]) null); + } + }); } @SuppressWarnings("unchecked") @Test public void testNullPromiseInArray() { - expectedException.expect(IllegalArgumentException.class); - new PromiseNotifier>((Promise) null); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + new PromiseNotifier>((Promise) null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java b/common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java index 6c7f274aa4..46ddda8966 100644 --- a/common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java +++ b/common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java @@ -15,13 +15,17 @@ */ package io.netty.util.concurrent; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class UnorderedThreadPoolEventExecutorTest { // See https://github.com/netty/netty/issues/6507 @@ -50,14 +54,15 @@ public class UnorderedThreadPoolEventExecutorTest { // Now just check if the queue stays empty multiple times. This is needed as the submit to execute(...) // by DefaultPromise may happen in an async fashion for (int i = 0; i < 10000; i++) { - Assert.assertTrue(executor.getQueue().isEmpty()); + assertTrue(executor.getQueue().isEmpty()); } } finally { executor.shutdownGracefully(); } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void scheduledAtFixedRateMustRunTaskRepeatedly() throws InterruptedException { UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1); final CountDownLatch latch = new CountDownLatch(3); @@ -87,7 +92,7 @@ public class UnorderedThreadPoolEventExecutorTest { } }); - Assert.assertEquals(expected, f.get()); + assertEquals(expected, f.get()); } finally { executor.shutdownGracefully(); } @@ -105,7 +110,7 @@ public class UnorderedThreadPoolEventExecutorTest { } }); - Assert.assertSame(cause, f.await().cause()); + assertSame(cause, f.await().cause()); } finally { executor.shutdownGracefully(); } diff --git a/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java b/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java index 4b5cf60311..b735a8a8ec 100644 --- a/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java +++ b/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java @@ -15,10 +15,9 @@ */ package io.netty.util.internal; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class AppendableCharSequenceTest { diff --git a/common/src/test/java/io/netty/util/internal/DefaultPriorityQueueTest.java b/common/src/test/java/io/netty/util/internal/DefaultPriorityQueueTest.java index 9b9821ae77..132e4710c0 100644 --- a/common/src/test/java/io/netty/util/internal/DefaultPriorityQueueTest.java +++ b/common/src/test/java/io/netty/util/internal/DefaultPriorityQueueTest.java @@ -15,7 +15,7 @@ */ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.Serializable; import java.util.ArrayList; @@ -25,12 +25,12 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class DefaultPriorityQueueTest { @Test diff --git a/common/src/test/java/io/netty/util/internal/MacAddressUtilTest.java b/common/src/test/java/io/netty/util/internal/MacAddressUtilTest.java index 11442ebeb1..f7a25414ca 100644 --- a/common/src/test/java/io/netty/util/internal/MacAddressUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/MacAddressUtilTest.java @@ -15,12 +15,14 @@ */ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES; import static io.netty.util.internal.MacAddressUtil.parseMAC; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MacAddressUtilTest { @Test @@ -94,53 +96,103 @@ public class MacAddressUtilTest { parseMAC("00:AA:11:FF:FE:BB:22:CC")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalid7HexGroupsA() { - parseMAC("00-AA-11-BB-22-CC-FF"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00-AA-11-BB-22-CC-FF"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalid7HexGroupsB() { - parseMAC("00:AA:11:BB:22:CC:FF"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00:AA:11:BB:22:CC:FF"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI48MixedSeparatorA() { - parseMAC("00-AA:11-BB-22-CC"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00-AA:11-BB-22-CC"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI48MixedSeparatorB() { - parseMAC("00:AA-11:BB:22:CC"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00:AA-11:BB:22:CC"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI64MixedSeparatorA() { - parseMAC("00-AA-11-FF-FE-BB-22:CC"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00-AA-11-FF-FE-BB-22:CC"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI64MixedSeparatorB() { - parseMAC("00:AA:11:FF:FE:BB:22-CC"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00:AA:11:FF:FE:BB:22-CC"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI48TrailingSeparatorA() { - parseMAC("00-AA-11-BB-22-CC-"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00-AA-11-BB-22-CC-"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI48TrailingSeparatorB() { - parseMAC("00:AA:11:BB:22:CC:"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00:AA:11:BB:22:CC:"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI64TrailingSeparatorA() { - parseMAC("00-AA-11-FF-FE-BB-22-CC-"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00-AA-11-FF-FE-BB-22-CC-"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMacInvalidEUI64TrailingSeparatorB() { - parseMAC("00:AA:11:FF:FE:BB:22:CC:"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + parseMAC("00:AA:11:FF:FE:BB:22:CC:"); + } + }); } } diff --git a/common/src/test/java/io/netty/util/internal/MathUtilTest.java b/common/src/test/java/io/netty/util/internal/MathUtilTest.java index 2fd44ced4b..9b6370dee2 100644 --- a/common/src/test/java/io/netty/util/internal/MathUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/MathUtilTest.java @@ -15,12 +15,12 @@ */ package io.netty.util.internal; -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; import static io.netty.util.internal.MathUtil.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MathUtilTest { diff --git a/common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java b/common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java index 98aca0f825..2f6491a7fd 100644 --- a/common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java +++ b/common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java @@ -16,7 +16,7 @@ package io.netty.util.internal; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -26,10 +26,10 @@ import java.io.InputStream; import java.util.Arrays; import java.util.UUID; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class NativeLibraryLoaderTest { diff --git a/common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java b/common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java index cfa32ed13a..4c56230c67 100644 --- a/common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java +++ b/common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java @@ -15,23 +15,26 @@ */ package io.netty.util.internal; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ObjectCleanerTest { private Thread temporaryThread; private Object temporaryObject; - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testCleanup() throws Exception { final AtomicBoolean freeCalled = new AtomicBoolean(); final CountDownLatch latch = new CountDownLatch(1); @@ -55,7 +58,7 @@ public class ObjectCleanerTest { latch.countDown(); temporaryThread.join(); - Assert.assertFalse(freeCalled.get()); + assertFalse(freeCalled.get()); // Null out the temporary object to ensure it is enqueued for GC. temporaryThread = null; @@ -67,7 +70,8 @@ public class ObjectCleanerTest { } } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testCleanupContinuesDespiteThrowing() throws InterruptedException { final AtomicInteger freeCalledCount = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); @@ -113,7 +117,8 @@ public class ObjectCleanerTest { } } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testCleanerThreadIsDaemon() throws Exception { temporaryObject = new Object(); ObjectCleaner.register(temporaryObject, new Runnable() { diff --git a/common/src/test/java/io/netty/util/internal/ObjectUtilTest.java b/common/src/test/java/io/netty/util/internal/ObjectUtilTest.java index 61b797e50d..8e0dd226f3 100644 --- a/common/src/test/java/io/netty/util/internal/ObjectUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/ObjectUtilTest.java @@ -14,10 +14,11 @@ */ package io.netty.util.internal; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Testcases for io.netty.util.internal.ObjectUtil. @@ -78,7 +79,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -86,8 +87,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -98,7 +99,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -106,8 +107,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -118,7 +119,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -126,8 +127,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -138,7 +139,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -146,8 +147,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -155,8 +156,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -167,7 +168,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -175,8 +176,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -184,8 +185,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -196,7 +197,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -204,8 +205,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -213,8 +214,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -225,7 +226,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -233,8 +234,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -242,8 +243,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -254,7 +255,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -262,7 +263,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -270,8 +271,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -282,7 +283,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -290,7 +291,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -298,8 +299,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -310,7 +311,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -318,7 +319,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -326,8 +327,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -338,7 +339,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -346,7 +347,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -354,8 +355,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -367,8 +368,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -376,7 +377,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -384,8 +385,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -397,8 +398,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -406,7 +407,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -414,8 +415,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -427,8 +428,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -436,7 +437,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -444,8 +445,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -456,8 +457,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -465,7 +466,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -473,8 +474,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } @Test @@ -486,8 +487,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -495,7 +496,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -503,8 +504,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -512,7 +513,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); } @Test @@ -524,8 +525,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -533,7 +534,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -541,8 +542,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -550,7 +551,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); } @Test @@ -562,8 +563,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -571,7 +572,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNull(TEST_RESULT_NULLEX_NOK, actualEx); + assertNull(actualEx, TEST_RESULT_NULLEX_NOK); actualEx = null; try { @@ -579,8 +580,8 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); actualEx = null; try { @@ -588,7 +589,7 @@ public class ObjectUtilTest { } catch (Exception e) { actualEx = e; } - assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); - assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); + assertNotNull(actualEx, TEST_RESULT_NULLEX_OK); + assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK); } } diff --git a/common/src/test/java/io/netty/util/internal/PlatformDependent0Test.java b/common/src/test/java/io/netty/util/internal/PlatformDependent0Test.java index 42a6ad5d4c..8899fa045f 100644 --- a/common/src/test/java/io/netty/util/internal/PlatformDependent0Test.java +++ b/common/src/test/java/io/netty/util/internal/PlatformDependent0Test.java @@ -15,18 +15,18 @@ */ package io.netty.util.internal; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.security.Permission; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class PlatformDependent0Test { - @BeforeClass + @BeforeAll public static void assumeUnsafe() { assumeTrue(PlatformDependent0.hasUnsafe()); assumeTrue(PlatformDependent0.hasDirectBufferNoCleanerConstructor()); diff --git a/common/src/test/java/io/netty/util/internal/PlatformDependentTest.java b/common/src/test/java/io/netty/util/internal/PlatformDependentTest.java index f223e962ff..d29a985689 100644 --- a/common/src/test/java/io/netty/util/internal/PlatformDependentTest.java +++ b/common/src/test/java/io/netty/util/internal/PlatformDependentTest.java @@ -15,15 +15,19 @@ */ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.util.Random; import static io.netty.util.internal.PlatformDependent.hashCodeAscii; import static io.netty.util.internal.PlatformDependent.hashCodeAsciiSafe; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; +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.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class PlatformDependentTest { private static final Random r = new Random(); @@ -137,12 +141,12 @@ public class PlatformDependentTest { bytes[j] = (byte) (bytesChar[j] & 0xff); } String string = new String(bytesChar); - assertEquals("length=" + i, - hashCodeAsciiSafe(bytes, 0, bytes.length), - hashCodeAscii(bytes, 0, bytes.length)); - assertEquals("length=" + i, - hashCodeAscii(bytes, 0, bytes.length), - hashCodeAscii(string)); + assertEquals(hashCodeAsciiSafe(bytes, 0, bytes.length), + hashCodeAscii(bytes, 0, bytes.length), + "length=" + i); + assertEquals(hashCodeAscii(bytes, 0, bytes.length), + hashCodeAscii(string), + "length=" + i); } } diff --git a/common/src/test/java/io/netty/util/internal/StringUtilTest.java b/common/src/test/java/io/netty/util/internal/StringUtilTest.java index 93988626cb..65d9128346 100644 --- a/common/src/test/java/io/netty/util/internal/StringUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/StringUtilTest.java @@ -15,7 +15,8 @@ */ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.Arrays; import java.util.Collections; @@ -33,12 +34,13 @@ import static io.netty.util.internal.StringUtil.unescapeCsv; import static io.netty.util.internal.StringUtil.unescapeCsvFields; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class StringUtilTest { @@ -160,9 +162,14 @@ public class StringUtilTest { return sp; } - @Test (expected = NullPointerException.class) + @Test public void escapeCsvNull() { - StringUtil.escapeCsv(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + StringUtil.escapeCsv(null); + } + }); } @Test @@ -407,29 +414,54 @@ public class StringUtilTest { assertEquals("hello,netty", unescapeCsv("\"hello,netty\"")); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvWithSingleQuote() { - unescapeCsv("\""); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsv("\""); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvWithOddQuote() { - unescapeCsv("\"\"\""); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsv("\"\"\""); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvWithCRAndWithoutQuote() { - unescapeCsv("\r"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsv("\r"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvWithLFAndWithoutQuote() { - unescapeCsv("\n"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsv("\n"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvWithCommaAndWithoutQuote() { - unescapeCsv(","); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsv(","); + } + }); } @Test @@ -464,29 +496,54 @@ public class StringUtilTest { assertEquals(Arrays.asList("a\rb", "c\nd"), unescapeCsvFields("\"a\rb\",\"c\nd\"")); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvFieldsWithCRWithoutQuote() { - unescapeCsvFields("a,\r"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsvFields("a,\r"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvFieldsWithLFWithoutQuote() { - unescapeCsvFields("a,\r"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsvFields("a,\r"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvFieldsWithQuote() { - unescapeCsvFields("a,\""); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsvFields("a,\""); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvFieldsWithQuote2() { - unescapeCsvFields("\",a"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsvFields("\",a"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void unescapeCsvFieldsWithQuote3() { - unescapeCsvFields("a\"b,a"); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + unescapeCsvFields("a\"b,a"); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/internal/SystemPropertyUtilTest.java b/common/src/test/java/io/netty/util/internal/SystemPropertyUtilTest.java index cbd3aa9963..1c2df10bdf 100644 --- a/common/src/test/java/io/netty/util/internal/SystemPropertyUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/SystemPropertyUtilTest.java @@ -15,28 +15,40 @@ */ package io.netty.util.internal; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SystemPropertyUtilTest { - @Before + @BeforeEach public void clearSystemPropertyBeforeEach() { System.clearProperty("key"); } - @Test(expected = NullPointerException.class) + @Test public void testGetWithKeyNull() { - SystemPropertyUtil.get(null, null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + SystemPropertyUtil.get(null, null); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetWithKeyEmpty() { - SystemPropertyUtil.get("", null); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() { + SystemPropertyUtil.get("", null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/internal/ThreadExecutorMapTest.java b/common/src/test/java/io/netty/util/internal/ThreadExecutorMapTest.java index 41ce6f2fd8..6b1ff009d9 100644 --- a/common/src/test/java/io/netty/util/internal/ThreadExecutorMapTest.java +++ b/common/src/test/java/io/netty/util/internal/ThreadExecutorMapTest.java @@ -17,13 +17,14 @@ package io.netty.util.internal; import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateExecutor; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; +import static org.junit.jupiter.api.Assertions.assertSame; + public class ThreadExecutorMapTest { @Test @@ -32,7 +33,7 @@ public class ThreadExecutorMapTest { executor.execute(new Runnable() { @Override public void run() { - Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); + assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); } }); } @@ -42,7 +43,8 @@ public class ThreadExecutorMapTest { ThreadExecutorMap.apply(new Runnable() { @Override public void run() { - Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); + assertSame(ImmediateEventExecutor.INSTANCE, + ThreadExecutorMap.currentExecutor()); } }, ImmediateEventExecutor.INSTANCE).run(); } @@ -54,7 +56,7 @@ public class ThreadExecutorMapTest { Thread thread = threadFactory.newThread(new Runnable() { @Override public void run() { - Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); + assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); } }); thread.start(); diff --git a/common/src/test/java/io/netty/util/internal/ThreadLocalRandomTest.java b/common/src/test/java/io/netty/util/internal/ThreadLocalRandomTest.java index 1dfde6bef0..33259fbaf5 100644 --- a/common/src/test/java/io/netty/util/internal/ThreadLocalRandomTest.java +++ b/common/src/test/java/io/netty/util/internal/ThreadLocalRandomTest.java @@ -15,9 +15,9 @@ */ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ThreadLocalRandomTest { @@ -25,11 +25,11 @@ public class ThreadLocalRandomTest { public void getInitialSeedUniquifierPreservesInterrupt() { try { Thread.currentThread().interrupt(); - assertTrue("Assert that thread is interrupted before invocation of getInitialSeedUniquifier()", - Thread.currentThread().isInterrupted()); + assertTrue(Thread.currentThread().isInterrupted(), + "Assert that thread is interrupted before invocation of getInitialSeedUniquifier()"); ThreadLocalRandom.getInitialSeedUniquifier(); - assertTrue("Assert that thread is interrupted after invocation of getInitialSeedUniquifier()", - Thread.currentThread().isInterrupted()); + assertTrue(Thread.currentThread().isInterrupted(), + "Assert that thread is interrupted after invocation of getInitialSeedUniquifier()"); } finally { Thread.interrupted(); // clear interrupted status in order to not affect other tests } diff --git a/common/src/test/java/io/netty/util/internal/TypeParameterMatcherTest.java b/common/src/test/java/io/netty/util/internal/TypeParameterMatcherTest.java index 093ed6150a..1b6e0179c6 100644 --- a/common/src/test/java/io/netty/util/internal/TypeParameterMatcherTest.java +++ b/common/src/test/java/io/netty/util/internal/TypeParameterMatcherTest.java @@ -16,11 +16,14 @@ package io.netty.util.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.util.Date; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TypeParameterMatcherTest { @@ -38,9 +41,14 @@ public class TypeParameterMatcherTest { assertFalse(m.match(new CC())); } - @Test(expected = IllegalStateException.class) + @Test public void testUnsolvedParameter() throws Exception { - TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B"); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B"); + } + }); } @Test @@ -135,10 +143,15 @@ public class TypeParameterMatcherTest { T t; } - @Test(expected = IllegalStateException.class) + @Test public void testErasure() throws Exception { - TypeParameterMatcher m = TypeParameterMatcher.find(new X(), W.class, "E"); - assertTrue(m.match(new Date())); - assertFalse(m.match(new Object())); + assertThrows(IllegalStateException.class, new Executable() { + @Override + public void execute() { + TypeParameterMatcher m = TypeParameterMatcher.find(new X(), W.class, "E"); + assertTrue(m.match(new Date())); + assertFalse(m.match(new Object())); + } + }); } } diff --git a/common/src/test/java/io/netty/util/internal/logging/AbstractInternalLoggerTest.java b/common/src/test/java/io/netty/util/internal/logging/AbstractInternalLoggerTest.java index 3114519317..4b51d88038 100644 --- a/common/src/test/java/io/netty/util/internal/logging/AbstractInternalLoggerTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/AbstractInternalLoggerTest.java @@ -15,15 +15,15 @@ */ package io.netty.util.internal.logging; -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; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * We only need to test methods defined by {@link InternaLogger}. diff --git a/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerFactoryTest.java index 59450381a9..d7a8f6212b 100644 --- a/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerFactoryTest.java @@ -15,9 +15,10 @@ */ package io.netty.util.internal.logging; -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.assertTrue; public class CommonsLoggerFactoryTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerTest.java b/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerTest.java index 85219d3821..ff0027f33c 100644 --- a/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/CommonsLoggerTest.java @@ -16,9 +16,9 @@ package io.netty.util.internal.logging; import org.apache.commons.logging.Log; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; public class CommonsLoggerTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/InternalLoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/InternalLoggerFactoryTest.java index b813a81aa6..69dc5948d9 100644 --- a/common/src/test/java/io/netty/util/internal/logging/InternalLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/InternalLoggerFactoryTest.java @@ -15,13 +15,15 @@ */ package io.netty.util.internal.logging; -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.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; public class InternalLoggerFactoryTest { @@ -29,7 +31,7 @@ public class InternalLoggerFactoryTest { private InternalLoggerFactory oldLoggerFactory; private InternalLogger mockLogger; - @Before + @BeforeEach public void init() { oldLoggerFactory = InternalLoggerFactory.getDefaultFactory(); @@ -39,15 +41,20 @@ public class InternalLoggerFactoryTest { InternalLoggerFactory.setDefaultFactory(mockFactory); } - @After + @AfterEach public void destroy() { reset(mockLogger); InternalLoggerFactory.setDefaultFactory(oldLoggerFactory); } - @Test(expected = NullPointerException.class) + @Test public void shouldNotAllowNullDefaultFactory() { - InternalLoggerFactory.setDefaultFactory(null); + assertThrows(NullPointerException.class, new Executable() { + @Override + public void execute() { + InternalLoggerFactory.setDefaultFactory(null); + } + }); } @Test diff --git a/common/src/test/java/io/netty/util/internal/logging/JdkLoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/JdkLoggerFactoryTest.java index 05464b6d67..96278d213e 100644 --- a/common/src/test/java/io/netty/util/internal/logging/JdkLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/JdkLoggerFactoryTest.java @@ -15,9 +15,10 @@ */ package io.netty.util.internal.logging; -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.assertTrue; public class JdkLoggerFactoryTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerFactoryTest.java index 6cd815ef11..118f2a5f48 100644 --- a/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerFactoryTest.java @@ -15,10 +15,10 @@ */ package io.netty.util.internal.logging; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Log4J2LoggerFactoryTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerTest.java b/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerTest.java index 303b74e3ef..879f87cd3f 100644 --- a/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/Log4J2LoggerTest.java @@ -15,7 +15,7 @@ */ package io.netty.util.internal.logging; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Method; import java.util.Arrays; @@ -26,10 +26,9 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.spi.ExtendedLoggerWrapper; -import org.hamcrest.CoreMatchers; -import org.junit.Assume; import io.netty.util.internal.ReflectionUtil; +import org.junit.jupiter.api.Assumptions; /** * {@linkplain Log4J2Logger} extends {@linkplain ExtendedLoggerWrapper} implements {@linkplain InternalLogger}.
@@ -66,7 +65,7 @@ public class Log4J2LoggerTest extends AbstractInternalLoggerTest { Method method = mockLog.getClass().getDeclaredMethod("setLevel", Level.class); if (!method.isAccessible()) { - Assume.assumeThat(ReflectionUtil.trySetAccessible(method, true), CoreMatchers.nullValue()); + Assumptions.assumeTrue(ReflectionUtil.trySetAccessible(method, true) == null); } method.invoke(mockLog, targetLevel); } diff --git a/common/src/test/java/io/netty/util/internal/logging/Log4JLoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/Log4JLoggerFactoryTest.java index 0a50a0430c..00db0b0cdd 100644 --- a/common/src/test/java/io/netty/util/internal/logging/Log4JLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/Log4JLoggerFactoryTest.java @@ -15,9 +15,10 @@ */ package io.netty.util.internal.logging; -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.assertTrue; public class Log4JLoggerFactoryTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/MessageFormatterTest.java b/common/src/test/java/io/netty/util/internal/logging/MessageFormatterTest.java index 8ee5e33524..60a44fcf39 100644 --- a/common/src/test/java/io/netty/util/internal/logging/MessageFormatterTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/MessageFormatterTest.java @@ -38,9 +38,10 @@ */ package io.netty.util.internal.logging; -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 MessageFormatterTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java b/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java index 125e87936a..6ec9256326 100644 --- a/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java @@ -15,7 +15,7 @@ */ package io.netty.util.internal.logging; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.slf4j.Logger; @@ -24,9 +24,9 @@ import org.slf4j.spi.LocationAwareLogger; import java.util.Iterator; -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; import static org.mockito.Mockito.*; public class Slf4JLoggerFactoryTest { diff --git a/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerTest.java b/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerTest.java index ac395213a0..259868d3cb 100644 --- a/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerTest.java +++ b/common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerTest.java @@ -15,10 +15,10 @@ */ package io.netty.util.internal.logging; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; public class Slf4JLoggerTest {