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

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

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

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

@ -17,93 +17,61 @@
package cn.hippo4j.common.toolkit; package cn.hippo4j.common.toolkit;
import java.util.Collections;
import org.junit.Test; 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 { public final class AssertTest {
@Test(expected = IllegalArgumentException.class) @Test
public void assertIsTrue() { public void testIsTrue() {
Assert.isTrue(false, "test message"); Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.isTrue(false));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.isTrue(false, "test message"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void assertIsTrueAndMessageIsNull() { public void testIsNull() {
Assert.isTrue(false); Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.isNull(""));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.isNull("", "object is null"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void assertIsNullAndMessageIsNull() { public void testNotNull() {
Assert.isNull(""); Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notNull(null));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notNull(null, "object is null"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void assertIsNull() { public void testNotEmpty() {
Assert.isNull("", "object is null"); 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) @Test
public void assertNotNull() { public void testNotBlank() {
Assert.notNull(null, "object is null"); Assertions.assertThrows(IllegalArgumentException.class, () -> Assert.notBlank(" "));
Assertions.assertThrows(IllegalArgumentException.class,
() -> Assert.notBlank(" ", "string is null"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void assertNotNullAndMessageIsNull() { public void testHasText() {
Assert.notNull(null); 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.Assert;
import org.junit.Test; import org.junit.Test;
/**
* test for {@link BooleanUtil}
*/
public class BooleanUtilTest { public class BooleanUtilTest {
@Test @Test
public void assertToBoolean() { public void testToBoolean() {
Assert.assertTrue(BooleanUtil.toBoolean("true")); Assert.assertTrue(BooleanUtil.toBoolean("true"));
Assert.assertTrue(BooleanUtil.toBoolean("yes")); Assert.assertTrue(BooleanUtil.toBoolean("yes"));
Assert.assertTrue(BooleanUtil.toBoolean("1")); Assert.assertTrue(BooleanUtil.toBoolean("1"));
} }
@Test @Test
public void assertIsTrue() { public void testIsTrue() {
Assert.assertTrue(BooleanUtil.isTrue(true)); Assert.assertTrue(BooleanUtil.isTrue(true));
} }
} }

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

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

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

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

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

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

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

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

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

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

@ -29,19 +29,19 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* test {@link ServiceLoaderRegistry} * test for {@link ServiceLoaderRegistry}
*/ */
public final class DynamicThreadPoolServiceLoaderTest { public final class DynamicThreadPoolServiceLoaderTest {
@Test @Test
public void assertRegister() { public void testRegister() {
ServiceLoaderRegistry.register(Collection.class); ServiceLoaderRegistry.register(Collection.class);
Collection<?> collections = ServiceLoaderRegistry.getSingletonServiceInstances(Collection.class); Collection<?> collections = ServiceLoaderRegistry.getSingletonServiceInstances(Collection.class);
assertTrue(collections.isEmpty()); assertTrue(collections.isEmpty());
} }
@Test @Test
public void assertGetSingletonServiceInstances() { public void testGetSingletonServiceInstances() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1)); assertThat(instances.size(), equalTo(1));
@ -49,7 +49,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
} }
@Test @Test
public void assertNewServiceInstances() { public void testNewServiceInstances() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.newServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.newServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1)); assertThat(instances.size(), equalTo(1));
@ -57,7 +57,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
} }
@Test @Test
public void assertGetServiceInstancesWhenIsSingleton() { public void testGetServiceInstancesWhenIsSingleton() {
ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next())); assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
@ -65,7 +65,7 @@ public final class DynamicThreadPoolServiceLoaderTest {
} }
@Test @Test
public void assertGetServiceInstancesWhenNotSingleton() { public void testGetServiceInstancesWhenNotSingleton() {
ServiceLoaderRegistry.register(TestInterfaceSPI.class); ServiceLoaderRegistry.register(TestInterfaceSPI.class);
Collection<TestInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestInterfaceSPI.class); Collection<TestInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestInterfaceSPI.class);
assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestInterfaceSPI.class).iterator().next())); 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.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
/**
* test for {@link FileUtil}
*/
public class FileUtilTest { public class FileUtilTest {
@Test @Test
public void assertReadUtf8String() { public void testReadUtf8String() {
String testFilePath = "test/test_utf8.txt"; String testFilePath = "test/test_utf8.txt";
String contentByFileUtil = FileUtil.readUtf8String(testFilePath); String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
Assert.assertFalse(contentByFileUtil.isEmpty()); Assert.assertFalse(contentByFileUtil.isEmpty());
} }
@Test @Test
public void assertReadUtf8String2() { public void testReadUtf8String2() {
String linebreaks = System.getProperty("line.separator"); String linebreaks = System.getProperty("line.separator");
String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *" + linebreaks + String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *" + linebreaks +
"second line" + linebreaks + "second line" + linebreaks +
"empty line next" + linebreaks; "empty line next" + linebreaks;
String testFilePath = "test/test_utf8.txt"; String testFilePath = "test/test_utf8.txt";
String contentByFileUtil = FileUtil.readUtf8String(testFilePath); String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
Assert.assertTrue(testText.equals(contentByFileUtil)); Assert.assertEquals(testText, contentByFileUtil);
} }
@Test @Test
public void assertReadLines() { public void testReadLines() {
String testFilePath = "test/test_utf8.txt"; String testFilePath = "test/test_utf8.txt";
List<String> readLines = FileUtil.readLines(testFilePath, StandardCharsets.UTF_8); List<String> readLines = FileUtil.readLines(testFilePath, StandardCharsets.UTF_8);
Assert.assertEquals(3, readLines.size()); Assert.assertEquals(3, readLines.size());

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

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

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

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

Loading…
Cancel
Save