Migrate common tests to JUnit 5 (#11319)

Motivation:

JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel.

Modifications:

Use JUnit5 in tests

Result:

Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
Riley Park 2021-05-26 23:31:53 -07:00 committed by GitHub
parent 7a1e0b46b6
commit e0b9eeb324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 652 additions and 561 deletions

View File

@ -15,7 +15,8 @@
*/ */
package io.netty.util; 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.ArrayDeque;
import java.util.Queue; import java.util.Queue;
@ -24,35 +25,37 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class AbstractReferenceCountedTest { public class AbstractReferenceCountedTest {
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainOverflow() { public void testRetainOverflow() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); AbstractReferenceCounted referenceCounted = newReferenceCounted();
referenceCounted.setRefCnt(Integer.MAX_VALUE); referenceCounted.setRefCnt(Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, referenceCounted.refCnt()); assertEquals(Integer.MAX_VALUE, referenceCounted.refCnt());
referenceCounted.retain(); assertThrows(IllegalReferenceCountException.class, referenceCounted::retain);
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainOverflow2() { public void testRetainOverflow2() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertEquals(1, referenceCounted.refCnt()); assertEquals(1, referenceCounted.refCnt());
referenceCounted.retain(Integer.MAX_VALUE); assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.retain(Integer.MAX_VALUE));
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testReleaseOverflow() { public void testReleaseOverflow() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); AbstractReferenceCounted referenceCounted = newReferenceCounted();
referenceCounted.setRefCnt(0); referenceCounted.setRefCnt(0);
assertEquals(0, referenceCounted.refCnt()); assertEquals(0, referenceCounted.refCnt());
referenceCounted.release(Integer.MAX_VALUE); assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.release(Integer.MAX_VALUE));
} }
@Test @Test
@ -67,23 +70,24 @@ public class AbstractReferenceCountedTest {
} }
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainResurrect() { public void testRetainResurrect() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertTrue(referenceCounted.release()); assertTrue(referenceCounted.release());
assertEquals(0, referenceCounted.refCnt()); assertEquals(0, referenceCounted.refCnt());
referenceCounted.retain(); assertThrows(IllegalReferenceCountException.class, referenceCounted::retain);
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainResurrect2() { public void testRetainResurrect2() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertTrue(referenceCounted.release()); assertTrue(referenceCounted.release());
assertEquals(0, referenceCounted.refCnt()); assertEquals(0, referenceCounted.refCnt());
referenceCounted.retain(2); assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.retain(2));
} }
@Test(timeout = 30000) @Test
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception { public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception {
int threads = 4; int threads = 4;
Queue<Future<?>> futures = new ArrayDeque<>(threads); Queue<Future<?>> futures = new ArrayDeque<>(threads);
@ -128,7 +132,8 @@ public class AbstractReferenceCountedTest {
} }
} }
@Test(timeout = 30000) @Test
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testReleaseFromMultipleThreadsThrowsReferenceCountException() throws Exception { public void testReleaseFromMultipleThreadsThrowsReferenceCountException() throws Exception {
int threads = 4; int threads = 4;
Queue<Future<?>> futures = new ArrayDeque<>(threads); Queue<Future<?>> futures = new ArrayDeque<>(threads);

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -31,11 +31,11 @@ import static io.netty.util.CharsetUtil.UTF_16LE;
import static io.netty.util.CharsetUtil.UTF_8; import static io.netty.util.CharsetUtil.UTF_8;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Test character encoding and case insensitivity for the {@link AsciiString} class * Test character encoding and case insensitivity for the {@link AsciiString} class
@ -65,7 +65,7 @@ public class AsciiStringCharacterTest {
for (final Charset charset : CHARSETS) { for (final Charset charset : CHARSETS) {
byte[] expected = bString.getBytes(charset); byte[] expected = bString.getBytes(charset);
byte[] actual = new AsciiString(b, charset).toByteArray(); byte[] actual = new AsciiString(b, charset).toByteArray();
assertArrayEquals("failure for " + charset, expected, actual); assertArrayEquals(expected, actual, "failure for " + charset);
} }
} }
@ -79,7 +79,7 @@ public class AsciiStringCharacterTest {
for (final Charset charset : CHARSETS) { for (final Charset charset : CHARSETS) {
byte[] expected = bString.getBytes(charset); byte[] expected = bString.getBytes(charset);
byte[] actual = new AsciiString(bString, charset).toByteArray(); byte[] actual = new AsciiString(bString, charset).toByteArray();
assertArrayEquals("failure for " + charset, expected, actual); assertArrayEquals(expected, actual, "failure for " + charset);
} }
} }
@ -202,29 +202,29 @@ public class AsciiStringCharacterTest {
final String errorString = "len: " + len; final String errorString = "len: " + len;
// Test upper case hash codes are equal // Test upper case hash codes are equal
final int upperCaseExpected = upperCaseAscii.hashCode(); final int upperCaseExpected = upperCaseAscii.hashCode();
assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseBuilder)); assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseBuilder), errorString);
assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseString)); assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseString), errorString);
assertEquals(errorString, upperCaseExpected, upperCaseAscii.hashCode()); assertEquals(upperCaseExpected, upperCaseAscii.hashCode(), errorString);
// Test lower case hash codes are equal // Test lower case hash codes are equal
final int lowerCaseExpected = lowerCaseAscii.hashCode(); final int lowerCaseExpected = lowerCaseAscii.hashCode();
assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii)); assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii), errorString);
assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseString)); assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseString), errorString);
assertEquals(errorString, lowerCaseExpected, lowerCaseAscii.hashCode()); assertEquals(lowerCaseExpected, lowerCaseAscii.hashCode(), errorString);
// Test case insensitive hash codes are equal // Test case insensitive hash codes are equal
final int expectedCaseInsensitive = lowerCaseAscii.hashCode(); final int expectedCaseInsensitive = lowerCaseAscii.hashCode();
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder)); assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder), errorString);
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseString)); assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseString), errorString);
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString)); assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString), errorString);
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii)); assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii), errorString);
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii)); assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii), errorString);
assertEquals(errorString, expectedCaseInsensitive, lowerCaseAscii.hashCode()); assertEquals(expectedCaseInsensitive, lowerCaseAscii.hashCode(), errorString);
assertEquals(errorString, expectedCaseInsensitive, upperCaseAscii.hashCode()); assertEquals(expectedCaseInsensitive, upperCaseAscii.hashCode(), errorString);
// Test that opposite cases are equal // Test that opposite cases are equal
assertEquals(errorString, lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString)); assertEquals(lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString), errorString);
assertEquals(errorString, upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString)); assertEquals(upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString), errorString);
} }
@Test @Test

View File

@ -15,15 +15,15 @@
*/ */
package io.netty.util; package io.netty.util;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import io.netty.util.ByteProcessor.IndexOfProcessor; import io.netty.util.ByteProcessor.IndexOfProcessor;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Test the underlying memory methods for the {@link AsciiString} class. * Test the underlying memory methods for the {@link AsciiString} class.
@ -38,7 +38,7 @@ public class AsciiStringMemoryTest {
private AsciiString bAsciiString; private AsciiString bAsciiString;
private Random r = new Random(); private Random r = new Random();
@Before @BeforeEach
public void setup() { public void setup() {
a = new byte[128]; a = new byte[128];
b = new byte[256]; b = new byte[256];
@ -85,7 +85,7 @@ public class AsciiStringMemoryTest {
int i; int i;
@Override @Override
public boolean process(byte value) { public boolean process(byte value) {
assertEquals("failed at index: " + i, value, bAsciiString.byteAt(i++)); assertEquals(value, bAsciiString.byteAt(i++), "failed at index: " + i);
aCount.set(aCount.get() + 1); aCount.set(aCount.get() + 1);
return true; return true;
} }
@ -94,7 +94,7 @@ public class AsciiStringMemoryTest {
int i; int i;
@Override @Override
public boolean process(byte value) { public boolean process(byte value) {
assertEquals("failed at index: " + i, value, aAsciiString.byteAt(i++)); assertEquals(value, aAsciiString.byteAt(i++), "failed at index: " + i);
bCount.set(bCount.get() + 1); bCount.set(bCount.get() + 1);
return true; return true;
} }
@ -123,7 +123,7 @@ public class AsciiStringMemoryTest {
int i = 1; int i = 1;
@Override @Override
public boolean process(byte value) { public boolean process(byte value) {
assertEquals("failed at index: " + i, value, bAsciiString.byteAt(bAsciiString.length() - (i++))); assertEquals(value, bAsciiString.byteAt(bAsciiString.length() - (i++)), "failed at index: " + i);
aCount.set(aCount.get() + 1); aCount.set(aCount.get() + 1);
return true; return true;
} }
@ -132,7 +132,7 @@ public class AsciiStringMemoryTest {
int i = 1; int i = 1;
@Override @Override
public boolean process(byte value) { public boolean process(byte value) {
assertEquals("failed at index: " + i, value, aAsciiString.byteAt(aAsciiString.length() - (i++))); assertEquals(value, aAsciiString.byteAt(aAsciiString.length() - (i++)), "failed at index: " + i);
bCount.set(bCount.get() + 1); bCount.set(bCount.get() + 1);
return true; return true;
} }

View File

@ -15,9 +15,13 @@
*/ */
package io.netty.util; 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 { public class AttributeKeyTest {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -24,6 +24,7 @@ import java.util.TreeSet;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ConstantPoolTest { public class ConstantPoolTest {
@ -40,9 +41,9 @@ public class ConstantPoolTest {
} }
}; };
@Test(expected = NullPointerException.class) @Test
public void testCannotProvideNullName() { public void testCannotProvideNullName() {
pool.valueOf(null); assertThrows(NullPointerException.class, () -> pool.valueOf(null));
} }
@Test @Test

View File

@ -15,16 +15,22 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.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 { public class DefaultAttributeMapTest {
private DefaultAttributeMap map; private DefaultAttributeMap map;
@Before @BeforeEach
public void setup() { public void setup() {
map = new DefaultAttributeMap(); map = new DefaultAttributeMap();
} }

View File

@ -16,30 +16,31 @@
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Map; 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") @SuppressWarnings("deprecation")
public class DomainNameMappingTest { public class DomainNameMappingTest {
// Deprecated API // Deprecated API
@Test(expected = NullPointerException.class) @Test
public void testNullDefaultValueInDeprecatedApi() { public void testNullDefaultValueInDeprecatedApi() {
new DomainNameMapping<String>(null); assertThrows(NullPointerException.class, () -> new DomainNameMapping<String>(null));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() { public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() {
new DomainNameMapping<>("NotFound").add(null, "Some value"); assertThrows(NullPointerException.class, () -> new DomainNameMapping<>("NotFound").add(null, "Some value"));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullValuesAreForbiddenInDeprecatedApi() { public void testNullValuesAreForbiddenInDeprecatedApi() {
new DomainNameMapping<>("NotFound").add("Some key", null); assertThrows(NullPointerException.class, () -> new DomainNameMapping<>("NotFound").add("Some key", null));
} }
@Test @Test
@ -105,19 +106,21 @@ public class DomainNameMappingTest {
// Immutable DomainNameMapping Builder API // Immutable DomainNameMapping Builder API
@Test(expected = NullPointerException.class) @Test
public void testNullDefaultValue() { public void testNullDefaultValue() {
new DomainNameMappingBuilder<String>(null); assertThrows(NullPointerException.class, () -> new DomainNameMappingBuilder<String>(null));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullDomainNamePatternsAreForbidden() { public void testNullDomainNamePatternsAreForbidden() {
new DomainNameMappingBuilder<>("NotFound").add(null, "Some value"); assertThrows(NullPointerException.class,
() -> new DomainNameMappingBuilder<>("NotFound").add(null, "Some value"));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullValuesAreForbidden() { public void testNullValuesAreForbidden() {
new DomainNameMappingBuilder<>("NotFound").add("Some key", null); assertThrows(NullPointerException.class,
() -> new DomainNameMappingBuilder<>("NotFound").add("Some key", null));
} }
@Test @Test

View File

@ -16,27 +16,30 @@
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Map; 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 { public class DomainWildcardMappingBuilderTest {
@Test(expected = NullPointerException.class) @Test
public void testNullDefaultValue() { public void testNullDefaultValue() {
new DomainWildcardMappingBuilder<String>(null); assertThrows(NullPointerException.class, () -> new DomainWildcardMappingBuilder<String>(null));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullDomainNamePatternsAreForbidden() { public void testNullDomainNamePatternsAreForbidden() {
new DomainWildcardMappingBuilder<String>("NotFound").add(null, "Some value"); assertThrows(NullPointerException.class,
() -> new DomainWildcardMappingBuilder<String>("NotFound").add(null, "Some value"));
} }
@Test(expected = NullPointerException.class) @Test
public void testNullValuesAreForbidden() { public void testNullValuesAreForbidden() {
new DomainWildcardMappingBuilder<String>("NotFound").add("Some key", null); assertThrows(NullPointerException.class,
() -> new DomainWildcardMappingBuilder<String>("NotFound").add("Some key", null));
} }
@Test @Test

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -24,10 +24,10 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class HashedWheelTimerTest { public class HashedWheelTimerTest {
@ -40,7 +40,7 @@ public class HashedWheelTimerTest {
barrier.countDown(); barrier.countDown();
}, 10, TimeUnit.SECONDS); }, 10, TimeUnit.SECONDS);
assertFalse(barrier.await(3, TimeUnit.SECONDS)); assertFalse(barrier.await(3, TimeUnit.SECONDS));
assertFalse("timer should not expire", timeout.isExpired()); assertFalse(timeout.isExpired(), "timer should not expire");
timer.stop(); timer.stop();
} }
@ -50,11 +50,12 @@ public class HashedWheelTimerTest {
final CountDownLatch barrier = new CountDownLatch(1); final CountDownLatch barrier = new CountDownLatch(1);
final Timeout timeout = timer.newTimeout(timeout1 -> barrier.countDown(), 2, TimeUnit.SECONDS); final Timeout timeout = timer.newTimeout(timeout1 -> barrier.countDown(), 2, TimeUnit.SECONDS);
assertTrue(barrier.await(3, TimeUnit.SECONDS)); assertTrue(barrier.await(3, TimeUnit.SECONDS));
assertTrue("timer should expire", timeout.isExpired()); assertTrue(timeout.isExpired(), "timer should expire");
timer.stop(); timer.stop();
} }
@Test(timeout = 3000) @Test
@org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testStopTimer() throws InterruptedException { public void testStopTimer() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(3); final CountDownLatch latch = new CountDownLatch(3);
final Timer timerProcessed = new HashedWheelTimer(); final Timer timerProcessed = new HashedWheelTimer();
@ -63,7 +64,7 @@ public class HashedWheelTimerTest {
} }
latch.await(); 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(); final Timer timerUnprocessed = new HashedWheelTimer();
for (int i = 0; i < 5; i ++) { for (int i = 0; i < 5; i ++) {
@ -71,10 +72,11 @@ public class HashedWheelTimerTest {
}, 5, TimeUnit.SECONDS); }, 5, TimeUnit.SECONDS);
} }
Thread.sleep(1000L); // sleep for a second 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 { public void testTimerShouldThrowExceptionAfterShutdownForNewTimeouts() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(3); final CountDownLatch latch = new CountDownLatch(3);
final Timer timer = new HashedWheelTimer(); final Timer timer = new HashedWheelTimer();
@ -93,7 +95,8 @@ public class HashedWheelTimerTest {
} }
} }
@Test(timeout = 5000) @Test
@org.junit.jupiter.api.Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testTimerOverflowWheelLength() throws InterruptedException { public void testTimerOverflowWheelLength() throws InterruptedException {
final HashedWheelTimer timer = new HashedWheelTimer( final HashedWheelTimer timer = new HashedWheelTimer(
Executors.defaultThreadFactory(), 100, TimeUnit.MILLISECONDS, 32); Executors.defaultThreadFactory(), 100, TimeUnit.MILLISECONDS, 32);
@ -128,8 +131,8 @@ public class HashedWheelTimerTest {
for (int i = 0; i < scheduledTasks; i++) { for (int i = 0; i < scheduledTasks; i++) {
long delay = queue.take(); long delay = queue.take();
assertTrue("Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout, assertTrue(delay >= timeout && delay < maxTimeout,
delay >= timeout && delay < maxTimeout); "Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout);
} }
timer.stop(); timer.stop();
@ -170,7 +173,8 @@ public class HashedWheelTimerTest {
timer.stop(); timer.stop();
} }
@Test(timeout = 3000) @Test
@org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testNewTimeoutShouldStopThrowingRejectedExecutionExceptionWhenExistingTimeoutIsExecuted() public void testNewTimeoutShouldStopThrowingRejectedExecutionExceptionWhenExistingTimeoutIsExecuted()
throws InterruptedException { throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);

View File

@ -16,7 +16,7 @@
package io.netty.util; package io.netty.util;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.Inet6Address; import java.net.Inet6Address;
@ -28,11 +28,11 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import static io.netty.util.NetUtil.*; import static io.netty.util.NetUtil.*;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class NetUtilTest { public class NetUtilTest {
@ -611,72 +611,72 @@ public class NetUtilTest {
@Test @Test
public void testIsValidIpV4Address() { public void testIsValidIpV4Address() {
for (String host : validIpV4Hosts.keySet()) { for (String host : validIpV4Hosts.keySet()) {
assertTrue(host, isValidIpV4Address(host)); assertTrue(isValidIpV4Address(host), host);
} }
for (String host : invalidIpV4Hosts.keySet()) { for (String host : invalidIpV4Hosts.keySet()) {
assertFalse(host, isValidIpV4Address(host)); assertFalse(isValidIpV4Address(host), host);
} }
} }
@Test @Test
public void testIsValidIpV6Address() { public void testIsValidIpV6Address() {
for (String host : validIpV6Hosts.keySet()) { for (String host : validIpV6Hosts.keySet()) {
assertTrue(host, isValidIpV6Address(host)); assertTrue(isValidIpV6Address(host), host);
if (host.charAt(0) != '[' && !host.contains("%")) { if (host.charAt(0) != '[' && !host.contains("%")) {
assertNotNull(host, getByName(host, true)); assertNotNull(getByName(host, true), host);
String hostMod = '[' + host + ']'; String hostMod = '[' + host + ']';
assertTrue(hostMod, isValidIpV6Address(hostMod)); assertTrue(isValidIpV6Address(hostMod), hostMod);
hostMod = host + '%'; hostMod = host + '%';
assertTrue(hostMod, isValidIpV6Address(hostMod)); assertTrue(isValidIpV6Address(hostMod), hostMod);
hostMod = host + "%eth1"; hostMod = host + "%eth1";
assertTrue(hostMod, isValidIpV6Address(hostMod)); assertTrue(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "%]"; hostMod = '[' + host + "%]";
assertTrue(hostMod, isValidIpV6Address(hostMod)); assertTrue(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "%1]"; hostMod = '[' + host + "%1]";
assertTrue(hostMod, isValidIpV6Address(hostMod)); assertTrue(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "]%"; hostMod = '[' + host + "]%";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "]%1"; hostMod = '[' + host + "]%1";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
} }
} }
for (String host : invalidIpV6Hosts.keySet()) { for (String host : invalidIpV6Hosts.keySet()) {
assertFalse(host, isValidIpV6Address(host)); assertFalse(isValidIpV6Address(host), host);
assertNull(host, getByName(host)); assertNull(getByName(host), host);
String hostMod = '[' + host + ']'; String hostMod = '[' + host + ']';
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = host + '%'; hostMod = host + '%';
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = host + "%eth1"; hostMod = host + "%eth1";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "%]"; hostMod = '[' + host + "%]";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "%1]"; hostMod = '[' + host + "%1]";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "]%"; hostMod = '[' + host + "]%";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host + "]%1"; hostMod = '[' + host + "]%1";
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = host + ']'; hostMod = host + ']';
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
hostMod = '[' + host; hostMod = '[' + host;
assertFalse(hostMod, isValidIpV6Address(hostMod)); assertFalse(isValidIpV6Address(hostMod), hostMod);
} }
} }
@ -737,19 +737,19 @@ public class NetUtilTest {
String srcIp = testEntry.getKey(); String srcIp = testEntry.getKey();
String dstIp = testEntry.getValue(); String dstIp = testEntry.getValue();
Inet6Address inet6Address = getByName(srcIp, true); Inet6Address inet6Address = getByName(srcIp, true);
assertNotNull(srcIp + ", " + dstIp, inet6Address); assertNotNull(inet6Address, srcIp + ", " + dstIp);
assertEquals(srcIp, dstIp, toAddressString(inet6Address, true)); assertEquals(dstIp, toAddressString(inet6Address, true), srcIp);
} }
} }
@Test @Test
public void testInvalidIpv4MappedIp6GetByName() { public void testInvalidIpv4MappedIp6GetByName() {
for (String host : invalidIpV4Hosts.keySet()) { for (String host : invalidIpV4Hosts.keySet()) {
assertNull(host, getByName(host, true)); assertNull(getByName(host, true), host);
} }
for (String host : invalidIpV6Hosts.keySet()) { 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) { 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) { private static String hex(byte[] value) {

View File

@ -17,7 +17,7 @@
package io.netty.util; package io.netty.util;
import io.netty.util.internal.SystemPropertyUtil; 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.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier; 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.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.hasToString;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class NettyRuntimeTests { public class NettyRuntimeTests {

View File

@ -15,15 +15,23 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; 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 { public class RecyclerTest {
@ -44,7 +52,8 @@ public class RecyclerTest {
}; };
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() throws Exception { public void testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() throws Exception {
final Recycler<HandledObject> recycler = newRecycler(1024); final Recycler<HandledObject> recycler = newRecycler(1024);
final AtomicBoolean collected = new AtomicBoolean(); final AtomicBoolean collected = new AtomicBoolean();
@ -78,15 +87,15 @@ public class RecyclerTest {
reference.getAndSet(null).recycle(); reference.getAndSet(null).recycle();
} }
@Test(expected = IllegalStateException.class) @Test
public void testMultipleRecycle() { public void testMultipleRecycle() {
Recycler<HandledObject> recycler = newRecycler(1024); Recycler<HandledObject> recycler = newRecycler(1024);
HandledObject object = recycler.get(); HandledObject object = recycler.get();
object.recycle(); object.recycle();
object.recycle(); assertThrows(IllegalStateException.class, object::recycle);
} }
@Test(expected = IllegalStateException.class) @Test
public void testMultipleRecycleAtDifferentThread() throws InterruptedException { public void testMultipleRecycleAtDifferentThread() throws InterruptedException {
Recycler<HandledObject> recycler = newRecycler(1024); Recycler<HandledObject> recycler = newRecycler(1024);
final HandledObject object = recycler.get(); final HandledObject object = recycler.get();
@ -108,9 +117,7 @@ public class RecyclerTest {
HandledObject b = recycler.get(); HandledObject b = recycler.get();
assertNotSame(a, b); assertNotSame(a, b);
IllegalStateException exception = exceptionStore.get(); IllegalStateException exception = exceptionStore.get();
if (exception != null) { assertNotNull(exception);
throw exception;
}
} }
@Test @Test
@ -296,9 +303,9 @@ public class RecyclerTest {
objects[i] = null; objects[i] = null;
} }
assertTrue("The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity (" assertTrue(maxCapacity >= recycler.threadLocalCapacity(),
+ maxCapacity + ") as we not pool all new handles internally", "The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity ("
maxCapacity >= recycler.threadLocalCapacity()); + maxCapacity + ") as we not pool all new handles internally");
} }
@Test @Test
@ -405,9 +412,10 @@ public class RecyclerTest {
} }
// The implementation uses maxCapacity / 2 as limit per WeakOrderQueue // 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" + + ") - maxCapacity (" + maxCapacity + ") / 2 as we not pool all new handles" +
" internally", array.length - maxCapacity / 2 <= instancesCount.get()); " internally");
} }
static final class HandledObject { static final class HandledObject {

View File

@ -15,17 +15,20 @@
*/ */
package io.netty.util; 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.ArrayDeque;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
public class ResourceLeakDetectorTest { public class ResourceLeakDetectorTest {
@Test(timeout = 60000) @Test
@Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
public void testConcurrentUsage() throws Throwable { public void testConcurrentUsage() throws Throwable {
final AtomicBoolean finished = new AtomicBoolean(); final AtomicBoolean finished = new AtomicBoolean();
final AtomicReference<Throwable> error = new AtomicReference<>(); final AtomicReference<Throwable> error = new AtomicReference<>();

View File

@ -16,7 +16,8 @@
package io.netty.util; 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.CountDownLatch;
import java.util.concurrent.TimeUnit; 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.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class ThreadDeathWatcherTest { public class ThreadDeathWatcherTest {
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testWatch() throws Exception { public void testWatch() throws Exception {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final Thread t = new Thread() { final Thread t = new Thread() {
@ -72,7 +74,8 @@ public class ThreadDeathWatcherTest {
latch.await(); latch.await();
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testUnwatch() throws Exception { public void testUnwatch() throws Exception {
final AtomicBoolean run = new AtomicBoolean(); final AtomicBoolean run = new AtomicBoolean();
final Thread t = new Thread() { final Thread t = new Thread() {
@ -109,7 +112,8 @@ public class ThreadDeathWatcherTest {
assertThat(run.get(), is(false)); assertThat(run.get(), is(false));
} }
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testThreadGroup() throws InterruptedException { public void testThreadGroup() throws InterruptedException {
final ThreadGroup group = new ThreadGroup("group"); final ThreadGroup group = new ThreadGroup("group");
final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>(); final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>();

View File

@ -15,16 +15,16 @@
*/ */
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class AbstractScheduledEventExecutorTest { public class AbstractScheduledEventExecutorTest {
private static final Runnable TEST_RUNNABLE = () -> { private static final Runnable TEST_RUNNABLE = () -> {
@ -68,33 +68,37 @@ public class AbstractScheduledEventExecutorTest {
assertNull(executor.pollScheduledTask()); assertNull(executor.pollScheduledTask());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleAtFixedRateRunnableZero() { public void testScheduleAtFixedRateRunnableZero() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class,
() -> executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleAtFixedRateRunnableNegative() { public void testScheduleAtFixedRateRunnableNegative() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class,
() -> executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleWithFixedDelayZero() { public void testScheduleWithFixedDelayZero() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class,
() -> executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleWithFixedDelayNegative() { public void testScheduleWithFixedDelayNegative() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class,
() -> executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
} }
@Test @Test
public void testDeadlineNanosNotOverflow() { public void testDeadlineNanosNotOverflow() {
Assert.assertEquals(Long.MAX_VALUE, AbstractScheduledEventExecutor.deadlineNanos(Long.MAX_VALUE)); assertEquals(Long.MAX_VALUE, AbstractScheduledEventExecutor.deadlineNanos(Long.MAX_VALUE));
} }
private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor { private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor {

View File

@ -15,10 +15,9 @@
*/ */
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -31,12 +30,13 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class DefaultFutureCompletionStageTest { public class DefaultFutureCompletionStageTest {
@ -47,13 +47,13 @@ public class DefaultFutureCompletionStageTest {
private static final Boolean INITIAL_BOOLEAN = Boolean.TRUE; private static final Boolean INITIAL_BOOLEAN = Boolean.TRUE;
private static final Boolean EXPECTED_BOOLEAN = Boolean.FALSE; private static final Boolean EXPECTED_BOOLEAN = Boolean.FALSE;
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
group = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory()); group = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory());
asyncExecutorGroup = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory()); asyncExecutorGroup = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory());
} }
@AfterClass @AfterAll
public static void destroy() { public static void destroy() {
group.shutdownGracefully(); group.shutdownGracefully();
asyncExecutorGroup.shutdownGracefully(); asyncExecutorGroup.shutdownGracefully();
@ -84,12 +84,12 @@ public class DefaultFutureCompletionStageTest {
assertSame(promise, stage.future()); assertSame(promise, stage.future());
} }
@Test(expected = UnsupportedOperationException.class) @Test
public void testThrowsUnsupportedOperationException() { public void testThrowsUnsupportedOperationException() {
EventExecutor executor = executor(); EventExecutor executor = executor();
Promise<Boolean> promise = executor.newPromise(); Promise<Boolean> promise = executor.newPromise();
FutureCompletionStage<Boolean> stage = new DefaultFutureCompletionStage<>(promise); FutureCompletionStage<Boolean> stage = new DefaultFutureCompletionStage<>(promise);
stage.toCompletableFuture(); assertThrows(UnsupportedOperationException.class, () -> stage.toCompletableFuture());
} }
@Test @Test

View File

@ -19,8 +19,9 @@ package io.netty.util.concurrent;
import io.netty.util.Signal; import io.netty.util.Signal;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.util.HashMap; import java.util.HashMap;
@ -41,14 +42,19 @@ import static java.lang.Math.max;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThan; 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") @SuppressWarnings("unchecked")
public class DefaultPromiseTest { public class DefaultPromiseTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultPromiseTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultPromiseTest.class);
private static int stackOverflowDepth; private static int stackOverflowDepth;
@BeforeClass @BeforeAll
public static void beforeClass() { public static void beforeClass() {
try { try {
findStackOverflowDepth(); findStackOverflowDepth();
@ -102,19 +108,19 @@ public class DefaultPromiseTest {
assertSame(cause, promise.cause()); assertSame(cause, promise.cause());
} }
@Test(expected = CancellationException.class) @Test
public void testCancellationExceptionIsThrownWhenBlockingGet() throws InterruptedException, ExecutionException { public void testCancellationExceptionIsThrownWhenBlockingGet() throws InterruptedException, ExecutionException {
final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE); final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false)); assertTrue(promise.cancel(false));
promise.get(); assertThrows(CancellationException.class, promise::get);
} }
@Test(expected = CancellationException.class) @Test
public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() throws InterruptedException, public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() throws InterruptedException,
ExecutionException, TimeoutException { ExecutionException, TimeoutException {
final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE); final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false)); assertTrue(promise.cancel(false));
promise.get(1, TimeUnit.SECONDS); assertThrows(CancellationException.class, () -> promise.get(1, TimeUnit.SECONDS));
} }
@Test @Test
@ -208,11 +214,11 @@ public class DefaultPromiseTest {
promise.addListener(listener1).addListener(listener2).addListener(listener3); promise.addListener(listener1).addListener(listener2).addListener(listener3);
assertSame("Fail 1 during run " + i + " / " + runs, listener1, listeners.take()); assertSame(listener1, listeners.take(), "Fail 1 during run " + i + " / " + runs);
assertSame("Fail 2 during run " + i + " / " + runs, listener2, listeners.take()); assertSame(listener2, listeners.take(), "Fail 2 during run " + i + " / " + runs);
assertSame("Fail 3 during run " + i + " / " + runs, listener3, listeners.take()); assertSame(listener3, listeners.take(), "Fail 3 during run " + i + " / " + runs);
assertSame("Fail 4 during run " + i + " / " + runs, listener4, listeners.take()); assertSame(listener4, listeners.take(), "Fail 4 during run " + i + " / " + runs);
assertTrue("Fail during run " + i + " / " + runs, listeners.isEmpty()); assertTrue(listeners.isEmpty(), "Fail during run " + i + " / " + runs);
} }
} finally { } finally {
executor.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync(); executor.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync();
@ -228,22 +234,26 @@ public class DefaultPromiseTest {
testListenerNotifyLater(2); testListenerNotifyLater(2);
} }
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testPromiseListenerAddWhenCompleteFailure() throws Exception { public void testPromiseListenerAddWhenCompleteFailure() throws Exception {
testPromiseListenerAddWhenComplete(fakeException()); testPromiseListenerAddWhenComplete(fakeException());
} }
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testPromiseListenerAddWhenCompleteSuccess() throws Exception { public void testPromiseListenerAddWhenCompleteSuccess() throws Exception {
testPromiseListenerAddWhenComplete(null); testPromiseListenerAddWhenComplete(null);
} }
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testLateListenerIsOrderedCorrectlySuccess() throws InterruptedException { public void testLateListenerIsOrderedCorrectlySuccess() throws InterruptedException {
testLateListenerIsOrderedCorrectly(null); testLateListenerIsOrderedCorrectly(null);
} }
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testLateListenerIsOrderedCorrectlyFailure() throws InterruptedException { public void testLateListenerIsOrderedCorrectlyFailure() throws InterruptedException {
testLateListenerIsOrderedCorrectly(fakeException()); testLateListenerIsOrderedCorrectly(fakeException());
} }
@ -334,11 +344,11 @@ public class DefaultPromiseTest {
} }
} }
@Test(expected = CancellationException.class) @Test
public void throwCancelled() throws InterruptedException { public void throwCancelled() throws InterruptedException {
final Promise<String> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE); final Promise<String> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
promise.cancel(true); promise.cancel(true);
promise.sync(); assertThrows(CancellationException.class, promise::sync);
} }
private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor, private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor,
@ -355,7 +365,7 @@ public class DefaultPromiseTest {
assertTrue(latch.await(2, TimeUnit.SECONDS)); assertTrue(latch.await(2, TimeUnit.SECONDS));
for (int i = 0; i < p.length; ++i) { for (int i = 0; i < p.length; ++i) {
assertTrue("index " + i, p[i].isSuccess()); assertTrue(p[i].isSuccess(), "index " + i);
} }
} }
@ -389,7 +399,7 @@ public class DefaultPromiseTest {
assertTrue(latch.await(2, TimeUnit.SECONDS)); assertTrue(latch.await(2, TimeUnit.SECONDS));
for (int i = 0; i < p.length; ++i) { for (int i = 0; i < p.length; ++i) {
assertTrue("index " + i, p[i].isSuccess()); assertTrue(p[i].isSuccess(), "index " + i);
} }
} }
@ -499,8 +509,8 @@ public class DefaultPromiseTest {
promise.addListener(listener); promise.addListener(listener);
}); });
assertTrue("Should have notified " + expectedCount + " listeners", assertTrue(latch.await(5, TimeUnit.SECONDS),
latch.await(5, TimeUnit.SECONDS)); "Should have notified " + expectedCount + " listeners");
executor.shutdownGracefully().sync(); executor.shutdownGracefully().sync();
} }

View File

@ -16,20 +16,23 @@
package io.netty.util.concurrent; 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.security.Permission;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultThreadFactoryTest { public class DefaultThreadFactoryTest {
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testDescendantThreadGroups() throws InterruptedException { public void testDescendantThreadGroups() throws InterruptedException {
final SecurityManager current = System.getSecurityManager(); final SecurityManager current = System.getSecurityManager();
@ -106,7 +109,8 @@ public class DefaultThreadFactoryTest {
// test that when DefaultThreadFactory is constructed with a sticky thread group, threads // test that when DefaultThreadFactory is constructed with a sticky thread group, threads
// created by it have the sticky thread group // created by it have the sticky thread group
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testDefaultThreadFactoryStickyThreadGroupConstructor() throws InterruptedException { public void testDefaultThreadFactoryStickyThreadGroupConstructor() throws InterruptedException {
final ThreadGroup sticky = new ThreadGroup("sticky"); final ThreadGroup sticky = new ThreadGroup("sticky");
runStickyThreadGroupTest( runStickyThreadGroupTest(
@ -116,7 +120,8 @@ public class DefaultThreadFactoryTest {
// test that when a security manager is installed that provides a ThreadGroup, DefaultThreadFactory inherits from // test that when a security manager is installed that provides a ThreadGroup, DefaultThreadFactory inherits from
// the security manager // the security manager
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testDefaultThreadFactoryInheritsThreadGroupFromSecurityManager() throws InterruptedException { public void testDefaultThreadFactoryInheritsThreadGroupFromSecurityManager() throws InterruptedException {
final SecurityManager current = System.getSecurityManager(); final SecurityManager current = System.getSecurityManager();
@ -169,7 +174,8 @@ public class DefaultThreadFactoryTest {
// test that when DefaultThreadFactory is constructed without a sticky thread group, threads // test that when DefaultThreadFactory is constructed without a sticky thread group, threads
// created by it inherit the correct thread group // created by it inherit the correct thread group
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testDefaultThreadFactoryNonStickyThreadGroupConstructor() throws InterruptedException { public void testDefaultThreadFactoryNonStickyThreadGroupConstructor() throws InterruptedException {
final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>(); final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>();
@ -203,7 +209,8 @@ public class DefaultThreadFactoryTest {
// test that when DefaultThreadFactory is constructed without a sticky thread group, threads // test that when DefaultThreadFactory is constructed without a sticky thread group, threads
// created by it inherit the correct thread group // created by it inherit the correct thread group
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testCurrentThreadGroupIsUsed() throws InterruptedException { public void testCurrentThreadGroupIsUsed() throws InterruptedException {
final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>(); final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>();
final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<>(); final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<>();

View File

@ -17,22 +17,24 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import io.netty.util.internal.ObjectCleaner; import io.netty.util.internal.ObjectCleaner;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; 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.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class FastThreadLocalTest { public class FastThreadLocalTest {
@Before @BeforeEach
public void setUp() { public void setUp() {
FastThreadLocal.removeAll(); FastThreadLocal.removeAll();
assertThat(FastThreadLocal.size(), is(0)); assertThat(FastThreadLocal.size(), is(0));
@ -55,7 +57,8 @@ public class FastThreadLocalTest {
assertNull(threadLocal.getIfExists()); assertNull(threadLocal.getIfExists());
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAll() throws Exception { public void testRemoveAll() throws Exception {
final AtomicBoolean removed = new AtomicBoolean(); final AtomicBoolean removed = new AtomicBoolean();
final FastThreadLocal<Boolean> var = new FastThreadLocal<Boolean>() { final FastThreadLocal<Boolean> var = new FastThreadLocal<Boolean>() {
@ -75,7 +78,8 @@ public class FastThreadLocalTest {
assertThat(FastThreadLocal.size(), is(0)); assertThat(FastThreadLocal.size(), is(0));
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAllFromFTLThread() throws Throwable { public void testRemoveAllFromFTLThread() throws Throwable {
final AtomicReference<Throwable> throwable = new AtomicReference<>(); final AtomicReference<Throwable> throwable = new AtomicReference<>();
final Thread thread = new FastThreadLocalThread() { final Thread thread = new FastThreadLocalThread() {
@ -151,24 +155,28 @@ public class FastThreadLocalTest {
assertEquals(0, ObjectCleaner.getLiveSetCount() - sizeWhenStart); assertEquals(0, ObjectCleaner.getLiveSetCount() - sizeWhenStart);
} }
@Test(timeout = 4000) @Test
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
public void testOnRemoveCalledForFastThreadLocalGet() throws Exception { public void testOnRemoveCalledForFastThreadLocalGet() throws Exception {
testOnRemoveCalled(true, true); testOnRemoveCalled(true, true);
} }
@Ignore("onRemoval(...) not called with non FastThreadLocal") @Disabled("onRemoval(...) not called with non FastThreadLocal")
@Test(timeout = 4000) @Test
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
public void testOnRemoveCalledForNonFastThreadLocalGet() throws Exception { public void testOnRemoveCalledForNonFastThreadLocalGet() throws Exception {
testOnRemoveCalled(false, true); testOnRemoveCalled(false, true);
} }
@Test(timeout = 4000) @Test
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
public void testOnRemoveCalledForFastThreadLocalSet() throws Exception { public void testOnRemoveCalledForFastThreadLocalSet() throws Exception {
testOnRemoveCalled(true, false); testOnRemoveCalled(true, false);
} }
@Ignore("onRemoval(...) not called with non FastThreadLocal") @Disabled("onRemoval(...) not called with non FastThreadLocal")
@Test(timeout = 4000) @Test
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
public void testOnRemoveCalledForNonFastThreadLocalSet() throws Exception { public void testOnRemoveCalledForNonFastThreadLocalSet() throws Exception {
testOnRemoveCalled(false, false); testOnRemoveCalled(false, false);
} }

View File

@ -15,13 +15,13 @@
*/ */
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
public class FutureCompletionStageTest { public class FutureCompletionStageTest {

View File

@ -16,8 +16,9 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; 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.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class GlobalEventExecutorTest { public class GlobalEventExecutorTest {
private static final GlobalEventExecutor e = GlobalEventExecutor.INSTANCE; private static final GlobalEventExecutor e = GlobalEventExecutor.INSTANCE;
@Before @BeforeEach
public void setUp() throws Exception { 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) // Wait until the global executor is stopped (just in case there is a task running due to previous test cases)
for (;;) { for (;;) {
@ -46,7 +47,8 @@ public class GlobalEventExecutorTest {
} }
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testAutomaticStartStop() throws Exception { public void testAutomaticStartStop() throws Exception {
final TestRunnable task = new TestRunnable(500); final TestRunnable task = new TestRunnable(500);
e.execute(task); e.execute(task);
@ -70,7 +72,8 @@ public class GlobalEventExecutorTest {
assertThat(task.ran.get(), is(true)); assertThat(task.ran.get(), is(true));
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testScheduledTasks() throws Exception { public void testScheduledTasks() throws Exception {
TestRunnable task = new TestRunnable(0); TestRunnable task = new TestRunnable(0);
ScheduledFuture<?> f = e.schedule(task, 1500, TimeUnit.MILLISECONDS); 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 // ensure that when a task submission causes a new thread to be created, the thread inherits the thread group of the
// submitting thread // submitting thread
@Test(timeout = 2000) @Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testThreadGroup() throws InterruptedException { public void testThreadGroup() throws InterruptedException {
final ThreadGroup group = new ThreadGroup("group"); final ThreadGroup group = new ThreadGroup("group");
final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>(); final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>();
@ -102,7 +106,8 @@ public class GlobalEventExecutorTest {
assertEquals(group, capturedGroup.get()); assertEquals(group, capturedGroup.get());
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testTakeTask() throws Exception { public void testTakeTask() throws Exception {
//add task //add task
TestRunnable beforeTask = new TestRunnable(0); TestRunnable beforeTask = new TestRunnable(0);
@ -123,7 +128,8 @@ public class GlobalEventExecutorTest {
assertThat(afterTask.ran.get(), is(true)); assertThat(afterTask.ran.get(), is(true));
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testTakeTaskAlwaysHasTask() throws Exception { public void testTakeTaskAlwaysHasTask() throws Exception {
//for https://github.com/netty/netty/issues/1614 //for https://github.com/netty/netty/issues/1614
//add scheduled task //add scheduled task

View File

@ -16,19 +16,20 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ImmediateExecutorTest { public class ImmediateExecutorTest {
@Test(expected = NullPointerException.class) @Test
public void testExecuteNullRunnable() { public void testExecuteNullRunnable() {
ImmediateExecutor.INSTANCE.execute(null); assertThrows(NullPointerException.class, () -> ImmediateExecutor.INSTANCE.execute(null));
} }
@Test @Test

View File

@ -16,10 +16,10 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import io.netty.util.NettyRuntime; import io.netty.util.NettyRuntime;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.Timeout;
import org.junit.runner.RunWith; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -29,22 +29,22 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; 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 { public class NonStickyEventExecutorGroupTest {
private static final String PARAMETERIZED_NAME = "{index}: maxTaskExecutePerRun = {0}";
private final int maxTaskExecutePerRun; @Test
@Test(expected = IllegalArgumentException.class)
public void testInvalidGroup() { public void testInvalidGroup() {
EventExecutorGroup group = new DefaultEventExecutorGroup(1); EventExecutorGroup group = new DefaultEventExecutorGroup(1);
try { try {
new NonStickyEventExecutorGroup(group); assertThrows(IllegalArgumentException.class, () -> new NonStickyEventExecutorGroup(group));
} finally { } finally {
group.shutdownGracefully(); group.shutdownGracefully();
} }
} }
@Parameterized.Parameters(name = "{index}: maxTaskExecutePerRun = {0}")
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
List<Object[]> params = new ArrayList<>(); List<Object[]> params = new ArrayList<>();
params.add(new Object[] {64}); params.add(new Object[] {64});
@ -54,12 +54,10 @@ public class NonStickyEventExecutorGroupTest {
return params; return params;
} }
public NonStickyEventExecutorGroupTest(int maxTaskExecutePerRun) { @ParameterizedTest(name = PARAMETERIZED_NAME)
this.maxTaskExecutePerRun = maxTaskExecutePerRun; @MethodSource("data")
} @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testOrdering(int maxTaskExecutePerRun) throws Throwable {
@Test(timeout = 10000)
public void testOrdering() throws Throwable {
final int threads = NettyRuntime.availableProcessors() * 2; final int threads = NettyRuntime.availableProcessors() * 2;
final EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(threads); final EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(threads);
final NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun); final NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun);
@ -91,8 +89,9 @@ public class NonStickyEventExecutorGroupTest {
} }
} }
@Test @ParameterizedTest(name = PARAMETERIZED_NAME)
public void testRaceCondition() throws InterruptedException { @MethodSource("data")
public void testRaceCondition(int maxTaskExecutePerRun) throws InterruptedException {
EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(1); EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(1);
NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun); NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun);
@ -107,10 +106,10 @@ public class NonStickyEventExecutorGroupTest {
firstCompleted.countDown(); firstCompleted.countDown();
latch.countDown(); 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 { } finally {
nonStickyGroup.shutdownGracefully(); nonStickyGroup.shutdownGracefully();
@ -119,7 +118,7 @@ public class NonStickyEventExecutorGroupTest {
private static void execute(EventExecutorGroup group, CountDownLatch startLatch) throws Throwable { private static void execute(EventExecutorGroup group, CountDownLatch startLatch) throws Throwable {
EventExecutor executor = group.next(); EventExecutor executor = group.next();
Assert.assertTrue(executor instanceof OrderedEventExecutor); assertTrue(executor instanceof OrderedEventExecutor);
final AtomicReference<Throwable> cause = new AtomicReference<>(); final AtomicReference<Throwable> cause = new AtomicReference<>();
final AtomicInteger last = new AtomicInteger(); final AtomicInteger last = new AtomicInteger();
int tasks = 10000; int tasks = 10000;

View File

@ -16,23 +16,18 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class PromiseAggregatorTest { public class PromiseAggregatorTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test @Test
public void testNullAggregatePromise() { public void testNullAggregatePromise() {
expectedException.expect(NullPointerException.class); assertThrows(NullPointerException.class, () -> new PromiseAggregator<Void, Future<Void>>(null));
new PromiseAggregator<Void, Future<Void>>(null);
} }
@Test @Test
@ -41,8 +36,7 @@ public class PromiseAggregatorTest {
Promise<Void> p = mock(Promise.class); Promise<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a = PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<>(p); new PromiseAggregator<>(p);
expectedException.expect(NullPointerException.class); assertThrows(NullPointerException.class, () -> a.add((Promise<Void>[]) null));
a.add((Promise<Void>[]) null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -15,14 +15,15 @@
*/ */
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; 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.any;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
@ -54,7 +55,7 @@ public class PromiseCombinerTest {
private Promise<Void> p3; private Promise<Void> p3;
private PromiseCombiner combiner; private PromiseCombiner combiner;
@Before @BeforeEach
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
combiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE); combiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE);
@ -64,7 +65,7 @@ public class PromiseCombinerTest {
public void testNullArgument() { public void testNullArgument() {
try { try {
combiner.finish(null); combiner.finish(null);
Assert.fail(); fail();
} catch (NullPointerException expected) { } catch (NullPointerException expected) {
// expected // expected
} }
@ -78,34 +79,34 @@ public class PromiseCombinerTest {
verify(p1).trySuccess(null); verify(p1).trySuccess(null);
} }
@Test(expected = NullPointerException.class) @Test
public void testAddNullPromise() { public void testAddNullPromise() {
combiner.add(null); assertThrows(NullPointerException.class, () -> combiner.add(null));
} }
@Test(expected = NullPointerException.class) @Test
public void testAddAllNullPromise() { public void testAddAllNullPromise() {
combiner.addAll(null); assertThrows(NullPointerException.class, () -> combiner.addAll(null));
} }
@Test(expected = IllegalStateException.class) @Test
public void testAddAfterFinish() { public void testAddAfterFinish() {
combiner.finish(p1); combiner.finish(p1);
combiner.add(p2); assertThrows(IllegalStateException.class, () -> combiner.add(p2));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class) @Test
public void testAddAllAfterFinish() { public void testAddAllAfterFinish() {
combiner.finish(p1); combiner.finish(p1);
combiner.addAll(p2); assertThrows(IllegalStateException.class, () -> combiner.addAll(p2));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class) @Test
public void testFinishCalledTwiceThrows() { public void testFinishCalledTwiceThrows() {
combiner.finish(p1); combiner.finish(p1);
combiner.finish(p1); assertThrows(IllegalStateException.class, () -> combiner.finish(p1));
} }
@Test @Test
@ -172,14 +173,14 @@ public class PromiseCombinerTest {
try { try {
combiner.add(future); combiner.add(future);
Assert.fail(); fail();
} catch (IllegalStateException expected) { } catch (IllegalStateException expected) {
// expected // expected
} }
try { try {
combiner.addAll(future); combiner.addAll(future);
Assert.fail(); fail();
} catch (IllegalStateException expected) { } catch (IllegalStateException expected) {
// expected // expected
} }
@ -188,7 +189,7 @@ public class PromiseCombinerTest {
Promise<Void> promise = (Promise<Void>) mock(Promise.class); Promise<Void> promise = (Promise<Void>) mock(Promise.class);
try { try {
combiner.finish(promise); combiner.finish(promise);
Assert.fail(); fail();
} catch (IllegalStateException expected) { } catch (IllegalStateException expected) {
// expected // expected
} }

View File

@ -16,28 +16,22 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import static org.mockito.Mockito.*; import org.junit.jupiter.api.Test;
import org.junit.Rule; import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.Test; import static org.mockito.Mockito.*;
import org.junit.rules.ExpectedException;
public class PromiseNotifierTest { public class PromiseNotifierTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test @Test
public void testNullPromisesArray() { public void testNullPromisesArray() {
expectedException.expect(NullPointerException.class); assertThrows(NullPointerException.class, () -> new PromiseNotifier<>((Promise<Void>[]) null));
new PromiseNotifier<>((Promise<Void>[]) null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testNullPromiseInArray() { public void testNullPromiseInArray() {
expectedException.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> new PromiseNotifier<>((Promise<Void>) null));
new PromiseNotifier<>((Promise<Void>) null);
} }
@Test @Test

View File

@ -15,13 +15,17 @@
*/ */
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.Timeout;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; 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 { public class UnorderedThreadPoolEventExecutorTest {
// See https://github.com/netty/netty/issues/6507 // See https://github.com/netty/netty/issues/6507
@ -40,14 +44,15 @@ public class UnorderedThreadPoolEventExecutorTest {
// Now just check if the queue stays empty multiple times. This is needed as the submit to execute(...) // 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 // by DefaultPromise may happen in an async fashion
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
Assert.assertTrue(executor.getQueue().isEmpty()); assertTrue(executor.getQueue().isEmpty());
} }
} finally { } finally {
executor.shutdownGracefully(); executor.shutdownGracefully();
} }
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void scheduledAtFixedRateMustRunTaskRepeatedly() throws InterruptedException { public void scheduledAtFixedRateMustRunTaskRepeatedly() throws InterruptedException {
UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1); UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
final CountDownLatch latch = new CountDownLatch(3); final CountDownLatch latch = new CountDownLatch(3);
@ -77,7 +82,7 @@ public class UnorderedThreadPoolEventExecutorTest {
} }
}); });
Assert.assertEquals(expected, f.get()); assertEquals(expected, f.get());
} finally { } finally {
executor.shutdownGracefully(); executor.shutdownGracefully();
} }
@ -95,7 +100,7 @@ public class UnorderedThreadPoolEventExecutorTest {
} }
}); });
Assert.assertSame(cause, f.await().cause()); assertSame(cause, f.await().cause());
} finally { } finally {
executor.shutdownGracefully(); executor.shutdownGracefully();
} }

View File

@ -15,10 +15,9 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.jupiter.api.Test;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.*;
public class AppendableCharSequenceTest { public class AppendableCharSequenceTest {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,12 +25,12 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class DefaultPriorityQueueTest { public class DefaultPriorityQueueTest {
@Test @Test

View File

@ -15,12 +15,13 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES; import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES;
import static io.netty.util.internal.MacAddressUtil.parseMAC; import static io.netty.util.internal.MacAddressUtil.parseMAC;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MacAddressUtilTest { public class MacAddressUtilTest {
@Test @Test
@ -94,53 +95,53 @@ public class MacAddressUtilTest {
parseMAC("00:AA:11:FF:FE:BB:22:CC")); parseMAC("00:AA:11:FF:FE:BB:22:CC"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalid7HexGroupsA() { public void testParseMacInvalid7HexGroupsA() {
parseMAC("00-AA-11-BB-22-CC-FF"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-BB-22-CC-FF"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalid7HexGroupsB() { public void testParseMacInvalid7HexGroupsB() {
parseMAC("00:AA:11:BB:22:CC:FF"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:BB:22:CC:FF"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI48MixedSeparatorA() { public void testParseMacInvalidEUI48MixedSeparatorA() {
parseMAC("00-AA:11-BB-22-CC"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA:11-BB-22-CC"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI48MixedSeparatorB() { public void testParseMacInvalidEUI48MixedSeparatorB() {
parseMAC("00:AA-11:BB:22:CC"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA-11:BB:22:CC"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI64MixedSeparatorA() { public void testParseMacInvalidEUI64MixedSeparatorA() {
parseMAC("00-AA-11-FF-FE-BB-22:CC"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-FF-FE-BB-22:CC"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI64MixedSeparatorB() { public void testParseMacInvalidEUI64MixedSeparatorB() {
parseMAC("00:AA:11:FF:FE:BB:22-CC"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:FF:FE:BB:22-CC"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI48TrailingSeparatorA() { public void testParseMacInvalidEUI48TrailingSeparatorA() {
parseMAC("00-AA-11-BB-22-CC-"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-BB-22-CC-"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI48TrailingSeparatorB() { public void testParseMacInvalidEUI48TrailingSeparatorB() {
parseMAC("00:AA:11:BB:22:CC:"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:BB:22:CC:"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI64TrailingSeparatorA() { public void testParseMacInvalidEUI64TrailingSeparatorA() {
parseMAC("00-AA-11-FF-FE-BB-22-CC-"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-FF-FE-BB-22-CC-"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testParseMacInvalidEUI64TrailingSeparatorB() { public void testParseMacInvalidEUI64TrailingSeparatorB() {
parseMAC("00:AA:11:FF:FE:BB:22:CC:"); assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:FF:FE:BB:22:CC:"));
} }
} }

View File

@ -15,12 +15,12 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static io.netty.util.internal.MathUtil.*; import static io.netty.util.internal.MathUtil.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MathUtilTest { public class MathUtilTest {

View File

@ -16,7 +16,7 @@
package io.netty.util.internal; package io.netty.util.internal;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -27,10 +27,10 @@ import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class NativeLibraryLoaderTest { public class NativeLibraryLoaderTest {

View File

@ -15,23 +15,26 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.Timeout;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ObjectCleanerTest { public class ObjectCleanerTest {
private Thread temporaryThread; private Thread temporaryThread;
private Object temporaryObject; private Object temporaryObject;
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testCleanup() throws Exception { public void testCleanup() throws Exception {
final AtomicBoolean freeCalled = new AtomicBoolean(); final AtomicBoolean freeCalled = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
@ -47,7 +50,7 @@ public class ObjectCleanerTest {
latch.countDown(); latch.countDown();
temporaryThread.join(); temporaryThread.join();
Assert.assertFalse(freeCalled.get()); assertFalse(freeCalled.get());
// Null out the temporary object to ensure it is enqueued for GC. // Null out the temporary object to ensure it is enqueued for GC.
temporaryThread = null; temporaryThread = null;
@ -59,7 +62,8 @@ public class ObjectCleanerTest {
} }
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testCleanupContinuesDespiteThrowing() throws InterruptedException { public void testCleanupContinuesDespiteThrowing() throws InterruptedException {
final AtomicInteger freeCalledCount = new AtomicInteger(); final AtomicInteger freeCalledCount = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
@ -96,7 +100,8 @@ public class ObjectCleanerTest {
} }
} }
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testCleanerThreadIsDaemon() throws Exception { public void testCleanerThreadIsDaemon() throws Exception {
temporaryObject = new Object(); temporaryObject = new Object();
ObjectCleaner.register(temporaryObject, () -> { ObjectCleaner.register(temporaryObject, () -> {

View File

@ -14,10 +14,11 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
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. * Testcases for io.netty.util.internal.ObjectUtil.
@ -78,7 +79,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -86,8 +87,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -98,7 +99,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -106,8 +107,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -118,7 +119,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -126,8 +127,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -138,7 +139,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -146,8 +147,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -155,8 +156,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -167,7 +168,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -175,8 +176,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -184,8 +185,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -196,7 +197,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -204,8 +205,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -213,8 +214,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -225,7 +226,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -233,8 +234,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -242,8 +243,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -254,7 +255,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -262,7 +263,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -270,8 +271,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -282,7 +283,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -290,7 +291,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -298,8 +299,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -310,7 +311,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -318,7 +319,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -326,8 +327,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -338,7 +339,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -346,7 +347,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -354,8 +355,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -367,8 +368,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -376,7 +377,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -384,8 +385,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -397,8 +398,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -406,7 +407,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -414,8 +415,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -427,8 +428,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -436,7 +437,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -444,8 +445,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -456,8 +457,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -465,7 +466,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -473,8 +474,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
@Test @Test
@ -486,8 +487,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -495,7 +496,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -503,8 +504,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -512,7 +513,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
} }
@Test @Test
@ -524,8 +525,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -533,7 +534,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -541,8 +542,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -550,7 +551,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
} }
@Test @Test
@ -562,8 +563,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException); assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -571,7 +572,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNull(TEST_RESULT_NULLEX_NOK, actualEx); assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
actualEx = null; actualEx = null;
try { try {
@ -579,8 +580,8 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
actualEx = null; actualEx = null;
try { try {
@ -588,7 +589,7 @@ public class ObjectUtilTest {
} catch (Exception e) { } catch (Exception e) {
actualEx = e; actualEx = e;
} }
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx); assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException); assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
} }
} }

View File

@ -15,18 +15,18 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.Permission; import java.security.Permission;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class PlatformDependent0Test { public class PlatformDependent0Test {
@BeforeClass @BeforeAll
public static void assumeUnsafe() { public static void assumeUnsafe() {
assumeTrue(PlatformDependent0.hasUnsafe()); assumeTrue(PlatformDependent0.hasUnsafe());
assumeTrue(PlatformDependent0.hasDirectBufferNoCleanerConstructor()); assumeTrue(PlatformDependent0.hasDirectBufferNoCleanerConstructor());

View File

@ -15,15 +15,19 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Random; import java.util.Random;
import static io.netty.util.internal.PlatformDependent.hashCodeAscii; import static io.netty.util.internal.PlatformDependent.hashCodeAscii;
import static io.netty.util.internal.PlatformDependent.hashCodeAsciiSafe; import static io.netty.util.internal.PlatformDependent.hashCodeAsciiSafe;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assume.assumeTrue; 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 { public class PlatformDependentTest {
private static final Random r = new Random(); private static final Random r = new Random();
@ -128,12 +132,12 @@ public class PlatformDependentTest {
bytes[j] = (byte) (bytesChar[j] & 0xff); bytes[j] = (byte) (bytesChar[j] & 0xff);
} }
String string = new String(bytesChar); String string = new String(bytesChar);
assertEquals("length=" + i, assertEquals(hashCodeAsciiSafe(bytes, 0, bytes.length),
hashCodeAsciiSafe(bytes, 0, bytes.length), hashCodeAscii(bytes, 0, bytes.length),
hashCodeAscii(bytes, 0, bytes.length)); "length=" + i);
assertEquals("length=" + i, assertEquals(hashCodeAscii(bytes, 0, bytes.length),
hashCodeAscii(bytes, 0, bytes.length), hashCodeAscii(string),
hashCodeAscii(string)); "length=" + i);
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -33,12 +33,13 @@ import static io.netty.util.internal.StringUtil.unescapeCsv;
import static io.netty.util.internal.StringUtil.unescapeCsvFields; import static io.netty.util.internal.StringUtil.unescapeCsvFields;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StringUtilTest { public class StringUtilTest {
@ -160,9 +161,9 @@ public class StringUtilTest {
return sp; return sp;
} }
@Test (expected = NullPointerException.class) @Test
public void escapeCsvNull() { public void escapeCsvNull() {
StringUtil.escapeCsv(null); assertThrows(NullPointerException.class, () -> StringUtil.escapeCsv(null));
} }
@Test @Test
@ -407,29 +408,29 @@ public class StringUtilTest {
assertEquals("hello,netty", unescapeCsv("\"hello,netty\"")); assertEquals("hello,netty", unescapeCsv("\"hello,netty\""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithSingleQuote() { public void unescapeCsvWithSingleQuote() {
unescapeCsv("\""); assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithOddQuote() { public void unescapeCsvWithOddQuote() {
unescapeCsv("\"\"\""); assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\"\"\""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithCRAndWithoutQuote() { public void unescapeCsvWithCRAndWithoutQuote() {
unescapeCsv("\r"); assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\r"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithLFAndWithoutQuote() { public void unescapeCsvWithLFAndWithoutQuote() {
unescapeCsv("\n"); assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\n"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithCommaAndWithoutQuote() { public void unescapeCsvWithCommaAndWithoutQuote() {
unescapeCsv(","); assertThrows(IllegalArgumentException.class, () -> unescapeCsv(","));
} }
@Test @Test
@ -464,29 +465,29 @@ public class StringUtilTest {
assertEquals(Arrays.asList("a\rb", "c\nd"), unescapeCsvFields("\"a\rb\",\"c\nd\"")); assertEquals(Arrays.asList("a\rb", "c\nd"), unescapeCsvFields("\"a\rb\",\"c\nd\""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithCRWithoutQuote() { public void unescapeCsvFieldsWithCRWithoutQuote() {
unescapeCsvFields("a,\r"); assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\r"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithLFWithoutQuote() { public void unescapeCsvFieldsWithLFWithoutQuote() {
unescapeCsvFields("a,\r"); assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\r"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote() { public void unescapeCsvFieldsWithQuote() {
unescapeCsvFields("a,\""); assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote2() { public void unescapeCsvFieldsWithQuote2() {
unescapeCsvFields("\",a"); assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("\",a"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote3() { public void unescapeCsvFieldsWithQuote3() {
unescapeCsvFields("a\"b,a"); assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a\"b,a"));
} }
@Test @Test

View File

@ -15,28 +15,29 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SystemPropertyUtilTest { public class SystemPropertyUtilTest {
@Before @BeforeEach
public void clearSystemPropertyBeforeEach() { public void clearSystemPropertyBeforeEach() {
System.clearProperty("key"); System.clearProperty("key");
} }
@Test(expected = NullPointerException.class) @Test
public void testGetWithKeyNull() { public void testGetWithKeyNull() {
SystemPropertyUtil.get(null, null); assertThrows(NullPointerException.class, () -> SystemPropertyUtil.get(null, null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetWithKeyEmpty() { public void testGetWithKeyEmpty() {
SystemPropertyUtil.get("", null); assertThrows(IllegalArgumentException.class, () -> SystemPropertyUtil.get("", null));
} }
@Test @Test

View File

@ -17,25 +17,26 @@ package io.netty.util.internal;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.ImmediateExecutor; import io.netty.util.concurrent.ImmediateExecutor;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import static org.junit.jupiter.api.Assertions.assertSame;
public class ThreadExecutorMapTest { public class ThreadExecutorMapTest {
@Test @Test
public void testDecorateExecutor() { public void testDecorateExecutor() {
Executor executor = ThreadExecutorMap.apply(ImmediateExecutor.INSTANCE, ImmediateEventExecutor.INSTANCE); Executor executor = ThreadExecutorMap.apply(ImmediateExecutor.INSTANCE, ImmediateEventExecutor.INSTANCE);
executor.execute(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor())); executor.execute(() -> assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()));
} }
@Test @Test
public void testDecorateRunnable() { public void testDecorateRunnable() {
ThreadExecutorMap.apply(() -> ThreadExecutorMap.apply(() ->
Assert.assertSame(ImmediateEventExecutor.INSTANCE, assertSame(ImmediateEventExecutor.INSTANCE,
ThreadExecutorMap.currentExecutor()), ImmediateEventExecutor.INSTANCE).run(); ThreadExecutorMap.currentExecutor()), ImmediateEventExecutor.INSTANCE).run();
} }
@ -43,7 +44,7 @@ public class ThreadExecutorMapTest {
public void testDecorateThreadFactory() throws InterruptedException { public void testDecorateThreadFactory() throws InterruptedException {
ThreadFactory threadFactory = ThreadFactory threadFactory =
ThreadExecutorMap.apply(Executors.defaultThreadFactory(), ImmediateEventExecutor.INSTANCE); ThreadExecutorMap.apply(Executors.defaultThreadFactory(), ImmediateEventExecutor.INSTANCE);
Thread thread = threadFactory.newThread(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE, Thread thread = threadFactory.newThread(() -> assertSame(ImmediateEventExecutor.INSTANCE,
ThreadExecutorMap.currentExecutor())); ThreadExecutorMap.currentExecutor()));
thread.start(); thread.start();
thread.join(); thread.join();

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class ThreadLocalRandomTest { public class ThreadLocalRandomTest {
@ -25,10 +25,10 @@ public class ThreadLocalRandomTest {
public void getInitialSeedUniquifierPreservesInterrupt() { public void getInitialSeedUniquifierPreservesInterrupt() {
try { try {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
assertTrue("Assert that thread is interrupted before invocation of getInitialSeedUniquifier()", assertTrue(Thread.currentThread().isInterrupted(),
Thread.currentThread().isInterrupted()); "Assert that thread is interrupted before invocation of getInitialSeedUniquifier()");
assertTrue("Assert that thread is interrupted after invocation of getInitialSeedUniquifier()", assertTrue(Thread.currentThread().isInterrupted(),
Thread.currentThread().isInterrupted()); "Assert that thread is interrupted after invocation of getInitialSeedUniquifier()");
} finally { } finally {
Thread.interrupted(); // clear interrupted status in order to not affect other tests Thread.interrupted(); // clear interrupted status in order to not affect other tests
} }

View File

@ -16,11 +16,13 @@
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Date; 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 { public class TypeParameterMatcherTest {
@ -38,9 +40,9 @@ public class TypeParameterMatcherTest {
assertFalse(m.match(new CC())); assertFalse(m.match(new CC()));
} }
@Test(expected = IllegalStateException.class) @Test
public void testUnsolvedParameter() throws Exception { public void testUnsolvedParameter() throws Exception {
TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B"); assertThrows(IllegalStateException.class, () -> TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B"));
} }
@Test @Test
@ -135,10 +137,12 @@ public class TypeParameterMatcherTest {
T t; T t;
} }
@Test(expected = IllegalStateException.class) @Test
public void testErasure() throws Exception { public void testErasure() throws Exception {
TypeParameterMatcher m = TypeParameterMatcher.find(new X<String, Date>(), W.class, "E"); assertThrows(IllegalStateException.class, () -> {
assertTrue(m.match(new Date())); TypeParameterMatcher m = TypeParameterMatcher.find(new X<String, Date>(), W.class, "E");
assertFalse(m.match(new Object())); assertTrue(m.match(new Date()));
assertFalse(m.match(new Object()));
});
} }
} }

View File

@ -15,15 +15,15 @@
*/ */
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* We only need to test methods defined by {@link InternaLogger}. * We only need to test methods defined by {@link InternaLogger}.

View File

@ -15,9 +15,10 @@
*/ */
package io.netty.util.internal.logging; 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 { public class CommonsLoggerFactoryTest {

View File

@ -16,9 +16,9 @@
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import org.apache.commons.logging.Log; 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.*; import static org.mockito.Mockito.*;
public class CommonsLoggerTest { public class CommonsLoggerTest {

View File

@ -15,13 +15,14 @@
*/ */
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class InternalLoggerFactoryTest { public class InternalLoggerFactoryTest {
@ -29,7 +30,7 @@ public class InternalLoggerFactoryTest {
private InternalLoggerFactory oldLoggerFactory; private InternalLoggerFactory oldLoggerFactory;
private InternalLogger mockLogger; private InternalLogger mockLogger;
@Before @BeforeEach
public void init() { public void init() {
oldLoggerFactory = InternalLoggerFactory.getDefaultFactory(); oldLoggerFactory = InternalLoggerFactory.getDefaultFactory();
@ -39,15 +40,15 @@ public class InternalLoggerFactoryTest {
InternalLoggerFactory.setDefaultFactory(mockFactory); InternalLoggerFactory.setDefaultFactory(mockFactory);
} }
@After @AfterEach
public void destroy() { public void destroy() {
reset(mockLogger); reset(mockLogger);
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory); InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
} }
@Test(expected = NullPointerException.class) @Test
public void shouldNotAllowNullDefaultFactory() { public void shouldNotAllowNullDefaultFactory() {
InternalLoggerFactory.setDefaultFactory(null); assertThrows(NullPointerException.class, () -> InternalLoggerFactory.setDefaultFactory(null));
} }
@Test @Test

View File

@ -15,9 +15,10 @@
*/ */
package io.netty.util.internal.logging; 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 { public class JdkLoggerFactoryTest {

View File

@ -15,10 +15,10 @@
*/ */
package io.netty.util.internal.logging; 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.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class Log4J2LoggerFactoryTest { public class Log4J2LoggerFactoryTest {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util.internal.logging; 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.lang.reflect.Method;
import java.util.Arrays; 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.Marker;
import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.spi.ExtendedLoggerWrapper; import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
import org.hamcrest.CoreMatchers;
import org.junit.Assume;
import io.netty.util.internal.ReflectionUtil; import io.netty.util.internal.ReflectionUtil;
import org.junit.jupiter.api.Assumptions;
/** /**
* {@linkplain Log4J2Logger} extends {@linkplain ExtendedLoggerWrapper} implements {@linkplain InternalLogger}.<br> * {@linkplain Log4J2Logger} extends {@linkplain ExtendedLoggerWrapper} implements {@linkplain InternalLogger}.<br>
@ -66,7 +65,7 @@ public class Log4J2LoggerTest extends AbstractInternalLoggerTest<Logger> {
Method method = mockLog.getClass().getDeclaredMethod("setLevel", Level.class); Method method = mockLog.getClass().getDeclaredMethod("setLevel", Level.class);
if (!method.isAccessible()) { if (!method.isAccessible()) {
Assume.assumeThat(ReflectionUtil.trySetAccessible(method, true), CoreMatchers.nullValue()); Assumptions.assumeTrue(ReflectionUtil.trySetAccessible(method, true) == null);
} }
method.invoke(mockLog, targetLevel); method.invoke(mockLog, targetLevel);
} }

View File

@ -15,9 +15,10 @@
*/ */
package io.netty.util.internal.logging; 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 { public class Log4JLoggerFactoryTest {

View File

@ -38,9 +38,10 @@
*/ */
package io.netty.util.internal.logging; 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 { public class MessageFormatterTest {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -23,9 +23,9 @@ import org.slf4j.spi.LocationAwareLogger;
import java.util.Iterator; import java.util.Iterator;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class Slf4JLoggerFactoryTest { public class Slf4JLoggerFactoryTest {

View File

@ -15,10 +15,10 @@
*/ */
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class Slf4JLoggerTest { public class Slf4JLoggerTest {