Refactor the signatures of invalid test methods and add comments.

pull/1354/head
lucca 2 years ago
parent 0e7e6ec6e7
commit 3d7aafd298

@ -29,6 +29,9 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.stream.IntStream;
/**
* test for {@link ExecutorFactory}
*/
public final class ExecutorFactoryTest {
ThreadFactory threadFactory = new ThreadFactoryBuilder().prefix("test").build();
@ -47,7 +50,7 @@ public final class ExecutorFactoryTest {
Integer defaultIndex = 0;
@Test
public void assertNewSingleScheduledExecutorService() {
public void testNewSingleScheduledExecutorService() {
// init data snapshot
ThreadPoolManager poolManager = (ThreadPoolManager) ReflectUtil.getFieldValue(ExecutorFactory.Managed.class, "THREAD_POOL_MANAGER");
String poolName = (String) ReflectUtil.getFieldValue(ExecutorFactory.Managed.class, "DEFAULT_NAMESPACE");

@ -17,16 +17,17 @@
package cn.hippo4j.common.executor.support;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* BlockingQueueTypeEnum test class
* test for {@link BlockingQueueTypeEnum}
*/
public final class BlockingQueueTypeEnumTest {
@ -34,101 +35,99 @@ public final class BlockingQueueTypeEnumTest {
private static final List<String> BLOCKING_QUEUE_NAMES = Arrays.stream(BlockingQueueTypeEnum.values()).map(BlockingQueueTypeEnum::getName).collect(Collectors.toList());
@Test
void assertCreateBlockingQueueNormal() {
// check legal param: name and capacity
for (String name : BLOCKING_QUEUE_NAMES) {
BlockingQueue<Object> blockingQueueByName = BlockingQueueTypeEnum.createBlockingQueue(name, 10);
Assert.assertNotNull(blockingQueueByName);
}
void testGetType() {
Assertions.assertEquals(1, BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE.getType());
Assertions.assertEquals(2, BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE.getType());
Assertions.assertEquals(3, BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE.getType());
Assertions.assertEquals(4, BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE.getType());
Assertions.assertEquals(5, BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE.getType());
Assertions.assertEquals(6, BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE.getType());
Assertions.assertEquals(9, BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE.getType());
}
@Test
void assertCreateBlockingQueueWithIllegalName() {
// check illegal null name
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, 10));
// check unexistent name
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("ABC", 10));
void testGetName() {
Assertions.assertEquals("ArrayBlockingQueue", BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE.getName());
Assertions.assertEquals("LinkedBlockingQueue", BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE.getName());
Assertions.assertEquals("LinkedBlockingDeque", BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE.getName());
Assertions.assertEquals("SynchronousQueue", BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE.getName());
Assertions.assertEquals("LinkedTransferQueue", BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE.getName());
Assertions.assertEquals("PriorityBlockingQueue", BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE.getName());
Assertions.assertEquals("ResizableCapacityLinkedBlockingQueue", BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE.getName());
}
@Test
void assertCreateBlockingQueueWithIllegalCapacity() {
// check illegal null capacity
for (String name : BLOCKING_QUEUE_NAMES) {
BlockingQueue<Object> blockingQueueWithNullCapacity = BlockingQueueTypeEnum.createBlockingQueue(name, null);
Assert.assertNotNull(blockingQueueWithNullCapacity);
}
// check illegal negatives capacity
final String arrayBlockingQueueName = BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE.getName();
Assert.assertThrows(IllegalArgumentException.class, () -> BlockingQueueTypeEnum.createBlockingQueue(arrayBlockingQueueName, -100));
final String linkedBlockingQueueName = BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE.getName();
Assert.assertThrows(IllegalArgumentException.class, () -> BlockingQueueTypeEnum.createBlockingQueue(linkedBlockingQueueName, -100));
final String linkedBlockingDequeName = BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE.getName();
Assert.assertThrows(IllegalArgumentException.class, () -> BlockingQueueTypeEnum.createBlockingQueue(linkedBlockingDequeName, -100));
final String synchronousQueueName = BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE.getName();
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(synchronousQueueName, -99));
final String linkedTransferQueueName = BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE.getName();
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(linkedTransferQueueName, -0));
final String priorityBlockingQueueName = BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE.getName();
Assert.assertThrows(IllegalArgumentException.class, () -> BlockingQueueTypeEnum.createBlockingQueue(priorityBlockingQueueName, -100));
final String resizableLinkedBlockingQueueName = BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE.getName();
Assert.assertThrows(IllegalArgumentException.class, () -> BlockingQueueTypeEnum.createBlockingQueue(resizableLinkedBlockingQueueName, -100));
void testValues() {
Assertions.assertNotNull(BlockingQueueTypeEnum.values());
}
@Test
void assertCreateBlockingQueueWithIllegalParams() {
// check illegal name and capacity
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("HelloWorld", null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, null));
void testValueOf() {
Assertions.assertEquals(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE, BlockingQueueTypeEnum.valueOf("ARRAY_BLOCKING_QUEUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.valueOf("LINKED_BLOCKING_QUEUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE, BlockingQueueTypeEnum.valueOf("LINKED_BLOCKING_DEQUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE, BlockingQueueTypeEnum.valueOf("SYNCHRONOUS_QUEUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE, BlockingQueueTypeEnum.valueOf("LINKED_TRANSFER_QUEUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE, BlockingQueueTypeEnum.valueOf("PRIORITY_BLOCKING_QUEUE"));
Assertions.assertEquals(BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.valueOf("RESIZABLE_LINKED_BLOCKING_QUEUE"));
}
@Test
void assertCreateBlockingQueueWithType() {
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(1, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(2, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(3, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(4, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(5, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(6, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(9, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(100, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(-1, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(0, null));
void testCreateBlockingQueue() {
// check legal param: name and capacity
for (String name : BLOCKING_QUEUE_NAMES) {
BlockingQueue<Object> blockingQueueByName = BlockingQueueTypeEnum.createBlockingQueue(name, 10);
Assertions.assertNotNull(blockingQueueByName);
}
// check illegal null name
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, 10));
// check nonexistent name
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("ABC", 10));
// check illegal null capacity
for (String name : BLOCKING_QUEUE_NAMES) {
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(name, null));
}
// check illegal negatives capacity
Assertions.assertThrows(
IllegalArgumentException.class,
() -> BlockingQueueTypeEnum.createBlockingQueue(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE.getName(), -100)
);
// check normal type
Stream.of(1, 2, 3, 4, 5, 6, 9, 100, -1, 0).forEach(each ->
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(each, null)));
// check illegal name and capacity
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("HelloWorld", null));
Assertions.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, null));
}
@Test
void assertGetBlockingQueueNameByType() {
void testGetBlockingQueueNameByType() {
// check legal range of type
Assert.assertEquals("ArrayBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(1));
Assert.assertEquals("LinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(2));
Assert.assertEquals("LinkedBlockingDeque", BlockingQueueTypeEnum.getBlockingQueueNameByType(3));
Assert.assertEquals("SynchronousQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(4));
Assert.assertEquals("LinkedTransferQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(5));
Assert.assertEquals("PriorityBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(6));
Assert.assertEquals("ResizableCapacityLinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(9));
Assertions.assertEquals("ArrayBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(1));
Assertions.assertEquals("LinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(2));
Assertions.assertEquals("LinkedBlockingDeque", BlockingQueueTypeEnum.getBlockingQueueNameByType(3));
Assertions.assertEquals("SynchronousQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(4));
Assertions.assertEquals("LinkedTransferQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(5));
Assertions.assertEquals("PriorityBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(6));
Assertions.assertEquals("ResizableCapacityLinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(9));
// check illegal range of type
Assert.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(0));
Assert.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(-1));
Assert.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(100));
Assertions.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(0));
Assertions.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(-1));
Assertions.assertEquals("", BlockingQueueTypeEnum.getBlockingQueueNameByType(100));
}
@Test
void assertGetBlockingQueueTypeEnumByName() {
void testGetBlockingQueueTypeEnumByName() {
// check legal range of name
Assert.assertEquals(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ArrayBlockingQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingDeque"));
Assert.assertEquals(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("SynchronousQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedTransferQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("PriorityBlockingQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ResizableCapacityLinkedBlockingQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ArrayBlockingQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_DEQUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingDeque"));
Assertions.assertEquals(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("SynchronousQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_TRANSFER_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedTransferQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.PRIORITY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("PriorityBlockingQueue"));
Assertions.assertEquals(BlockingQueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ResizableCapacityLinkedBlockingQueue"));
// check illegal range of name
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("Hello"));
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName(null));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("Hello"));
Assertions.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName(null));
}
}

@ -30,7 +30,7 @@ public final class MatcherFunctionTest {
}
@Test
public void assertMatch() {
public void testMatch() {
Assert.isTrue(matchTest(Boolean.TRUE::equals, true));
Assert.isTrue(matchTest(BigDecimal.ZERO::equals, BigDecimal.ZERO));
}

@ -22,24 +22,24 @@ import org.junit.Test;
import org.springframework.util.StringUtils;
/**
* test {@link ArrayUtil}
* test for {@link ArrayUtil}
*/
public class ArrayUtilTest {
@Test
public void assertIsEmpty() {
public void testIsEmpty() {
String[] array = new String[0];
Assert.isTrue(ArrayUtil.isEmpty(array));
}
@Test
public void assertIsNotEmpty() {
public void testIsNotEmpty() {
String[] array = new String[0];
Assert.isTrue(!ArrayUtil.isNotEmpty(array));
}
@Test
public void assertFirstMatch() {
public void testFirstMatch() {
Matcher<String> matcher = (str) -> "1".equalsIgnoreCase(str);
String[] array = new String[0];
Assert.isTrue(StringUtils.isEmpty(ArrayUtil.firstMatch(matcher, array)));
@ -50,7 +50,7 @@ public class ArrayUtilTest {
}
@Test
public void assertAddAll() {
public void testAddAll() {
String[] array = new String[]{"1"};
Assert.isTrue(ArrayUtil.addAll(array, null).length == 1);
Assert.isTrue(ArrayUtil.addAll(null, array).length == 1);
@ -58,7 +58,7 @@ public class ArrayUtilTest {
}
@Test
public void assertClone() {
public void testClone() {
Assert.isNull(ArrayUtil.clone(null));
String[] array = new String[0];
Assert.isTrue(array != ArrayUtil.clone(array));

@ -17,93 +17,61 @@
package cn.hippo4j.common.toolkit;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import java.util.Collections;
/**
* test {@link Assert}
* test for {@link Assert}
*/
public final class AssertTest {
@Test(expected = IllegalArgumentException.class)
public void assertIsTrue() {
Assert.isTrue(false, "test message");
@Test
public void testIsTrue() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.isTrue(false));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.isTrue(false, "test message"));
}
@Test(expected = IllegalArgumentException.class)
public void assertIsTrueAndMessageIsNull() {
Assert.isTrue(false);
@Test
public void testIsNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.isNull(""));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.isNull("", "object is null"));
}
@Test(expected = IllegalArgumentException.class)
public void assertIsNullAndMessageIsNull() {
Assert.isNull("");
@Test
public void testNotNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notNull(null));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notNull(null, "object is null"));
}
@Test(expected = IllegalArgumentException.class)
public void assertIsNull() {
Assert.isNull("", "object is null");
@Test
public void testNotEmpty() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notEmpty(Collections.emptyList()));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notEmpty(Collections.emptyList(), "object is null"));
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notEmpty(Collections.emptyMap()));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notEmpty(Collections.emptyMap(), "map is null"));
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notEmpty(""));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notEmpty("", "string is null"));
}
@Test(expected = IllegalArgumentException.class)
public void assertNotNull() {
Assert.notNull(null, "object is null");
@Test
public void testNotBlank() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notBlank(" "));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notBlank(" ", "string is null"));
}
@Test(expected = IllegalArgumentException.class)
public void assertNotNullAndMessageIsNull() {
Assert.notNull(null);
@Test
public void testHasText() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.hasText(" "));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.hasText(" ", "text is null"));
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByList() {
Assert.notEmpty(Collections.emptyList(), "object is null");
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByListAndMessageIsNull() {
Assert.notEmpty(Collections.emptyList());
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByMap() {
Assert.notEmpty(Collections.emptyMap(), "map is null");
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByMapAndMessageIsNull() {
Assert.notEmpty(Collections.emptyMap());
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByString() {
Assert.notEmpty("", "string is null");
}
@Test(expected = IllegalArgumentException.class)
public void assertNotEmptyByStringAndMessageIsNull() {
Assert.notEmpty("");
}
@Test(expected = IllegalArgumentException.class)
public void assertNotBlankByString() {
Assert.notBlank(" ", "string is null");
}
@Test(expected = IllegalArgumentException.class)
public void assertNotBlankByStringAndMessageIsNull() {
Assert.notBlank(" ");
}
@Test(expected = IllegalArgumentException.class)
public void assertHasText() {
Assert.hasText(" ", "text is null");
}
@Test(expected = IllegalArgumentException.class)
public void assertHasTextAndMessageIsNull() {
Assert.hasText(" ");
}
}

@ -20,17 +20,20 @@ package cn.hippo4j.common.toolkit;
import org.junit.Assert;
import org.junit.Test;
/**
* test for {@link BooleanUtil}
*/
public class BooleanUtilTest {
@Test
public void assertToBoolean() {
public void testToBoolean() {
Assert.assertTrue(BooleanUtil.toBoolean("true"));
Assert.assertTrue(BooleanUtil.toBoolean("yes"));
Assert.assertTrue(BooleanUtil.toBoolean("1"));
}
@Test
public void assertIsTrue() {
public void testIsTrue() {
Assert.assertTrue(BooleanUtil.isTrue(true));
}
}

@ -21,10 +21,13 @@ import org.junit.Test;
import java.util.Objects;
/**
* test for {@link ByteConvertUtil}
*/
public class ByteConvertUtilTest {
@Test
public void assertGetPrintSize() {
public void testGetPrintSize() {
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(220), "220B"));
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(2200), "2.15KB"));
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(2200000), "2.10MB"));

@ -19,10 +19,13 @@ package cn.hippo4j.common.toolkit;
import org.junit.Test;
/**
* test for {@link CalculateUtil}
*/
public class CalculateUtilTest {
@Test
public void assertDivide() {
public void testDivide() {
Assert.isTrue(CalculateUtil.divide(200, 100) == 200);
Assert.isTrue(CalculateUtil.divide(100, 200) == 50);
Assert.isTrue(CalculateUtil.divide(100, 100) == 100);

@ -25,17 +25,20 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* test for {@link CollectionUtil}
*/
public class CollectionUtilTest {
@Test
public void assertGetFirst() {
public void testGetFirst() {
Assert.isNull(CollectionUtil.getFirst(null));
String first = CollectionUtil.getFirst(Lists.newArrayList("1", "2"));
Assert.notEmpty(first);
}
@Test
public void assertIsEmpty() {
public void testIsEmpty() {
List list = null;
Assert.isTrue(CollectionUtil.isEmpty(list));
list = Lists.newArrayList();
@ -57,7 +60,7 @@ public class CollectionUtilTest {
}
@Test
public void assertIsNotEmpty() {
public void testIsNotEmpty() {
List list = null;
Assert.isTrue(!CollectionUtil.isNotEmpty(list));
list = Lists.newArrayList();

@ -22,10 +22,13 @@ import org.junit.Test;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* test for {@link ConditionUtil}
*/
public class ConditionUtilTest {
@Test
public void assertCondition() {
public void testCondition() {
// init consumer
AtomicBoolean checkValue = new AtomicBoolean(false);
NoArgsConsumer trueConsumer = () -> checkValue.set(true);

@ -20,10 +20,13 @@ package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import org.junit.Test;
/**
* test for {@link ContentUtil}
*/
public class ContentUtilTest {
@Test
public void assertGetPoolContent() {
public void testGetPoolContent() {
String testText = "{\"tenantId\":\"prescription\",\"itemId\":\"dynamic-threadpool-example\",\"tpId\":" +
"\"message-consume\",\"queueType\":1,\"capacity\":4,\"keepAliveTime\":513,\"rejectedType\":4,\"isAlarm\"" +
":1,\"capacityAlarm\":80,\"livenessAlarm\":80,\"allowCoreThreadTimeOut\":1}";
@ -35,7 +38,7 @@ public class ContentUtilTest {
}
@Test
public void assertGetGroupKey() {
public void testGetGroupKey() {
String testText = "message-consume+dynamic-threadpool-example+prescription";
ThreadPoolParameterInfo parameter = ThreadPoolParameterInfo.builder()
.tenantId("prescription").itemId("dynamic-threadpool-example").tpId("message-consume").build();
@ -43,7 +46,7 @@ public class ContentUtilTest {
}
@Test
public void assertGetGroupKeys() {
public void testGetGroupKeys() {
String testText = "message-consume+dynamic-threadpool-example+prescription";
String groupKey = ContentUtil.getGroupKey("message-consume", "dynamic-threadpool-example", "prescription");
Assert.isTrue(testText.equals(groupKey));

@ -29,6 +29,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* test for {@link JSONUtil}
*/
public class JSONUtilTest {
private static final Foo EXPECTED_FOO = new Foo(1, "foo1", new Foo(2, "foo2", null));
@ -40,32 +43,26 @@ public class JSONUtilTest {
private static final String EXPECTED_FOO_JSON_ARRAY = "[" + EXPECTED_FOO_JSON + "," + EXPECTED_FOO_JSON + "]";
@Test
public void assertToJSONString() {
public void testToJSONString() {
Assert.assertNull(JSONUtil.toJSONString(null));
Assert.assertEquals(EXPECTED_FOO_JSON, JSONUtil.toJSONString(EXPECTED_FOO));
}
@Test
public void assertParseObject() {
public void testParseObject() {
Assert.assertNull(JSONUtil.parseObject(null, Foo.class));
Assert.assertNull(JSONUtil.parseObject(" ", Foo.class));
Assert.assertEquals(EXPECTED_FOO, JSONUtil.parseObject(EXPECTED_FOO_JSON, Foo.class));
}
@Test
public void assertParseObjectTypeReference() {
Assert.assertNull(JSONUtil.parseObject(null, new TypeReference<List<Foo>>() {
}));
Assert.assertNull(JSONUtil.parseObject(" ", new TypeReference<List<Foo>>() {
}));
Assert.assertNull(JSONUtil.parseObject(null, new TypeReference<List<Foo>>() {}));
Assert.assertNull(JSONUtil.parseObject(" ", new TypeReference<List<Foo>>() {}));
Assert.assertEquals(
EXPECTED_FOO_ARRAY,
JSONUtil.parseObject(EXPECTED_FOO_JSON_ARRAY, new TypeReference<List<Foo>>() {
}));
JSONUtil.parseObject(EXPECTED_FOO_JSON_ARRAY, new TypeReference<List<Foo>>() {})
);
}
@Test
public void assertParseArray() {
public void testParseArray() {
Assert.assertEquals(Collections.emptyList(), JSONUtil.parseArray(null, Foo.class));
Assert.assertEquals(Collections.emptyList(), JSONUtil.parseArray(" ", Foo.class));
Assert.assertEquals(

@ -25,31 +25,34 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
/**
* test for {@link Md5Util}
*/
public class Md5UtilTest {
@Test
public void assertMd5Hex() throws NoSuchAlgorithmException {
public void testMd5Hex() throws NoSuchAlgorithmException {
String md5 = "3cdefff74dcf7a5d60893865b84b62c8";
String message = "message-consume";
Assert.isTrue(md5.equals(Md5Util.md5Hex(message.getBytes())));
}
@Test
public void assertMd5Hex2() {
public void testMd5Hex2() {
String md5 = "503840dc3af3cdb39749cd099e4dfeff";
String message = "dynamic-threadpool-example";
Assert.isTrue(md5.equals(Md5Util.md5Hex(message, "UTF-8")));
}
@Test
public void assetEncodeHexString() {
public void testEncodeHexString() {
String encodeHexString = "00010f107f80203040506070";
byte[] bytes = {0, 1, 15, 16, 127, -128, 32, 48, 64, 80, 96, 112};
Assert.isTrue(encodeHexString.equals(Md5Util.encodeHexString(bytes)));
}
@Test
public void assetGetTpContentMd5() {
public void testGetTpContentMd5() {
String md5Result = "ef5ea7cb47377fb9fb85a7125e76715d";
ThreadPoolParameterInfo threadPoolParameterInfo = ThreadPoolParameterInfo.builder().tenantId("prescription")
.itemId("dynamic-threadpool-example").tpId("message-consume").content("描述信息").corePoolSize(1)
@ -59,7 +62,7 @@ public class Md5UtilTest {
}
@Test
public void assetCompareMd5ResultString() throws IOException {
public void testCompareMd5ResultString() throws IOException {
Assert.isTrue("".equals(Md5Util.compareMd5ResultString(null)));
String result = "prescription%02dynamic-threadpool-example%02message-consume%01" +
"prescription%02dynamic-threadpool-example%02message-produce%01";

@ -21,10 +21,13 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import org.junit.Assert;
import org.junit.Test;
/**
* test for {@link Singleton}
*/
public class SingletonTest {
@Test
public void assertSingletonGet() {
public void testSingletonGet() {
Assert.assertNull(Singleton.get("userName"));
Singleton.put("userName", "hippo4j");
Assert.assertEquals("hippo4j", Singleton.get("userName"));
@ -37,7 +40,7 @@ public class SingletonTest {
}
@Test
public void assertSingletonGet2() {
public void testSingletonGet2() {
Assert.assertNull(Singleton.get("userName1", () -> null));
Assert.assertEquals("hippo4j", Singleton.get("userName1", () -> "hippo4j"));
Assert.assertEquals("123456", Singleton.get("pw", () -> "123456") + "");

@ -20,6 +20,9 @@ package cn.hippo4j.common.toolkit;
import org.junit.Test;
import org.junit.Assert;
/**
* test for {@link StringUtil}
*/
public class StringUtilTest {
@Test
@ -70,13 +73,13 @@ public class StringUtilTest {
}
@Test
public void assertIsEmpty() {
public void testIsEmpty() {
String string = "";
Assert.assertTrue(StringUtil.isEmpty(string));
}
@Test
public void assertIsNotEmpty() {
public void testIsNotEmpty() {
String string = "string";
Assert.assertTrue(StringUtil.isNotEmpty(string));
}

@ -85,13 +85,10 @@ public class ExtensibleThreadPoolExecutorTest {
public void testInvokeTaskAwarePlugin() {
TestTaskAwarePlugin plugin = new TestTaskAwarePlugin();
executor.register(plugin);
executor.submit(() -> {
});
executor.submit(() -> {});
executor.submit(() -> true);
executor.submit(() -> {
}, false);
executor.execute(() -> {
});
executor.submit(() -> {}, false);
executor.execute(() -> {});
Assert.assertEquals(7, plugin.getInvokeCount().get());
}
@ -99,15 +96,13 @@ public class ExtensibleThreadPoolExecutorTest {
public void testInvokeExecuteAwarePlugin() {
TestExecuteAwarePlugin plugin = new TestExecuteAwarePlugin();
executor.register(plugin);
executor.execute(() -> {
});
executor.execute(() -> {});
ThreadUtil.sleep(500L);
Assert.assertEquals(2, plugin.getInvokeCount().get());
// no task will be executed because it has been replaced with null
executor.register(new TestTaskToNullAwarePlugin());
executor.execute(() -> {
});
executor.execute(() -> {});
ThreadUtil.sleep(500L);
Assert.assertEquals(2, plugin.getInvokeCount().get());
}
@ -123,12 +118,9 @@ public class ExtensibleThreadPoolExecutorTest {
executor.submit(() -> ThreadUtil.sleep(500L));
executor.submit(() -> ThreadUtil.sleep(500L));
// reject 3 tasks
executor.submit(() -> {
});
executor.submit(() -> {
});
executor.submit(() -> {
});
executor.submit(() -> {});
executor.submit(() -> {});
executor.submit(() -> {});
ThreadUtil.sleep(500L);
Assert.assertEquals(3, plugin.getInvokeCount().get());

@ -19,10 +19,13 @@ package cn.hippo4j.core.executor.handler;
import org.junit.Test;
/**
* test for {@link DynamicThreadPoolBannerHandler}
*/
public final class DynamicThreadPoolBannerHandlerTest {
@Test
public void assertGetVersion() {
public void testGetVersion() {
// Assert.assertTrue(StringUtil.isEmpty(DynamicThreadPoolBannerHandler.getVersion()));
}
}

@ -29,19 +29,19 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertTrue;
/**
* test {@link ServiceLoaderRegistry}
* test for {@link ServiceLoaderRegistry}
*/
public final class DynamicThreadPoolServiceLoaderTest {
@Test
public void assertRegister() {
public void testRegister() {
ServiceLoaderRegistry.register(Collection.class);
Collection<?> collections = ServiceLoaderRegistry.getSingletonServiceInstances(Collection.class);
assertTrue(collections.isEmpty());
}
@Test
public void assertGetSingletonServiceInstances() {
public void testGetSingletonServiceInstances() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1));
@ -49,7 +49,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
}
@Test
public void assertNewServiceInstances() {
public void testNewServiceInstances() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.newServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1));
@ -57,7 +57,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
}
@Test
public void assertGetServiceInstancesWhenIsSingleton() {
public void testGetServiceInstancesWhenIsSingleton() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
@ -65,7 +65,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
}
@Test
public void assertGetServiceInstancesWhenNotSingleton() {
public void testGetServiceInstancesWhenNotSingleton() {
ServiceLoaderRegistry.register(TestInterfaceSPI.class);
Collection<TestInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestInterfaceSPI.class);
assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestInterfaceSPI.class).iterator().next()));

@ -23,28 +23,31 @@ import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* test for {@link FileUtil}
*/
public class FileUtilTest {
@Test
public void assertReadUtf8String() {
public void testReadUtf8String() {
String testFilePath = "test/test_utf8.txt";
String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
Assert.assertFalse(contentByFileUtil.isEmpty());
}
@Test
public void assertReadUtf8String2() {
public void testReadUtf8String2() {
String linebreaks = System.getProperty("line.separator");
String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *" + linebreaks +
"second line" + linebreaks +
"empty line next" + linebreaks;
String testFilePath = "test/test_utf8.txt";
String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
Assert.assertTrue(testText.equals(contentByFileUtil));
Assert.assertEquals(testText, contentByFileUtil);
}
@Test
public void assertReadLines() {
public void testReadLines() {
String testFilePath = "test/test_utf8.txt";
List<String> readLines = FileUtil.readLines(testFilePath, StandardCharsets.UTF_8);
Assert.assertEquals(3, readLines.size());

@ -22,17 +22,20 @@ import cn.hippo4j.message.enums.NotifyTypeEnum;
import org.junit.Assert;
import org.junit.Test;
/**
* test for {@link AlarmControlHandler}
*/
public final class AlarmControlHandlerTest {
@Test
public void assertIsNotSendAlarm() {
public void testIsNotSendAlarm() {
AlarmControlHandler alarmControlHandler = new AlarmControlHandler();
AlarmControlDTO alarmControlDTO = new AlarmControlDTO("1", "Wechat", NotifyTypeEnum.ACTIVITY);
Assert.assertFalse(alarmControlHandler.isSendAlarm(alarmControlDTO));
}
@Test
public void assertIsSendAlarm() {
public void testIsSendAlarm() {
AlarmControlHandler alarmControlHandler = new AlarmControlHandler();
AlarmControlDTO alarmControlDTO = new AlarmControlDTO("1", "Wechat", NotifyTypeEnum.ACTIVITY);
alarmControlHandler.initCacheAndLock("1", "Wechat", 1);

@ -21,18 +21,19 @@ import cn.hippo4j.common.toolkit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* test for {@link AuthUtil}
*/
public final class AuthUtilTest {
private AuthUtil authUtil;
@Before
public void beforeInit() {
authUtil = new AuthUtil();
AuthUtil authUtil = new AuthUtil();
authUtil.setEnableAuthentication(true);
}
@Test
public void assertGetEnableAuthentication() {
public void testIsEnableAuthentication() {
Assert.isTrue(AuthUtil.isEnableAuthentication());
}
}

@ -23,6 +23,9 @@ import org.junit.Test;
import java.util.Objects;
/**
* test for {@link ReturnT}
*/
public final class ReturnTTest {
private ReturnT returnT;
@ -33,17 +36,17 @@ public final class ReturnTTest {
}
@Test
public void assertGetCode() {
public void testGetCode() {
Assert.isTrue(Objects.equals(returnT.getCode(), 200));
}
@Test
public void assertGetMessage() {
public void testGetMessage() {
Assert.isNull(returnT.getMessage());
}
@Test
public void assertGetContent() {
public void testGetContent() {
Assert.isTrue(Objects.equals(returnT.getContent(), "success"));
}
}

@ -21,10 +21,13 @@ import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.StringUtil;
import org.junit.Test;
/**
* test for {@link LocalDataChangeEvent}
*/
public final class LocalDataChangeEventTest {
@Test
public void assertGetSingleton() {
public void testGetSingleton() {
LocalDataChangeEvent localDataChangeEvent = new LocalDataChangeEvent("groupKey", "identify");
Assert.isTrue(StringUtil.isNotEmpty(localDataChangeEvent.getGroupKey()));
Assert.isTrue(StringUtil.isNotEmpty(localDataChangeEvent.getIdentify()));

Loading…
Cancel
Save