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:
parent
7a1e0b46b6
commit
e0b9eeb324
@ -15,7 +15,8 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
@ -24,35 +25,37 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class AbstractReferenceCountedTest {
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@Test
|
||||
public void testRetainOverflow() {
|
||||
AbstractReferenceCounted referenceCounted = newReferenceCounted();
|
||||
referenceCounted.setRefCnt(Integer.MAX_VALUE);
|
||||
assertEquals(Integer.MAX_VALUE, referenceCounted.refCnt());
|
||||
referenceCounted.retain();
|
||||
assertThrows(IllegalReferenceCountException.class, referenceCounted::retain);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@Test
|
||||
public void testRetainOverflow2() {
|
||||
AbstractReferenceCounted referenceCounted = newReferenceCounted();
|
||||
assertEquals(1, referenceCounted.refCnt());
|
||||
referenceCounted.retain(Integer.MAX_VALUE);
|
||||
assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.retain(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@Test
|
||||
public void testReleaseOverflow() {
|
||||
AbstractReferenceCounted referenceCounted = newReferenceCounted();
|
||||
referenceCounted.setRefCnt(0);
|
||||
assertEquals(0, referenceCounted.refCnt());
|
||||
referenceCounted.release(Integer.MAX_VALUE);
|
||||
assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.release(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -67,23 +70,24 @@ public class AbstractReferenceCountedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@Test
|
||||
public void testRetainResurrect() {
|
||||
AbstractReferenceCounted referenceCounted = newReferenceCounted();
|
||||
assertTrue(referenceCounted.release());
|
||||
assertEquals(0, referenceCounted.refCnt());
|
||||
referenceCounted.retain();
|
||||
assertThrows(IllegalReferenceCountException.class, referenceCounted::retain);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@Test
|
||||
public void testRetainResurrect2() {
|
||||
AbstractReferenceCounted referenceCounted = newReferenceCounted();
|
||||
assertTrue(referenceCounted.release());
|
||||
assertEquals(0, referenceCounted.refCnt());
|
||||
referenceCounted.retain(2);
|
||||
assertThrows(IllegalReferenceCountException.class, () -> referenceCounted.retain(2));
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
@Test
|
||||
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception {
|
||||
int threads = 4;
|
||||
Queue<Future<?>> futures = new ArrayDeque<>(threads);
|
||||
@ -128,7 +132,8 @@ public class AbstractReferenceCountedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
@Test
|
||||
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testReleaseFromMultipleThreadsThrowsReferenceCountException() throws Exception {
|
||||
int threads = 4;
|
||||
Queue<Future<?>> futures = new ArrayDeque<>(threads);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
@ -31,11 +31,11 @@ import static io.netty.util.CharsetUtil.UTF_16LE;
|
||||
import static io.netty.util.CharsetUtil.UTF_8;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test character encoding and case insensitivity for the {@link AsciiString} class
|
||||
@ -65,7 +65,7 @@ public class AsciiStringCharacterTest {
|
||||
for (final Charset charset : CHARSETS) {
|
||||
byte[] expected = bString.getBytes(charset);
|
||||
byte[] actual = new AsciiString(b, charset).toByteArray();
|
||||
assertArrayEquals("failure for " + charset, expected, actual);
|
||||
assertArrayEquals(expected, actual, "failure for " + charset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class AsciiStringCharacterTest {
|
||||
for (final Charset charset : CHARSETS) {
|
||||
byte[] expected = bString.getBytes(charset);
|
||||
byte[] actual = new AsciiString(bString, charset).toByteArray();
|
||||
assertArrayEquals("failure for " + charset, expected, actual);
|
||||
assertArrayEquals(expected, actual, "failure for " + charset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,29 +202,29 @@ public class AsciiStringCharacterTest {
|
||||
final String errorString = "len: " + len;
|
||||
// Test upper case hash codes are equal
|
||||
final int upperCaseExpected = upperCaseAscii.hashCode();
|
||||
assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseBuilder));
|
||||
assertEquals(errorString, upperCaseExpected, AsciiString.hashCode(upperCaseString));
|
||||
assertEquals(errorString, upperCaseExpected, upperCaseAscii.hashCode());
|
||||
assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseBuilder), errorString);
|
||||
assertEquals(upperCaseExpected, AsciiString.hashCode(upperCaseString), errorString);
|
||||
assertEquals(upperCaseExpected, upperCaseAscii.hashCode(), errorString);
|
||||
|
||||
// Test lower case hash codes are equal
|
||||
final int lowerCaseExpected = lowerCaseAscii.hashCode();
|
||||
assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii));
|
||||
assertEquals(errorString, lowerCaseExpected, AsciiString.hashCode(lowerCaseString));
|
||||
assertEquals(errorString, lowerCaseExpected, lowerCaseAscii.hashCode());
|
||||
assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseAscii), errorString);
|
||||
assertEquals(lowerCaseExpected, AsciiString.hashCode(lowerCaseString), errorString);
|
||||
assertEquals(lowerCaseExpected, lowerCaseAscii.hashCode(), errorString);
|
||||
|
||||
// Test case insensitive hash codes are equal
|
||||
final int expectedCaseInsensitive = lowerCaseAscii.hashCode();
|
||||
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder));
|
||||
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseString));
|
||||
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString));
|
||||
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii));
|
||||
assertEquals(errorString, expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii));
|
||||
assertEquals(errorString, expectedCaseInsensitive, lowerCaseAscii.hashCode());
|
||||
assertEquals(errorString, expectedCaseInsensitive, upperCaseAscii.hashCode());
|
||||
assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseBuilder), errorString);
|
||||
assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseString), errorString);
|
||||
assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseString), errorString);
|
||||
assertEquals(expectedCaseInsensitive, AsciiString.hashCode(lowerCaseAscii), errorString);
|
||||
assertEquals(expectedCaseInsensitive, AsciiString.hashCode(upperCaseAscii), errorString);
|
||||
assertEquals(expectedCaseInsensitive, lowerCaseAscii.hashCode(), errorString);
|
||||
assertEquals(expectedCaseInsensitive, upperCaseAscii.hashCode(), errorString);
|
||||
|
||||
// Test that opposite cases are equal
|
||||
assertEquals(errorString, lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString));
|
||||
assertEquals(errorString, upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString));
|
||||
assertEquals(lowerCaseAscii.hashCode(), AsciiString.hashCode(upperCaseString), errorString);
|
||||
assertEquals(upperCaseAscii.hashCode(), AsciiString.hashCode(lowerCaseString), errorString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,15 +15,15 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import io.netty.util.ByteProcessor.IndexOfProcessor;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test the underlying memory methods for the {@link AsciiString} class.
|
||||
@ -38,7 +38,7 @@ public class AsciiStringMemoryTest {
|
||||
private AsciiString bAsciiString;
|
||||
private Random r = new Random();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
a = new byte[128];
|
||||
b = new byte[256];
|
||||
@ -85,7 +85,7 @@ public class AsciiStringMemoryTest {
|
||||
int i;
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@ -94,7 +94,7 @@ public class AsciiStringMemoryTest {
|
||||
int i;
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@ -123,7 +123,7 @@ public class AsciiStringMemoryTest {
|
||||
int i = 1;
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@ -132,7 +132,7 @@ public class AsciiStringMemoryTest {
|
||||
int i = 1;
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
@ -15,9 +15,13 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class AttributeKeyTest {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@ -24,6 +24,7 @@ import java.util.TreeSet;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class ConstantPoolTest {
|
||||
|
||||
@ -40,9 +41,9 @@ public class ConstantPoolTest {
|
||||
}
|
||||
};
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testCannotProvideNullName() {
|
||||
pool.valueOf(null);
|
||||
assertThrows(NullPointerException.class, () -> pool.valueOf(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,16 +15,22 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DefaultAttributeMapTest {
|
||||
|
||||
private DefaultAttributeMap map;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
map = new DefaultAttributeMap();
|
||||
}
|
||||
|
@ -16,30 +16,31 @@
|
||||
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DomainNameMappingTest {
|
||||
|
||||
// Deprecated API
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDefaultValueInDeprecatedApi() {
|
||||
new DomainNameMapping<String>(null);
|
||||
assertThrows(NullPointerException.class, () -> new DomainNameMapping<String>(null));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDomainNamePatternsAreForbiddenInDeprecatedApi() {
|
||||
new DomainNameMapping<>("NotFound").add(null, "Some value");
|
||||
assertThrows(NullPointerException.class, () -> new DomainNameMapping<>("NotFound").add(null, "Some value"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullValuesAreForbiddenInDeprecatedApi() {
|
||||
new DomainNameMapping<>("NotFound").add("Some key", null);
|
||||
assertThrows(NullPointerException.class, () -> new DomainNameMapping<>("NotFound").add("Some key", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -105,19 +106,21 @@ public class DomainNameMappingTest {
|
||||
|
||||
// Immutable DomainNameMapping Builder API
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDefaultValue() {
|
||||
new DomainNameMappingBuilder<String>(null);
|
||||
assertThrows(NullPointerException.class, () -> new DomainNameMappingBuilder<String>(null));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDomainNamePatternsAreForbidden() {
|
||||
new DomainNameMappingBuilder<>("NotFound").add(null, "Some value");
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new DomainNameMappingBuilder<>("NotFound").add(null, "Some value"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullValuesAreForbidden() {
|
||||
new DomainNameMappingBuilder<>("NotFound").add("Some key", null);
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new DomainNameMappingBuilder<>("NotFound").add("Some key", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,27 +16,30 @@
|
||||
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class DomainWildcardMappingBuilderTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDefaultValue() {
|
||||
new DomainWildcardMappingBuilder<String>(null);
|
||||
assertThrows(NullPointerException.class, () -> new DomainWildcardMappingBuilder<String>(null));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullDomainNamePatternsAreForbidden() {
|
||||
new DomainWildcardMappingBuilder<String>("NotFound").add(null, "Some value");
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new DomainWildcardMappingBuilder<String>("NotFound").add(null, "Some value"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullValuesAreForbidden() {
|
||||
new DomainWildcardMappingBuilder<String>("NotFound").add("Some key", null);
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new DomainWildcardMappingBuilder<String>("NotFound").add("Some key", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@ -24,10 +24,10 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class HashedWheelTimerTest {
|
||||
|
||||
@ -40,7 +40,7 @@ public class HashedWheelTimerTest {
|
||||
barrier.countDown();
|
||||
}, 10, TimeUnit.SECONDS);
|
||||
assertFalse(barrier.await(3, TimeUnit.SECONDS));
|
||||
assertFalse("timer should not expire", timeout.isExpired());
|
||||
assertFalse(timeout.isExpired(), "timer should not expire");
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@ -50,11 +50,12 @@ public class HashedWheelTimerTest {
|
||||
final CountDownLatch barrier = new CountDownLatch(1);
|
||||
final Timeout timeout = timer.newTimeout(timeout1 -> barrier.countDown(), 2, TimeUnit.SECONDS);
|
||||
assertTrue(barrier.await(3, TimeUnit.SECONDS));
|
||||
assertTrue("timer should expire", timeout.isExpired());
|
||||
assertTrue(timeout.isExpired(), "timer should expire");
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 3000)
|
||||
@Test
|
||||
@org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testStopTimer() throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(3);
|
||||
final Timer timerProcessed = new HashedWheelTimer();
|
||||
@ -63,7 +64,7 @@ public class HashedWheelTimerTest {
|
||||
}
|
||||
|
||||
latch.await();
|
||||
assertEquals("Number of unprocessed timeouts should be 0", 0, timerProcessed.stop().size());
|
||||
assertEquals(0, timerProcessed.stop().size(), "Number of unprocessed timeouts should be 0");
|
||||
|
||||
final Timer timerUnprocessed = new HashedWheelTimer();
|
||||
for (int i = 0; i < 5; i ++) {
|
||||
@ -71,10 +72,11 @@ public class HashedWheelTimerTest {
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
Thread.sleep(1000L); // sleep for a second
|
||||
assertFalse("Number of unprocessed timeouts should be greater than 0", timerUnprocessed.stop().isEmpty());
|
||||
assertFalse(timerUnprocessed.stop().isEmpty(), "Number of unprocessed timeouts should be greater than 0");
|
||||
}
|
||||
|
||||
@Test(timeout = 3000)
|
||||
@Test
|
||||
@org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testTimerShouldThrowExceptionAfterShutdownForNewTimeouts() throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(3);
|
||||
final Timer timer = new HashedWheelTimer();
|
||||
@ -93,7 +95,8 @@ public class HashedWheelTimerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@org.junit.jupiter.api.Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testTimerOverflowWheelLength() throws InterruptedException {
|
||||
final HashedWheelTimer timer = new HashedWheelTimer(
|
||||
Executors.defaultThreadFactory(), 100, TimeUnit.MILLISECONDS, 32);
|
||||
@ -128,8 +131,8 @@ public class HashedWheelTimerTest {
|
||||
|
||||
for (int i = 0; i < scheduledTasks; i++) {
|
||||
long delay = queue.take();
|
||||
assertTrue("Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout,
|
||||
delay >= timeout && delay < maxTimeout);
|
||||
assertTrue(delay >= timeout && delay < maxTimeout,
|
||||
"Timeout + " + scheduledTasks + " delay " + delay + " must be " + timeout + " < " + maxTimeout);
|
||||
}
|
||||
|
||||
timer.stop();
|
||||
@ -170,7 +173,8 @@ public class HashedWheelTimerTest {
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 3000)
|
||||
@Test
|
||||
@org.junit.jupiter.api.Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testNewTimeoutShouldStopThrowingRejectedExecutionExceptionWhenExistingTimeoutIsExecuted()
|
||||
throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
@ -28,11 +28,11 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static io.netty.util.NetUtil.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NetUtilTest {
|
||||
|
||||
@ -611,72 +611,72 @@ public class NetUtilTest {
|
||||
@Test
|
||||
public void testIsValidIpV4Address() {
|
||||
for (String host : validIpV4Hosts.keySet()) {
|
||||
assertTrue(host, isValidIpV4Address(host));
|
||||
assertTrue(isValidIpV4Address(host), host);
|
||||
}
|
||||
for (String host : invalidIpV4Hosts.keySet()) {
|
||||
assertFalse(host, isValidIpV4Address(host));
|
||||
assertFalse(isValidIpV4Address(host), host);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsValidIpV6Address() {
|
||||
for (String host : validIpV6Hosts.keySet()) {
|
||||
assertTrue(host, isValidIpV6Address(host));
|
||||
assertTrue(isValidIpV6Address(host), host);
|
||||
if (host.charAt(0) != '[' && !host.contains("%")) {
|
||||
assertNotNull(host, getByName(host, true));
|
||||
assertNotNull(getByName(host, true), host);
|
||||
|
||||
String hostMod = '[' + host + ']';
|
||||
assertTrue(hostMod, isValidIpV6Address(hostMod));
|
||||
assertTrue(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = host + '%';
|
||||
assertTrue(hostMod, isValidIpV6Address(hostMod));
|
||||
assertTrue(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = host + "%eth1";
|
||||
assertTrue(hostMod, isValidIpV6Address(hostMod));
|
||||
assertTrue(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "%]";
|
||||
assertTrue(hostMod, isValidIpV6Address(hostMod));
|
||||
assertTrue(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "%1]";
|
||||
assertTrue(hostMod, isValidIpV6Address(hostMod));
|
||||
assertTrue(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "]%";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "]%1";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
}
|
||||
}
|
||||
for (String host : invalidIpV6Hosts.keySet()) {
|
||||
assertFalse(host, isValidIpV6Address(host));
|
||||
assertNull(host, getByName(host));
|
||||
assertFalse(isValidIpV6Address(host), host);
|
||||
assertNull(getByName(host), host);
|
||||
|
||||
String hostMod = '[' + host + ']';
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = host + '%';
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = host + "%eth1";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "%]";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "%1]";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "]%";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host + "]%1";
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = host + ']';
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
|
||||
hostMod = '[' + host;
|
||||
assertFalse(hostMod, isValidIpV6Address(hostMod));
|
||||
assertFalse(isValidIpV6Address(hostMod), hostMod);
|
||||
}
|
||||
}
|
||||
|
||||
@ -737,19 +737,19 @@ public class NetUtilTest {
|
||||
String srcIp = testEntry.getKey();
|
||||
String dstIp = testEntry.getValue();
|
||||
Inet6Address inet6Address = getByName(srcIp, true);
|
||||
assertNotNull(srcIp + ", " + dstIp, inet6Address);
|
||||
assertEquals(srcIp, dstIp, toAddressString(inet6Address, true));
|
||||
assertNotNull(inet6Address, srcIp + ", " + dstIp);
|
||||
assertEquals(dstIp, toAddressString(inet6Address, true), srcIp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidIpv4MappedIp6GetByName() {
|
||||
for (String host : invalidIpV4Hosts.keySet()) {
|
||||
assertNull(host, getByName(host, true));
|
||||
assertNull(getByName(host, true), host);
|
||||
}
|
||||
|
||||
for (String host : invalidIpV6Hosts.keySet()) {
|
||||
assertNull(host, getByName(host, true));
|
||||
assertNull(getByName(host, true), host);
|
||||
}
|
||||
}
|
||||
|
||||
@ -770,7 +770,7 @@ public class NetUtilTest {
|
||||
}
|
||||
|
||||
private static void assertHexDumpEquals(String expected, byte[] actual, String message) {
|
||||
assertEquals(message, expected, hex(actual));
|
||||
assertEquals(expected, hex(actual), message);
|
||||
}
|
||||
|
||||
private static String hex(byte[] value) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
@ -27,9 +27,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasToString;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class NettyRuntimeTests {
|
||||
|
||||
|
@ -15,15 +15,23 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class RecyclerTest {
|
||||
|
||||
@ -44,7 +52,8 @@ public class RecyclerTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(timeout = 5000L)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() throws Exception {
|
||||
final Recycler<HandledObject> recycler = newRecycler(1024);
|
||||
final AtomicBoolean collected = new AtomicBoolean();
|
||||
@ -78,15 +87,15 @@ public class RecyclerTest {
|
||||
reference.getAndSet(null).recycle();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testMultipleRecycle() {
|
||||
Recycler<HandledObject> recycler = newRecycler(1024);
|
||||
HandledObject object = recycler.get();
|
||||
object.recycle();
|
||||
object.recycle();
|
||||
assertThrows(IllegalStateException.class, object::recycle);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testMultipleRecycleAtDifferentThread() throws InterruptedException {
|
||||
Recycler<HandledObject> recycler = newRecycler(1024);
|
||||
final HandledObject object = recycler.get();
|
||||
@ -108,9 +117,7 @@ public class RecyclerTest {
|
||||
HandledObject b = recycler.get();
|
||||
assertNotSame(a, b);
|
||||
IllegalStateException exception = exceptionStore.get();
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
assertNotNull(exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -296,9 +303,9 @@ public class RecyclerTest {
|
||||
objects[i] = null;
|
||||
}
|
||||
|
||||
assertTrue("The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity ("
|
||||
+ maxCapacity + ") as we not pool all new handles internally",
|
||||
maxCapacity >= recycler.threadLocalCapacity());
|
||||
assertTrue(maxCapacity >= recycler.threadLocalCapacity(),
|
||||
"The threadLocalCapacity (" + recycler.threadLocalCapacity() + ") must be <= maxCapacity ("
|
||||
+ maxCapacity + ") as we not pool all new handles internally");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -405,9 +412,10 @@ public class RecyclerTest {
|
||||
}
|
||||
|
||||
// The implementation uses maxCapacity / 2 as limit per WeakOrderQueue
|
||||
assertTrue("The instances count (" + instancesCount.get() + ") must be <= array.length (" + array.length
|
||||
assertTrue(array.length - maxCapacity / 2 <= instancesCount.get(),
|
||||
"The instances count (" + instancesCount.get() + ") must be <= array.length (" + array.length
|
||||
+ ") - maxCapacity (" + maxCapacity + ") / 2 as we not pool all new handles" +
|
||||
" internally", array.length - maxCapacity / 2 <= instancesCount.get());
|
||||
" internally");
|
||||
}
|
||||
|
||||
static final class HandledObject {
|
||||
|
@ -15,17 +15,20 @@
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ResourceLeakDetectorTest {
|
||||
|
||||
@Test(timeout = 60000)
|
||||
@Test
|
||||
@Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testConcurrentUsage() throws Throwable {
|
||||
final AtomicBoolean finished = new AtomicBoolean();
|
||||
final AtomicReference<Throwable> error = new AtomicReference<>();
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
package io.netty.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -25,12 +26,13 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ThreadDeathWatcherTest {
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testWatch() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final Thread t = new Thread() {
|
||||
@ -72,7 +74,8 @@ public class ThreadDeathWatcherTest {
|
||||
latch.await();
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testUnwatch() throws Exception {
|
||||
final AtomicBoolean run = new AtomicBoolean();
|
||||
final Thread t = new Thread() {
|
||||
@ -109,7 +112,8 @@ public class ThreadDeathWatcherTest {
|
||||
assertThat(run.get(), is(false));
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testThreadGroup() throws InterruptedException {
|
||||
final ThreadGroup group = new ThreadGroup("group");
|
||||
final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>();
|
||||
|
@ -15,16 +15,16 @@
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class AbstractScheduledEventExecutorTest {
|
||||
private static final Runnable TEST_RUNNABLE = () -> {
|
||||
@ -68,33 +68,37 @@ public class AbstractScheduledEventExecutorTest {
|
||||
assertNull(executor.pollScheduledTask());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testScheduleAtFixedRateRunnableZero() {
|
||||
TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
|
||||
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, 0, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testScheduleAtFixedRateRunnableNegative() {
|
||||
TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
|
||||
executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> executor.scheduleAtFixedRate(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testScheduleWithFixedDelayZero() {
|
||||
TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
|
||||
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testScheduleWithFixedDelayNegative() {
|
||||
TestScheduledEventExecutor executor = new TestScheduledEventExecutor();
|
||||
executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> executor.scheduleWithFixedDelay(TEST_RUNNABLE, 0, -1, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeadlineNanosNotOverflow() {
|
||||
Assert.assertEquals(Long.MAX_VALUE, AbstractScheduledEventExecutor.deadlineNanos(Long.MAX_VALUE));
|
||||
assertEquals(Long.MAX_VALUE, AbstractScheduledEventExecutor.deadlineNanos(Long.MAX_VALUE));
|
||||
}
|
||||
|
||||
private static final class TestScheduledEventExecutor extends AbstractScheduledEventExecutor {
|
||||
|
@ -15,10 +15,9 @@
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -31,12 +30,13 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class DefaultFutureCompletionStageTest {
|
||||
|
||||
@ -47,13 +47,13 @@ public class DefaultFutureCompletionStageTest {
|
||||
private static final Boolean INITIAL_BOOLEAN = Boolean.TRUE;
|
||||
private static final Boolean EXPECTED_BOOLEAN = Boolean.FALSE;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
group = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory());
|
||||
asyncExecutorGroup = new MultithreadEventExecutorGroup(1, Executors.defaultThreadFactory());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void destroy() {
|
||||
group.shutdownGracefully();
|
||||
asyncExecutorGroup.shutdownGracefully();
|
||||
@ -84,12 +84,12 @@ public class DefaultFutureCompletionStageTest {
|
||||
assertSame(promise, stage.future());
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void testThrowsUnsupportedOperationException() {
|
||||
EventExecutor executor = executor();
|
||||
Promise<Boolean> promise = executor.newPromise();
|
||||
FutureCompletionStage<Boolean> stage = new DefaultFutureCompletionStage<>(promise);
|
||||
stage.toCompletableFuture();
|
||||
assertThrows(UnsupportedOperationException.class, () -> stage.toCompletableFuture());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -19,8 +19,9 @@ package io.netty.util.concurrent;
|
||||
import io.netty.util.Signal;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -41,14 +42,19 @@ import static java.lang.Math.max;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DefaultPromiseTest {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultPromiseTest.class);
|
||||
private static int stackOverflowDepth;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
findStackOverflowDepth();
|
||||
@ -102,19 +108,19 @@ public class DefaultPromiseTest {
|
||||
assertSame(cause, promise.cause());
|
||||
}
|
||||
|
||||
@Test(expected = CancellationException.class)
|
||||
@Test
|
||||
public void testCancellationExceptionIsThrownWhenBlockingGet() throws InterruptedException, ExecutionException {
|
||||
final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
|
||||
assertTrue(promise.cancel(false));
|
||||
promise.get();
|
||||
assertThrows(CancellationException.class, promise::get);
|
||||
}
|
||||
|
||||
@Test(expected = CancellationException.class)
|
||||
@Test
|
||||
public void testCancellationExceptionIsThrownWhenBlockingGetWithTimeout() throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
final Promise<Void> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
|
||||
assertTrue(promise.cancel(false));
|
||||
promise.get(1, TimeUnit.SECONDS);
|
||||
assertThrows(CancellationException.class, () -> promise.get(1, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -208,11 +214,11 @@ public class DefaultPromiseTest {
|
||||
|
||||
promise.addListener(listener1).addListener(listener2).addListener(listener3);
|
||||
|
||||
assertSame("Fail 1 during run " + i + " / " + runs, listener1, listeners.take());
|
||||
assertSame("Fail 2 during run " + i + " / " + runs, listener2, listeners.take());
|
||||
assertSame("Fail 3 during run " + i + " / " + runs, listener3, listeners.take());
|
||||
assertSame("Fail 4 during run " + i + " / " + runs, listener4, listeners.take());
|
||||
assertTrue("Fail during run " + i + " / " + runs, listeners.isEmpty());
|
||||
assertSame(listener1, listeners.take(), "Fail 1 during run " + i + " / " + runs);
|
||||
assertSame(listener2, listeners.take(), "Fail 2 during run " + i + " / " + runs);
|
||||
assertSame(listener3, listeners.take(), "Fail 3 during run " + i + " / " + runs);
|
||||
assertSame(listener4, listeners.take(), "Fail 4 during run " + i + " / " + runs);
|
||||
assertTrue(listeners.isEmpty(), "Fail during run " + i + " / " + runs);
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync();
|
||||
@ -228,22 +234,26 @@ public class DefaultPromiseTest {
|
||||
testListenerNotifyLater(2);
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testPromiseListenerAddWhenCompleteFailure() throws Exception {
|
||||
testPromiseListenerAddWhenComplete(fakeException());
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testPromiseListenerAddWhenCompleteSuccess() throws Exception {
|
||||
testPromiseListenerAddWhenComplete(null);
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testLateListenerIsOrderedCorrectlySuccess() throws InterruptedException {
|
||||
testLateListenerIsOrderedCorrectly(null);
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testLateListenerIsOrderedCorrectlyFailure() throws InterruptedException {
|
||||
testLateListenerIsOrderedCorrectly(fakeException());
|
||||
}
|
||||
@ -334,11 +344,11 @@ public class DefaultPromiseTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = CancellationException.class)
|
||||
@Test
|
||||
public void throwCancelled() throws InterruptedException {
|
||||
final Promise<String> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
|
||||
promise.cancel(true);
|
||||
promise.sync();
|
||||
assertThrows(CancellationException.class, promise::sync);
|
||||
}
|
||||
|
||||
private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor,
|
||||
@ -355,7 +365,7 @@ public class DefaultPromiseTest {
|
||||
|
||||
assertTrue(latch.await(2, TimeUnit.SECONDS));
|
||||
for (int i = 0; i < p.length; ++i) {
|
||||
assertTrue("index " + i, p[i].isSuccess());
|
||||
assertTrue(p[i].isSuccess(), "index " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,7 +399,7 @@ public class DefaultPromiseTest {
|
||||
|
||||
assertTrue(latch.await(2, TimeUnit.SECONDS));
|
||||
for (int i = 0; i < p.length; ++i) {
|
||||
assertTrue("index " + i, p[i].isSuccess());
|
||||
assertTrue(p[i].isSuccess(), "index " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -499,8 +509,8 @@ public class DefaultPromiseTest {
|
||||
promise.addListener(listener);
|
||||
});
|
||||
|
||||
assertTrue("Should have notified " + expectedCount + " listeners",
|
||||
latch.await(5, TimeUnit.SECONDS));
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS),
|
||||
"Should have notified " + expectedCount + " listeners");
|
||||
executor.shutdownGracefully().sync();
|
||||
}
|
||||
|
||||
|
@ -16,20 +16,23 @@
|
||||
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.security.Permission;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DefaultThreadFactoryTest {
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testDescendantThreadGroups() throws InterruptedException {
|
||||
final SecurityManager current = System.getSecurityManager();
|
||||
|
||||
@ -106,7 +109,8 @@ public class DefaultThreadFactoryTest {
|
||||
|
||||
// test that when DefaultThreadFactory is constructed with a sticky thread group, threads
|
||||
// created by it have the sticky thread group
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testDefaultThreadFactoryStickyThreadGroupConstructor() throws InterruptedException {
|
||||
final ThreadGroup sticky = new ThreadGroup("sticky");
|
||||
runStickyThreadGroupTest(
|
||||
@ -116,7 +120,8 @@ public class DefaultThreadFactoryTest {
|
||||
|
||||
// test that when a security manager is installed that provides a ThreadGroup, DefaultThreadFactory inherits from
|
||||
// the security manager
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testDefaultThreadFactoryInheritsThreadGroupFromSecurityManager() throws InterruptedException {
|
||||
final SecurityManager current = System.getSecurityManager();
|
||||
|
||||
@ -169,7 +174,8 @@ public class DefaultThreadFactoryTest {
|
||||
|
||||
// test that when DefaultThreadFactory is constructed without a sticky thread group, threads
|
||||
// created by it inherit the correct thread group
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testDefaultThreadFactoryNonStickyThreadGroupConstructor() throws InterruptedException {
|
||||
|
||||
final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>();
|
||||
@ -203,7 +209,8 @@ public class DefaultThreadFactoryTest {
|
||||
|
||||
// test that when DefaultThreadFactory is constructed without a sticky thread group, threads
|
||||
// created by it inherit the correct thread group
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testCurrentThreadGroupIsUsed() throws InterruptedException {
|
||||
final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<>();
|
||||
final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<>();
|
||||
|
@ -17,22 +17,24 @@
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import io.netty.util.internal.ObjectCleaner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class FastThreadLocalTest {
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
FastThreadLocal.removeAll();
|
||||
assertThat(FastThreadLocal.size(), is(0));
|
||||
@ -55,7 +57,8 @@ public class FastThreadLocalTest {
|
||||
assertNull(threadLocal.getIfExists());
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testRemoveAll() throws Exception {
|
||||
final AtomicBoolean removed = new AtomicBoolean();
|
||||
final FastThreadLocal<Boolean> var = new FastThreadLocal<Boolean>() {
|
||||
@ -75,7 +78,8 @@ public class FastThreadLocalTest {
|
||||
assertThat(FastThreadLocal.size(), is(0));
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testRemoveAllFromFTLThread() throws Throwable {
|
||||
final AtomicReference<Throwable> throwable = new AtomicReference<>();
|
||||
final Thread thread = new FastThreadLocalThread() {
|
||||
@ -151,24 +155,28 @@ public class FastThreadLocalTest {
|
||||
assertEquals(0, ObjectCleaner.getLiveSetCount() - sizeWhenStart);
|
||||
}
|
||||
|
||||
@Test(timeout = 4000)
|
||||
@Test
|
||||
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testOnRemoveCalledForFastThreadLocalGet() throws Exception {
|
||||
testOnRemoveCalled(true, true);
|
||||
}
|
||||
|
||||
@Ignore("onRemoval(...) not called with non FastThreadLocal")
|
||||
@Test(timeout = 4000)
|
||||
@Disabled("onRemoval(...) not called with non FastThreadLocal")
|
||||
@Test
|
||||
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testOnRemoveCalledForNonFastThreadLocalGet() throws Exception {
|
||||
testOnRemoveCalled(false, true);
|
||||
}
|
||||
|
||||
@Test(timeout = 4000)
|
||||
@Test
|
||||
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testOnRemoveCalledForFastThreadLocalSet() throws Exception {
|
||||
testOnRemoveCalled(true, false);
|
||||
}
|
||||
|
||||
@Ignore("onRemoval(...) not called with non FastThreadLocal")
|
||||
@Test(timeout = 4000)
|
||||
@Disabled("onRemoval(...) not called with non FastThreadLocal")
|
||||
@Test
|
||||
@Timeout(value = 4000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testOnRemoveCalledForNonFastThreadLocalSet() throws Exception {
|
||||
testOnRemoveCalled(false, false);
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
public class FutureCompletionStageTest {
|
||||
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -28,13 +29,13 @@ import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GlobalEventExecutorTest {
|
||||
|
||||
private static final GlobalEventExecutor e = GlobalEventExecutor.INSTANCE;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
// Wait until the global executor is stopped (just in case there is a task running due to previous test cases)
|
||||
for (;;) {
|
||||
@ -46,7 +47,8 @@ public class GlobalEventExecutorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testAutomaticStartStop() throws Exception {
|
||||
final TestRunnable task = new TestRunnable(500);
|
||||
e.execute(task);
|
||||
@ -70,7 +72,8 @@ public class GlobalEventExecutorTest {
|
||||
assertThat(task.ran.get(), is(true));
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testScheduledTasks() throws Exception {
|
||||
TestRunnable task = new TestRunnable(0);
|
||||
ScheduledFuture<?> f = e.schedule(task, 1500, TimeUnit.MILLISECONDS);
|
||||
@ -87,7 +90,8 @@ public class GlobalEventExecutorTest {
|
||||
|
||||
// ensure that when a task submission causes a new thread to be created, the thread inherits the thread group of the
|
||||
// submitting thread
|
||||
@Test(timeout = 2000)
|
||||
@Test
|
||||
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testThreadGroup() throws InterruptedException {
|
||||
final ThreadGroup group = new ThreadGroup("group");
|
||||
final AtomicReference<ThreadGroup> capturedGroup = new AtomicReference<>();
|
||||
@ -102,7 +106,8 @@ public class GlobalEventExecutorTest {
|
||||
assertEquals(group, capturedGroup.get());
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testTakeTask() throws Exception {
|
||||
//add task
|
||||
TestRunnable beforeTask = new TestRunnable(0);
|
||||
@ -123,7 +128,8 @@ public class GlobalEventExecutorTest {
|
||||
assertThat(afterTask.ran.get(), is(true));
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testTakeTaskAlwaysHasTask() throws Exception {
|
||||
//for https://github.com/netty/netty/issues/1614
|
||||
//add scheduled task
|
||||
|
@ -16,19 +16,20 @@
|
||||
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ImmediateExecutorTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testExecuteNullRunnable() {
|
||||
ImmediateExecutor.INSTANCE.execute(null);
|
||||
assertThrows(NullPointerException.class, () -> ImmediateExecutor.INSTANCE.execute(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,10 +16,10 @@
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import io.netty.util.NettyRuntime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -29,22 +29,22 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NonStickyEventExecutorGroupTest {
|
||||
private static final String PARAMETERIZED_NAME = "{index}: maxTaskExecutePerRun = {0}";
|
||||
|
||||
private final int maxTaskExecutePerRun;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testInvalidGroup() {
|
||||
EventExecutorGroup group = new DefaultEventExecutorGroup(1);
|
||||
try {
|
||||
new NonStickyEventExecutorGroup(group);
|
||||
assertThrows(IllegalArgumentException.class, () -> new NonStickyEventExecutorGroup(group));
|
||||
} finally {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: maxTaskExecutePerRun = {0}")
|
||||
public static Collection<Object[]> data() throws Exception {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
params.add(new Object[] {64});
|
||||
@ -54,12 +54,10 @@ public class NonStickyEventExecutorGroupTest {
|
||||
return params;
|
||||
}
|
||||
|
||||
public NonStickyEventExecutorGroupTest(int maxTaskExecutePerRun) {
|
||||
this.maxTaskExecutePerRun = maxTaskExecutePerRun;
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testOrdering() throws Throwable {
|
||||
@ParameterizedTest(name = PARAMETERIZED_NAME)
|
||||
@MethodSource("data")
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testOrdering(int maxTaskExecutePerRun) throws Throwable {
|
||||
final int threads = NettyRuntime.availableProcessors() * 2;
|
||||
final EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(threads);
|
||||
final NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun);
|
||||
@ -91,8 +89,9 @@ public class NonStickyEventExecutorGroupTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaceCondition() throws InterruptedException {
|
||||
@ParameterizedTest(name = PARAMETERIZED_NAME)
|
||||
@MethodSource("data")
|
||||
public void testRaceCondition(int maxTaskExecutePerRun) throws InterruptedException {
|
||||
EventExecutorGroup group = new UnorderedThreadPoolEventExecutor(1);
|
||||
NonStickyEventExecutorGroup nonStickyGroup = new NonStickyEventExecutorGroup(group, maxTaskExecutePerRun);
|
||||
|
||||
@ -107,10 +106,10 @@ public class NonStickyEventExecutorGroupTest {
|
||||
firstCompleted.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 {
|
||||
nonStickyGroup.shutdownGracefully();
|
||||
@ -119,7 +118,7 @@ public class NonStickyEventExecutorGroupTest {
|
||||
|
||||
private static void execute(EventExecutorGroup group, CountDownLatch startLatch) throws Throwable {
|
||||
EventExecutor executor = group.next();
|
||||
Assert.assertTrue(executor instanceof OrderedEventExecutor);
|
||||
assertTrue(executor instanceof OrderedEventExecutor);
|
||||
final AtomicReference<Throwable> cause = new AtomicReference<>();
|
||||
final AtomicInteger last = new AtomicInteger();
|
||||
int tasks = 10000;
|
||||
|
@ -16,23 +16,18 @@
|
||||
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class PromiseAggregatorTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testNullAggregatePromise() {
|
||||
expectedException.expect(NullPointerException.class);
|
||||
new PromiseAggregator<Void, Future<Void>>(null);
|
||||
assertThrows(NullPointerException.class, () -> new PromiseAggregator<Void, Future<Void>>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -41,8 +36,7 @@ public class PromiseAggregatorTest {
|
||||
Promise<Void> p = mock(Promise.class);
|
||||
PromiseAggregator<Void, Future<Void>> a =
|
||||
new PromiseAggregator<>(p);
|
||||
expectedException.expect(NullPointerException.class);
|
||||
a.add((Promise<Void>[]) null);
|
||||
assertThrows(NullPointerException.class, () -> a.add((Promise<Void>[]) null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -15,14 +15,15 @@
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@ -54,7 +55,7 @@ public class PromiseCombinerTest {
|
||||
private Promise<Void> p3;
|
||||
private PromiseCombiner combiner;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
combiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE);
|
||||
@ -64,7 +65,7 @@ public class PromiseCombinerTest {
|
||||
public void testNullArgument() {
|
||||
try {
|
||||
combiner.finish(null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (NullPointerException expected) {
|
||||
// expected
|
||||
}
|
||||
@ -78,34 +79,34 @@ public class PromiseCombinerTest {
|
||||
verify(p1).trySuccess(null);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testAddNullPromise() {
|
||||
combiner.add(null);
|
||||
assertThrows(NullPointerException.class, () -> combiner.add(null));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testAddAllNullPromise() {
|
||||
combiner.addAll(null);
|
||||
assertThrows(NullPointerException.class, () -> combiner.addAll(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testAddAfterFinish() {
|
||||
combiner.finish(p1);
|
||||
combiner.add(p2);
|
||||
assertThrows(IllegalStateException.class, () -> combiner.add(p2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testAddAllAfterFinish() {
|
||||
combiner.finish(p1);
|
||||
combiner.addAll(p2);
|
||||
assertThrows(IllegalStateException.class, () -> combiner.addAll(p2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testFinishCalledTwiceThrows() {
|
||||
combiner.finish(p1);
|
||||
combiner.finish(p1);
|
||||
assertThrows(IllegalStateException.class, () -> combiner.finish(p1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -172,14 +173,14 @@ public class PromiseCombinerTest {
|
||||
|
||||
try {
|
||||
combiner.add(future);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalStateException expected) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
combiner.addAll(future);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalStateException expected) {
|
||||
// expected
|
||||
}
|
||||
@ -188,7 +189,7 @@ public class PromiseCombinerTest {
|
||||
Promise<Void> promise = (Promise<Void>) mock(Promise.class);
|
||||
try {
|
||||
combiner.finish(promise);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (IllegalStateException expected) {
|
||||
// expected
|
||||
}
|
||||
|
@ -16,28 +16,22 @@
|
||||
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class PromiseNotifierTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testNullPromisesArray() {
|
||||
expectedException.expect(NullPointerException.class);
|
||||
new PromiseNotifier<>((Promise<Void>[]) null);
|
||||
assertThrows(NullPointerException.class, () -> new PromiseNotifier<>((Promise<Void>[]) null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNullPromiseInArray() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
new PromiseNotifier<>((Promise<Void>) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new PromiseNotifier<>((Promise<Void>) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,13 +15,17 @@
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class UnorderedThreadPoolEventExecutorTest {
|
||||
|
||||
// See https://github.com/netty/netty/issues/6507
|
||||
@ -40,14 +44,15 @@ public class UnorderedThreadPoolEventExecutorTest {
|
||||
// Now just check if the queue stays empty multiple times. This is needed as the submit to execute(...)
|
||||
// by DefaultPromise may happen in an async fashion
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
Assert.assertTrue(executor.getQueue().isEmpty());
|
||||
assertTrue(executor.getQueue().isEmpty());
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||
public void scheduledAtFixedRateMustRunTaskRepeatedly() throws InterruptedException {
|
||||
UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
|
||||
final CountDownLatch latch = new CountDownLatch(3);
|
||||
@ -77,7 +82,7 @@ public class UnorderedThreadPoolEventExecutorTest {
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(expected, f.get());
|
||||
assertEquals(expected, f.get());
|
||||
} finally {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
@ -95,7 +100,7 @@ public class UnorderedThreadPoolEventExecutorTest {
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertSame(cause, f.await().cause());
|
||||
assertSame(cause, f.await().cause());
|
||||
} finally {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
|
@ -15,10 +15,9 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AppendableCharSequenceTest {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -25,12 +25,12 @@ import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class DefaultPriorityQueueTest {
|
||||
@Test
|
||||
|
@ -15,12 +15,13 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES;
|
||||
import static io.netty.util.internal.MacAddressUtil.parseMAC;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class MacAddressUtilTest {
|
||||
@Test
|
||||
@ -94,53 +95,53 @@ public class MacAddressUtilTest {
|
||||
parseMAC("00:AA:11:FF:FE:BB:22:CC"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalid7HexGroupsA() {
|
||||
parseMAC("00-AA-11-BB-22-CC-FF");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-BB-22-CC-FF"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalid7HexGroupsB() {
|
||||
parseMAC("00:AA:11:BB:22:CC:FF");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:BB:22:CC:FF"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI48MixedSeparatorA() {
|
||||
parseMAC("00-AA:11-BB-22-CC");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA:11-BB-22-CC"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI48MixedSeparatorB() {
|
||||
parseMAC("00:AA-11:BB:22:CC");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA-11:BB:22:CC"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI64MixedSeparatorA() {
|
||||
parseMAC("00-AA-11-FF-FE-BB-22:CC");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-FF-FE-BB-22:CC"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI64MixedSeparatorB() {
|
||||
parseMAC("00:AA:11:FF:FE:BB:22-CC");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:FF:FE:BB:22-CC"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI48TrailingSeparatorA() {
|
||||
parseMAC("00-AA-11-BB-22-CC-");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-BB-22-CC-"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI48TrailingSeparatorB() {
|
||||
parseMAC("00:AA:11:BB:22:CC:");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:BB:22:CC:"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI64TrailingSeparatorA() {
|
||||
parseMAC("00-AA-11-FF-FE-BB-22-CC-");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00-AA-11-FF-FE-BB-22-CC-"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testParseMacInvalidEUI64TrailingSeparatorB() {
|
||||
parseMAC("00:AA:11:FF:FE:BB:22:CC:");
|
||||
assertThrows(IllegalArgumentException.class, () -> parseMAC("00:AA:11:FF:FE:BB:22:CC:"));
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static io.netty.util.internal.MathUtil.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MathUtilTest {
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.util.internal;
|
||||
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -27,10 +27,10 @@ import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class NativeLibraryLoaderTest {
|
||||
|
||||
|
@ -15,23 +15,26 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ObjectCleanerTest {
|
||||
|
||||
private Thread temporaryThread;
|
||||
private Object temporaryObject;
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testCleanup() throws Exception {
|
||||
final AtomicBoolean freeCalled = new AtomicBoolean();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
@ -47,7 +50,7 @@ public class ObjectCleanerTest {
|
||||
|
||||
latch.countDown();
|
||||
temporaryThread.join();
|
||||
Assert.assertFalse(freeCalled.get());
|
||||
assertFalse(freeCalled.get());
|
||||
|
||||
// Null out the temporary object to ensure it is enqueued for GC.
|
||||
temporaryThread = null;
|
||||
@ -59,7 +62,8 @@ public class ObjectCleanerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testCleanupContinuesDespiteThrowing() throws InterruptedException {
|
||||
final AtomicInteger freeCalledCount = new AtomicInteger();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
@ -96,7 +100,8 @@ public class ObjectCleanerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||
public void testCleanerThreadIsDaemon() throws Exception {
|
||||
temporaryObject = new Object();
|
||||
ObjectCleaner.register(temporaryObject, () -> {
|
||||
|
@ -14,10 +14,11 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Testcases for io.netty.util.internal.ObjectUtil.
|
||||
@ -78,7 +79,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -86,8 +87,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -98,7 +99,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -106,8 +107,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,7 +119,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -126,8 +127,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -138,7 +139,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -146,8 +147,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -155,8 +156,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -167,7 +168,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -175,8 +176,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -184,8 +185,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -196,7 +197,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -204,8 +205,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -213,8 +214,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -225,7 +226,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -233,8 +234,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -242,8 +243,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -254,7 +255,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -262,7 +263,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -270,8 +271,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -282,7 +283,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -290,7 +291,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -298,8 +299,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -310,7 +311,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -318,7 +319,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -326,8 +327,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -338,7 +339,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -346,7 +347,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -354,8 +355,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -367,8 +368,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -376,7 +377,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -384,8 +385,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -397,8 +398,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -406,7 +407,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -414,8 +415,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -427,8 +428,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -436,7 +437,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -444,8 +445,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -456,8 +457,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -465,7 +466,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -473,8 +474,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -486,8 +487,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -495,7 +496,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -503,8 +504,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -512,7 +513,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -524,8 +525,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -533,7 +534,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -541,8 +542,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -550,7 +551,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -562,8 +563,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof NullPointerException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof NullPointerException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -571,7 +572,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNull(TEST_RESULT_NULLEX_NOK, actualEx);
|
||||
assertNull(actualEx, TEST_RESULT_NULLEX_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -579,8 +580,8 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
|
||||
actualEx = null;
|
||||
try {
|
||||
@ -588,7 +589,7 @@ public class ObjectUtilTest {
|
||||
} catch (Exception e) {
|
||||
actualEx = e;
|
||||
}
|
||||
assertNotNull(TEST_RESULT_NULLEX_OK, actualEx);
|
||||
assertTrue(TEST_RESULT_EXTYPE_NOK, actualEx instanceof IllegalArgumentException);
|
||||
assertNotNull(actualEx, TEST_RESULT_NULLEX_OK);
|
||||
assertTrue(actualEx instanceof IllegalArgumentException, TEST_RESULT_EXTYPE_NOK);
|
||||
}
|
||||
}
|
||||
|
@ -15,18 +15,18 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.Permission;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class PlatformDependent0Test {
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void assumeUnsafe() {
|
||||
assumeTrue(PlatformDependent0.hasUnsafe());
|
||||
assumeTrue(PlatformDependent0.hasDirectBufferNoCleanerConstructor());
|
||||
|
@ -15,15 +15,19 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Random;
|
||||
|
||||
import static io.netty.util.internal.PlatformDependent.hashCodeAscii;
|
||||
import static io.netty.util.internal.PlatformDependent.hashCodeAsciiSafe;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class PlatformDependentTest {
|
||||
private static final Random r = new Random();
|
||||
@ -128,12 +132,12 @@ public class PlatformDependentTest {
|
||||
bytes[j] = (byte) (bytesChar[j] & 0xff);
|
||||
}
|
||||
String string = new String(bytesChar);
|
||||
assertEquals("length=" + i,
|
||||
hashCodeAsciiSafe(bytes, 0, bytes.length),
|
||||
hashCodeAscii(bytes, 0, bytes.length));
|
||||
assertEquals("length=" + i,
|
||||
hashCodeAscii(bytes, 0, bytes.length),
|
||||
hashCodeAscii(string));
|
||||
assertEquals(hashCodeAsciiSafe(bytes, 0, bytes.length),
|
||||
hashCodeAscii(bytes, 0, bytes.length),
|
||||
"length=" + i);
|
||||
assertEquals(hashCodeAscii(bytes, 0, bytes.length),
|
||||
hashCodeAscii(string),
|
||||
"length=" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -33,12 +33,13 @@ import static io.netty.util.internal.StringUtil.unescapeCsv;
|
||||
import static io.netty.util.internal.StringUtil.unescapeCsvFields;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class StringUtilTest {
|
||||
|
||||
@ -160,9 +161,9 @@ public class StringUtilTest {
|
||||
return sp;
|
||||
}
|
||||
|
||||
@Test (expected = NullPointerException.class)
|
||||
@Test
|
||||
public void escapeCsvNull() {
|
||||
StringUtil.escapeCsv(null);
|
||||
assertThrows(NullPointerException.class, () -> StringUtil.escapeCsv(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -407,29 +408,29 @@ public class StringUtilTest {
|
||||
assertEquals("hello,netty", unescapeCsv("\"hello,netty\""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvWithSingleQuote() {
|
||||
unescapeCsv("\"");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvWithOddQuote() {
|
||||
unescapeCsv("\"\"\"");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\"\"\""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvWithCRAndWithoutQuote() {
|
||||
unescapeCsv("\r");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\r"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvWithLFAndWithoutQuote() {
|
||||
unescapeCsv("\n");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsv("\n"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvWithCommaAndWithoutQuote() {
|
||||
unescapeCsv(",");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsv(","));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -464,29 +465,29 @@ public class StringUtilTest {
|
||||
assertEquals(Arrays.asList("a\rb", "c\nd"), unescapeCsvFields("\"a\rb\",\"c\nd\""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvFieldsWithCRWithoutQuote() {
|
||||
unescapeCsvFields("a,\r");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\r"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvFieldsWithLFWithoutQuote() {
|
||||
unescapeCsvFields("a,\r");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\r"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvFieldsWithQuote() {
|
||||
unescapeCsvFields("a,\"");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a,\""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvFieldsWithQuote2() {
|
||||
unescapeCsvFields("\",a");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("\",a"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void unescapeCsvFieldsWithQuote3() {
|
||||
unescapeCsvFields("a\"b,a");
|
||||
assertThrows(IllegalArgumentException.class, () -> unescapeCsvFields("a\"b,a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,28 +15,29 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SystemPropertyUtilTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void clearSystemPropertyBeforeEach() {
|
||||
System.clearProperty("key");
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testGetWithKeyNull() {
|
||||
SystemPropertyUtil.get(null, null);
|
||||
assertThrows(NullPointerException.class, () -> SystemPropertyUtil.get(null, null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetWithKeyEmpty() {
|
||||
SystemPropertyUtil.get("", null);
|
||||
assertThrows(IllegalArgumentException.class, () -> SystemPropertyUtil.get("", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -17,25 +17,26 @@ package io.netty.util.internal;
|
||||
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.ImmediateExecutor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
public class ThreadExecutorMapTest {
|
||||
|
||||
@Test
|
||||
public void testDecorateExecutor() {
|
||||
Executor executor = ThreadExecutorMap.apply(ImmediateExecutor.INSTANCE, ImmediateEventExecutor.INSTANCE);
|
||||
executor.execute(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()));
|
||||
executor.execute(() -> assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecorateRunnable() {
|
||||
ThreadExecutorMap.apply(() ->
|
||||
Assert.assertSame(ImmediateEventExecutor.INSTANCE,
|
||||
assertSame(ImmediateEventExecutor.INSTANCE,
|
||||
ThreadExecutorMap.currentExecutor()), ImmediateEventExecutor.INSTANCE).run();
|
||||
}
|
||||
|
||||
@ -43,7 +44,7 @@ public class ThreadExecutorMapTest {
|
||||
public void testDecorateThreadFactory() throws InterruptedException {
|
||||
ThreadFactory threadFactory =
|
||||
ThreadExecutorMap.apply(Executors.defaultThreadFactory(), ImmediateEventExecutor.INSTANCE);
|
||||
Thread thread = threadFactory.newThread(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE,
|
||||
Thread thread = threadFactory.newThread(() -> assertSame(ImmediateEventExecutor.INSTANCE,
|
||||
ThreadExecutorMap.currentExecutor()));
|
||||
thread.start();
|
||||
thread.join();
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ThreadLocalRandomTest {
|
||||
|
||||
@ -25,10 +25,10 @@ public class ThreadLocalRandomTest {
|
||||
public void getInitialSeedUniquifierPreservesInterrupt() {
|
||||
try {
|
||||
Thread.currentThread().interrupt();
|
||||
assertTrue("Assert that thread is interrupted before invocation of getInitialSeedUniquifier()",
|
||||
Thread.currentThread().isInterrupted());
|
||||
assertTrue("Assert that thread is interrupted after invocation of getInitialSeedUniquifier()",
|
||||
Thread.currentThread().isInterrupted());
|
||||
assertTrue(Thread.currentThread().isInterrupted(),
|
||||
"Assert that thread is interrupted before invocation of getInitialSeedUniquifier()");
|
||||
assertTrue(Thread.currentThread().isInterrupted(),
|
||||
"Assert that thread is interrupted after invocation of getInitialSeedUniquifier()");
|
||||
} finally {
|
||||
Thread.interrupted(); // clear interrupted status in order to not affect other tests
|
||||
}
|
||||
|
@ -16,11 +16,13 @@
|
||||
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TypeParameterMatcherTest {
|
||||
|
||||
@ -38,9 +40,9 @@ public class TypeParameterMatcherTest {
|
||||
assertFalse(m.match(new CC()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testUnsolvedParameter() throws Exception {
|
||||
TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B");
|
||||
assertThrows(IllegalStateException.class, () -> TypeParameterMatcher.find(new TypeQ(), TypeX.class, "B"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -135,10 +137,12 @@ public class TypeParameterMatcherTest {
|
||||
T t;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testErasure() throws Exception {
|
||||
TypeParameterMatcher m = TypeParameterMatcher.find(new X<String, Date>(), W.class, "E");
|
||||
assertTrue(m.match(new Date()));
|
||||
assertFalse(m.match(new Object()));
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
TypeParameterMatcher m = TypeParameterMatcher.find(new X<String, Date>(), W.class, "E");
|
||||
assertTrue(m.match(new Date()));
|
||||
assertFalse(m.match(new Object()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -15,15 +15,15 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* We only need to test methods defined by {@link InternaLogger}.
|
||||
|
@ -15,9 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CommonsLoggerFactoryTest {
|
||||
|
||||
|
@ -16,9 +16,9 @@
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class CommonsLoggerTest {
|
||||
|
@ -15,13 +15,14 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class InternalLoggerFactoryTest {
|
||||
@ -29,7 +30,7 @@ public class InternalLoggerFactoryTest {
|
||||
private InternalLoggerFactory oldLoggerFactory;
|
||||
private InternalLogger mockLogger;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
oldLoggerFactory = InternalLoggerFactory.getDefaultFactory();
|
||||
|
||||
@ -39,15 +40,15 @@ public class InternalLoggerFactoryTest {
|
||||
InternalLoggerFactory.setDefaultFactory(mockFactory);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
reset(mockLogger);
|
||||
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void shouldNotAllowNullDefaultFactory() {
|
||||
InternalLoggerFactory.setDefaultFactory(null);
|
||||
assertThrows(NullPointerException.class, () -> InternalLoggerFactory.setDefaultFactory(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,9 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JdkLoggerFactoryTest {
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class Log4J2LoggerFactoryTest {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@ -26,10 +26,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assume;
|
||||
|
||||
import io.netty.util.internal.ReflectionUtil;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
|
||||
/**
|
||||
* {@linkplain Log4J2Logger} extends {@linkplain ExtendedLoggerWrapper} implements {@linkplain InternalLogger}.<br>
|
||||
@ -66,7 +65,7 @@ public class Log4J2LoggerTest extends AbstractInternalLoggerTest<Logger> {
|
||||
|
||||
Method method = mockLog.getClass().getDeclaredMethod("setLevel", Level.class);
|
||||
if (!method.isAccessible()) {
|
||||
Assume.assumeThat(ReflectionUtil.trySetAccessible(method, true), CoreMatchers.nullValue());
|
||||
Assumptions.assumeTrue(ReflectionUtil.trySetAccessible(method, true) == null);
|
||||
}
|
||||
method.invoke(mockLog, targetLevel);
|
||||
}
|
||||
|
@ -15,9 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class Log4JLoggerFactoryTest {
|
||||
|
||||
|
@ -38,9 +38,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class MessageFormatterTest {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.slf4j.Logger;
|
||||
@ -23,9 +23,9 @@ import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class Slf4JLoggerFactoryTest {
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package io.netty.util.internal.logging;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class Slf4JLoggerTest {
|
||||
|
Loading…
x
Reference in New Issue
Block a user