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 Norman Maurer
parent a743b74bfb
commit 3efd9642ca
50 changed files with 962 additions and 565 deletions

View File

@ -16,7 +16,9 @@
package io.netty.util; package io.netty.util;
import io.netty.util.internal.ThreadLocalRandom; import io.netty.util.internal.ThreadLocalRandom;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
@ -24,35 +26,52 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; 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.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(); final 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, new Executable() {
@Override
public void execute() {
referenceCounted.retain();
}
});
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainOverflow2() { public void testRetainOverflow2() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); final AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertEquals(1, referenceCounted.refCnt()); assertEquals(1, referenceCounted.refCnt());
referenceCounted.retain(Integer.MAX_VALUE); assertThrows(IllegalReferenceCountException.class, new Executable() {
@Override
public void execute() {
referenceCounted.retain(Integer.MAX_VALUE);
}
});
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testReleaseOverflow() { public void testReleaseOverflow() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); final 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, new Executable() {
@Override
public void execute() {
referenceCounted.release(Integer.MAX_VALUE);
}
});
} }
@Test @Test
@ -67,23 +86,34 @@ public class AbstractReferenceCountedTest {
} }
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainResurrect() { public void testRetainResurrect() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); final AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertTrue(referenceCounted.release()); assertTrue(referenceCounted.release());
assertEquals(0, referenceCounted.refCnt()); assertEquals(0, referenceCounted.refCnt());
referenceCounted.retain(); assertThrows(IllegalReferenceCountException.class, new Executable() {
@Override
public void execute() {
referenceCounted.retain();
}
});
} }
@Test(expected = IllegalReferenceCountException.class) @Test
public void testRetainResurrect2() { public void testRetainResurrect2() {
AbstractReferenceCounted referenceCounted = newReferenceCounted(); final AbstractReferenceCounted referenceCounted = newReferenceCounted();
assertTrue(referenceCounted.release()); assertTrue(referenceCounted.release());
assertEquals(0, referenceCounted.refCnt()); assertEquals(0, referenceCounted.refCnt());
referenceCounted.retain(2); assertThrows(IllegalReferenceCountException.class, new Executable() {
@Override
public void execute() {
referenceCounted.retain(2);
}
});
} }
@Test(timeout = 30000) @Test
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception { public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception {
int threads = 4; int threads = 4;
Queue<Future<?>> futures = new ArrayDeque<Future<?>>(threads); Queue<Future<?>> futures = new ArrayDeque<Future<?>>(threads);
@ -131,7 +161,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<Future<?>>(threads); Queue<Future<?>> futures = new ArrayDeque<Future<?>>(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;
@ -25,11 +25,11 @@ import static io.netty.util.AsciiString.contains;
import static io.netty.util.AsciiString.containsIgnoreCase; import static io.netty.util.AsciiString.containsIgnoreCase;
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
@ -58,7 +58,7 @@ public class AsciiStringCharacterTest {
final Charset charset = charsets[i]; final Charset charset = charsets[i];
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);
} }
} }
@ -74,7 +74,7 @@ public class AsciiStringCharacterTest {
final Charset charset = charsets[i]; final Charset charset = charsets[i];
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);
} }
} }
@ -197,29 +197,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];
@ -84,8 +84,8 @@ public class AsciiStringMemoryTest {
aAsciiString.forEachByte(new ByteProcessor() { aAsciiString.forEachByte(new ByteProcessor() {
int i; int i;
@Override @Override
public boolean process(byte value) throws Exception { 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;
} }
@ -93,8 +93,8 @@ public class AsciiStringMemoryTest {
bAsciiString.forEachByte(new ByteProcessor() { bAsciiString.forEachByte(new ByteProcessor() {
int i; int i;
@Override @Override
public boolean process(byte value) throws Exception { 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;
} }
@ -122,8 +122,8 @@ public class AsciiStringMemoryTest {
aAsciiString.forEachByteDesc(new ByteProcessor() { aAsciiString.forEachByteDesc(new ByteProcessor() {
int i = 1; int i = 1;
@Override @Override
public boolean process(byte value) throws Exception { 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;
} }
@ -131,8 +131,8 @@ public class AsciiStringMemoryTest {
bAsciiString.forEachByteDesc(new ByteProcessor() { bAsciiString.forEachByteDesc(new ByteProcessor() {
int i = 1; int i = 1;
@Override @Override
public boolean process(byte value) throws Exception { 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,8 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -24,6 +25,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 +42,14 @@ public class ConstantPoolTest {
} }
}; };
@Test(expected = NullPointerException.class) @Test
public void testCannotProvideNullName() { public void testCannotProvideNullName() {
pool.valueOf(null); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
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,47 @@
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Map; import 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 Executable() {
@Override
public void execute() {
new DomainNameMapping<String>(null);
}
});
} }
@Test(expected = NullPointerException.class) @Test
public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() { public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() {
new DomainNameMapping<String>("NotFound").add(null, "Some value"); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
new DomainNameMapping<String>("NotFound").add(null, "Some value");
}
});
} }
@Test(expected = NullPointerException.class) @Test
public void testNullValuesAreForbiddenInDeprecatedApi() { public void testNullValuesAreForbiddenInDeprecatedApi() {
new DomainNameMapping<String>("NotFound").add("Some key", null); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
new DomainNameMapping<String>("NotFound").add("Some key", null);
}
});
} }
@Test @Test
@ -105,19 +122,35 @@ 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 Executable() {
@Override
public void execute() {
new DomainNameMappingBuilder<String>(null);
}
});
} }
@Test(expected = NullPointerException.class) @Test
public void testNullDomainNamePatternsAreForbidden() { public void testNullDomainNamePatternsAreForbidden() {
new DomainNameMappingBuilder<String>("NotFound").add(null, "Some value"); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
new DomainNameMappingBuilder<String>("NotFound").add(null, "Some value");
}
});
} }
@Test(expected = NullPointerException.class) @Test
public void testNullValuesAreForbidden() { public void testNullValuesAreForbidden() {
new DomainNameMappingBuilder<String>("NotFound").add("Some key", null);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
new DomainNameMappingBuilder<String>("NotFound").add("Some key", null);
}
});
} }
@Test @Test

View File

@ -16,27 +16,44 @@
package io.netty.util; package io.netty.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Map; import 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 Executable() {
@Override
public void execute() {
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 Executable() {
@Override
public void execute() {
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 Executable() {
@Override
public void execute() {
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 {
@ -43,7 +43,7 @@ public class HashedWheelTimerTest {
} }
}, 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();
} }
@ -58,11 +58,12 @@ public class HashedWheelTimerTest {
} }
}, 2, TimeUnit.SECONDS); }, 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();
@ -76,7 +77,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 ++) {
@ -87,10 +88,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();
@ -114,7 +116,8 @@ public class HashedWheelTimerTest {
} }
} }
@Test(timeout = 5000) @Test
@org.junit.jupiter.api.Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testTimerOverflowWheelLength() throws InterruptedException { 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);
@ -153,8 +156,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();
@ -195,7 +198,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,24 @@
*/ */
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 org.junit.jupiter.api.function.Executable;
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 +53,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();
@ -81,15 +91,20 @@ 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(); final HandledObject object = recycler.get();
object.recycle();
object.recycle(); object.recycle();
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
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();
@ -119,9 +134,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
@ -307,9 +320,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
@ -416,9 +429,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<Throwable>(); final AtomicReference<Throwable> error = new AtomicReference<Throwable>();

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() {
@ -75,7 +77,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() {
@ -117,7 +120,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<ThreadGroup>(); final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<ThreadGroup>();

View File

@ -15,15 +15,17 @@
*/ */
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.function.Executable;
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 = new Runnable() { private static final Runnable TEST_RUNNABLE = new Runnable() {
@ -71,28 +73,48 @@ public class AbstractScheduledEventExecutorTest {
assertNull(executor.pollScheduledTask()); assertNull(executor.pollScheduledTask());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleAtFixedRateRunnableZero() { public void testScheduleAtFixedRateRunnableZero() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); final TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS);
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleAtFixedRateRunnableNegative() { public void testScheduleAtFixedRateRunnableNegative() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); final TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleWithFixedDelayZero() { public void testScheduleWithFixedDelayZero() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); final TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testScheduleWithFixedDelayNegative() { public void testScheduleWithFixedDelayNegative() {
TestScheduledEventExecutor executor = new TestScheduledEventExecutor(); final TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
}
});
} }
private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor { private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor {

View File

@ -19,8 +19,10 @@ 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.junit.jupiter.api.function.Executable;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.util.HashMap; import java.util.HashMap;
@ -40,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();
@ -101,24 +108,32 @@ 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() {
final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE); final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false)); assertTrue(promise.cancel(false));
promise.get(); assertThrows(CancellationException.class, new Executable() {
} @Override
public void execute() throws Throwable {
@Test(expected = CancellationException.class) promise.get();
public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() throws InterruptedException, }
ExecutionException, TimeoutException { });
final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false));
promise.get(1, TimeUnit.SECONDS);
} }
@Test @Test
public void testCancellationExceptionIsReturnedAsCause() throws InterruptedException, public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() {
ExecutionException, TimeoutException { final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false));
assertThrows(CancellationException.class, new Executable() {
@Override
public void execute() throws Throwable {
promise.get(1, TimeUnit.SECONDS);
}
});
}
@Test
public void testCancellationExceptionIsReturnedAsCause() {
final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE); final Promise<Void> promise = new DefaultPromise<Void>(ImmediateEventExecutor.INSTANCE);
assertTrue(promise.cancel(false)); assertTrue(promise.cancel(false));
assertThat(promise.cause(), instanceOf(CancellationException.class)); assertThat(promise.cause(), instanceOf(CancellationException.class));
@ -212,11 +227,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();
@ -232,22 +247,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());
} }
@ -336,7 +355,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);
} }
} }
@ -378,7 +397,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);
} }
} }
@ -534,8 +553,8 @@ public class DefaultPromiseTest {
} }
}); });
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();
@ -117,7 +120,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(
@ -132,7 +136,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();
@ -196,7 +201,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<DefaultThreadFactory>(); final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<DefaultThreadFactory>();
@ -242,7 +248,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<DefaultThreadFactory>(); final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<DefaultThreadFactory>();
final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<ThreadGroup>(); final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<ThreadGroup>();

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<Throwable>(); final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
final Thread thread = new FastThreadLocalThread() { final Thread thread = new FastThreadLocalThread() {
@ -157,24 +161,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

@ -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<ThreadGroup>(); final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<ThreadGroup>();
@ -108,7 +112,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);
@ -129,7 +134,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,26 @@
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;
import org.junit.jupiter.api.function.Executable;
public class ImmediateExecutorTest { public class ImmediateExecutorTest {
@Test(expected = NullPointerException.class) @Test
public void testExecuteNullRunnable() { public void testExecuteNullRunnable() {
ImmediateExecutor.INSTANCE.execute(null); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
ImmediateExecutor.INSTANCE.execute(null);
}
});
} }
@Test @Test

View File

@ -16,10 +16,11 @@
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.api.function.Executable;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.ParameterizedTest;
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 +30,27 @@ 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); final EventExecutorGroup group = new DefaultEventExecutorGroup(1);
try { try {
new NonStickyEventExecutorGroup(group); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
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<Object[]>(); List<Object[]> params = new ArrayList<Object[]>();
params.add(new Object[] {64}); params.add(new Object[] {64});
@ -54,12 +60,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);
@ -94,8 +98,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);
@ -113,10 +118,10 @@ public class NonStickyEventExecutorGroupTest {
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();
@ -125,7 +130,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<Throwable>(); final AtomicReference<Throwable> cause = new AtomicReference<Throwable>();
final AtomicInteger last = new AtomicInteger(); final AtomicInteger last = new AtomicInteger();
int tasks = 10000; int tasks = 10000;

View File

@ -16,39 +16,47 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.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 Executable() {
new PromiseAggregator<Void, Future<Void>>(null); @SuppressWarnings("deprecation")
@Override
public void execute() {
new PromiseAggregator<Void, Future<Void>>(null);
}
});
} }
@Test @Test
public void testAddNullFuture() { public void testAddNullFuture() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Promise<Void> p = mock(Promise.class); Promise<Void> p = mock(Promise.class);
PromiseAggregator<Void, Future<Void>> a = @SuppressWarnings("deprecation")
final PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<Void, Future<Void>>(p); new PromiseAggregator<Void, Future<Void>>(p);
expectedException.expect(NullPointerException.class); assertThrows(NullPointerException.class, new Executable() {
a.add((Promise<Void>[]) null); @Override
public void execute() {
a.add((Promise<Void>[]) null);
}
});
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testSuccessfulNoPending() throws Exception { public void testSuccessfulNoPending() throws Exception {
Promise<Void> p = mock(Promise.class); Promise<Void> p = mock(Promise.class);
@SuppressWarnings("deprecation")
PromiseAggregator<Void, Future<Void>> a = PromiseAggregator<Void, Future<Void>> a =
new PromiseAggregator<Void, Future<Void>>(p); new PromiseAggregator<Void, Future<Void>>(p);

View File

@ -15,14 +15,16 @@
*/ */
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.junit.jupiter.api.function.Executable;
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 +56,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 +66,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 +80,59 @@ 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, new Executable() {
@Override
public void execute() {
combiner.add(null);
}
});
} }
@Test(expected = NullPointerException.class) @Test
public void testAddAllNullPromise() { public void testAddAllNullPromise() {
combiner.addAll(null); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
combiner.addAll(null);
}
});
} }
@Test(expected = IllegalStateException.class) @Test
public void testAddAfterFinish() { public void testAddAfterFinish() {
combiner.finish(p1); combiner.finish(p1);
combiner.add(p2); assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
combiner.finish(p1);
}
});
} }
@Test @Test
@ -172,14 +199,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 +215,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,33 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import static org.mockito.Mockito.*; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.junit.Rule; import 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 Executable() {
new PromiseNotifier<Void, Future<Void>>((Promise<Void>[]) null); @Override
public void execute() {
new PromiseNotifier<Void, Future<Void>>((Promise<Void>[]) null);
}
});
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testNullPromiseInArray() { public void testNullPromiseInArray() {
expectedException.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, new Executable() {
new PromiseNotifier<Void, Future<Void>>((Promise<Void>) null); @Override
public void execute() {
new PromiseNotifier<Void, Future<Void>>((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
@ -50,14 +54,15 @@ public class UnorderedThreadPoolEventExecutorTest {
// Now just check if the queue stays empty multiple times. This is needed as the submit to execute(...) // 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);
@ -87,7 +92,7 @@ public class UnorderedThreadPoolEventExecutorTest {
} }
}); });
Assert.assertEquals(expected, f.get()); assertEquals(expected, f.get());
} finally { } finally {
executor.shutdownGracefully(); executor.shutdownGracefully();
} }
@ -105,7 +110,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,14 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES; import static io.netty.util.internal.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 +96,103 @@ 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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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, new Executable() {
@Override
public void execute() {
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;
@ -26,10 +26,10 @@ import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
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);
@ -55,7 +58,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;
@ -67,7 +70,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);
@ -113,7 +117,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, new Runnable() { ObjectCleaner.register(temporaryObject, new Runnable() {

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();
@ -137,12 +141,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,8 @@
*/ */
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -33,12 +34,13 @@ import static io.netty.util.internal.StringUtil.unescapeCsv;
import static io.netty.util.internal.StringUtil.unescapeCsvFields; import static 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 +162,14 @@ public class StringUtilTest {
return sp; return sp;
} }
@Test (expected = NullPointerException.class) @Test
public void escapeCsvNull() { public void escapeCsvNull() {
StringUtil.escapeCsv(null); assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
StringUtil.escapeCsv(null);
}
});
} }
@Test @Test
@ -407,29 +414,54 @@ 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, new Executable() {
@Override
public void execute() {
unescapeCsv("\"");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithOddQuote() { public void unescapeCsvWithOddQuote() {
unescapeCsv("\"\"\""); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsv("\"\"\"");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithCRAndWithoutQuote() { public void unescapeCsvWithCRAndWithoutQuote() {
unescapeCsv("\r"); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsv("\r");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithLFAndWithoutQuote() { public void unescapeCsvWithLFAndWithoutQuote() {
unescapeCsv("\n"); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsv("\n");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvWithCommaAndWithoutQuote() { public void unescapeCsvWithCommaAndWithoutQuote() {
unescapeCsv(","); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsv(",");
}
});
} }
@Test @Test
@ -464,29 +496,54 @@ 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, new Executable() {
@Override
public void execute() {
unescapeCsvFields("a,\r");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithLFWithoutQuote() { public void unescapeCsvFieldsWithLFWithoutQuote() {
unescapeCsvFields("a,\r"); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsvFields("a,\r");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote() { public void unescapeCsvFieldsWithQuote() {
unescapeCsvFields("a,\""); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsvFields("a,\"");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote2() { public void unescapeCsvFieldsWithQuote2() {
unescapeCsvFields("\",a"); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsvFields("\",a");
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void unescapeCsvFieldsWithQuote3() { public void unescapeCsvFieldsWithQuote3() {
unescapeCsvFields("a\"b,a"); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
unescapeCsvFields("a\"b,a");
}
});
} }
@Test @Test

View File

@ -15,28 +15,40 @@
*/ */
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 org.junit.jupiter.api.function.Executable;
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, new Executable() {
@Override
public void execute() {
SystemPropertyUtil.get(null, null);
}
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetWithKeyEmpty() { public void testGetWithKeyEmpty() {
SystemPropertyUtil.get("", null); assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
SystemPropertyUtil.get("", null);
}
});
} }
@Test @Test

View File

@ -17,13 +17,14 @@ 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
@ -32,7 +33,7 @@ public class ThreadExecutorMapTest {
executor.execute(new Runnable() { executor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor());
} }
}); });
} }
@ -42,7 +43,8 @@ public class ThreadExecutorMapTest {
ThreadExecutorMap.apply(new Runnable() { ThreadExecutorMap.apply(new Runnable() {
@Override @Override
public void run() { public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); assertSame(ImmediateEventExecutor.INSTANCE,
ThreadExecutorMap.currentExecutor());
} }
}, ImmediateEventExecutor.INSTANCE).run(); }, ImmediateEventExecutor.INSTANCE).run();
} }
@ -54,7 +56,7 @@ public class ThreadExecutorMapTest {
Thread thread = threadFactory.newThread(new Runnable() { Thread thread = threadFactory.newThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()); assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor());
} }
}); });
thread.start(); thread.start();

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.*; import static org.junit.jupiter.api.Assertions.assertTrue;
public class ThreadLocalRandomTest { public class ThreadLocalRandomTest {
@ -25,11 +25,11 @@ 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()");
ThreadLocalRandom.getInitialSeedUniquifier(); ThreadLocalRandom.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,14 @@
package io.netty.util.internal; package io.netty.util.internal;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Date; import 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 +41,14 @@ 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, new Executable() {
@Override
public void execute() {
TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B");
}
});
} }
@Test @Test
@ -135,10 +143,15 @@ 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, new Executable() {
assertTrue(m.match(new Date())); @Override
assertFalse(m.match(new Object())); public void execute() {
TypeParameterMatcher m = TypeParameterMatcher.find(new X<String, Date>(), W.class, "E");
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,15 @@
*/ */
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 org.junit.jupiter.api.function.Executable;
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 +31,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 +41,20 @@ 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, new Executable() {
@Override
public void execute() {
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;
@ -24,9 +24,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 {