fix: increase codecov coverage by using junit instead of junit.jupiter (#1349)

* increase codecov coverage by using junit instead of junit.jupiter

* increase codecov coverage in some other packages

* remove blank line
pull/1350/head
Annibale Ippolito 2 years ago committed by GitHub
parent 0e7e6ec6e7
commit 3d3de06438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,25 +17,25 @@
package cn.hippo4j.common; package cn.hippo4j.common;
import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.runner.RunWith;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.MockitoJUnitRunner;
import java.util.List;
@ExtendWith(MockitoExtension.class) @RunWith(MockitoJUnitRunner.class)
class MockitoTests { public class MockitoTests {
@Mock @Mock
List<String> list; List<String> list;
@Test @Test
void mockTests() { public void mockTests() {
Mockito.when(list.get(1)).thenReturn("mock success."); Mockito.when(list.get(1)).thenReturn("mock success.");
Assertions.assertEquals("mock success.", list.get(1)); Assertions.assertEquals("mock success.", list.get(1));
try (final MockedStatic<StringUtils> mockStatic = Mockito.mockStatic(StringUtils.class)) { try (final MockedStatic<StringUtils> mockStatic = Mockito.mockStatic(StringUtils.class)) {

@ -18,7 +18,7 @@
package cn.hippo4j.common.executor.support; package cn.hippo4j.common.executor.support;
import org.junit.Assert; import org.junit.Assert;
import org.junit.jupiter.api.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -34,7 +34,7 @@ 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() { public void testAssertCreateBlockingQueueNormal() {
// check legal param: name and capacity // check legal param: name and capacity
for (String name : BLOCKING_QUEUE_NAMES) { for (String name : BLOCKING_QUEUE_NAMES) {
BlockingQueue<Object> blockingQueueByName = BlockingQueueTypeEnum.createBlockingQueue(name, 10); BlockingQueue<Object> blockingQueueByName = BlockingQueueTypeEnum.createBlockingQueue(name, 10);
@ -43,7 +43,7 @@ public final class BlockingQueueTypeEnumTest {
} }
@Test @Test
void assertCreateBlockingQueueWithIllegalName() { public void testAssertCreateBlockingQueueWithIllegalName() {
// check illegal null name // check illegal null name
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, 10)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, 10));
// check unexistent name // check unexistent name
@ -51,7 +51,7 @@ public final class BlockingQueueTypeEnumTest {
} }
@Test @Test
void assertCreateBlockingQueueWithIllegalCapacity() { public void testAssertCreateBlockingQueueWithIllegalCapacity() {
// check illegal null capacity // check illegal null capacity
for (String name : BLOCKING_QUEUE_NAMES) { for (String name : BLOCKING_QUEUE_NAMES) {
BlockingQueue<Object> blockingQueueWithNullCapacity = BlockingQueueTypeEnum.createBlockingQueue(name, null); BlockingQueue<Object> blockingQueueWithNullCapacity = BlockingQueueTypeEnum.createBlockingQueue(name, null);
@ -81,14 +81,14 @@ public final class BlockingQueueTypeEnumTest {
} }
@Test @Test
void assertCreateBlockingQueueWithIllegalParams() { public void testAssertCreateBlockingQueueWithIllegalParams() {
// check illegal name and capacity // check illegal name and capacity
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("HelloWorld", null)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue("HelloWorld", null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, null)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(null, null));
} }
@Test @Test
void assertCreateBlockingQueueWithType() { public void testAssertCreateBlockingQueueWithType() {
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(1, null)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(1, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(2, null)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(2, null));
Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(3, null)); Assert.assertNotNull(BlockingQueueTypeEnum.createBlockingQueue(3, null));
@ -102,7 +102,7 @@ public final class BlockingQueueTypeEnumTest {
} }
@Test @Test
void assertGetBlockingQueueNameByType() { public void testAssertGetBlockingQueueNameByType() {
// check legal range of type // check legal range of type
Assert.assertEquals("ArrayBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(1)); Assert.assertEquals("ArrayBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(1));
Assert.assertEquals("LinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(2)); Assert.assertEquals("LinkedBlockingQueue", BlockingQueueTypeEnum.getBlockingQueueNameByType(2));
@ -118,7 +118,7 @@ public final class BlockingQueueTypeEnumTest {
} }
@Test @Test
void assertGetBlockingQueueTypeEnumByName() { public void testAssertGetBlockingQueueTypeEnumByName() {
// check legal range of name // check legal range of name
Assert.assertEquals(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ArrayBlockingQueue")); Assert.assertEquals(BlockingQueueTypeEnum.ARRAY_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("ArrayBlockingQueue"));
Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingQueue")); Assert.assertEquals(BlockingQueueTypeEnum.LINKED_BLOCKING_QUEUE, BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName("LinkedBlockingQueue"));

@ -17,18 +17,18 @@
package cn.hippo4j.common.executor.support; package cn.hippo4j.common.executor.support;
import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
/** /**
* test for {@link RejectedPolicyTypeEnum} * test for {@link RejectedPolicyTypeEnum}
*/ */
class RejectedPolicyTypeEnumTest { public class RejectedPolicyTypeEnumTest {
@Test @Test
void testGetType() { public void testGetType() {
Assertions.assertEquals(1, RejectedPolicyTypeEnum.CALLER_RUNS_POLICY.getType()); Assertions.assertEquals(1, RejectedPolicyTypeEnum.CALLER_RUNS_POLICY.getType());
Assertions.assertEquals(2, RejectedPolicyTypeEnum.ABORT_POLICY.getType()); Assertions.assertEquals(2, RejectedPolicyTypeEnum.ABORT_POLICY.getType());
Assertions.assertEquals(3, RejectedPolicyTypeEnum.DISCARD_POLICY.getType()); Assertions.assertEquals(3, RejectedPolicyTypeEnum.DISCARD_POLICY.getType());
@ -38,7 +38,7 @@ class RejectedPolicyTypeEnumTest {
} }
@Test @Test
void testGetName() { public void testGetName() {
Assertions.assertEquals("CallerRunsPolicy", RejectedPolicyTypeEnum.CALLER_RUNS_POLICY.getName()); Assertions.assertEquals("CallerRunsPolicy", RejectedPolicyTypeEnum.CALLER_RUNS_POLICY.getName());
Assertions.assertEquals("AbortPolicy", RejectedPolicyTypeEnum.ABORT_POLICY.getName()); Assertions.assertEquals("AbortPolicy", RejectedPolicyTypeEnum.ABORT_POLICY.getName());
Assertions.assertEquals("DiscardPolicy", RejectedPolicyTypeEnum.DISCARD_POLICY.getName()); Assertions.assertEquals("DiscardPolicy", RejectedPolicyTypeEnum.DISCARD_POLICY.getName());
@ -48,12 +48,12 @@ class RejectedPolicyTypeEnumTest {
} }
@Test @Test
void testValues() { public void testValues() {
Assertions.assertNotNull(RejectedPolicyTypeEnum.values()); Assertions.assertNotNull(RejectedPolicyTypeEnum.values());
} }
@Test @Test
void testValueOf() { public void testValueOf() {
Assertions.assertEquals(RejectedPolicyTypeEnum.CALLER_RUNS_POLICY, RejectedPolicyTypeEnum.valueOf("CALLER_RUNS_POLICY")); Assertions.assertEquals(RejectedPolicyTypeEnum.CALLER_RUNS_POLICY, RejectedPolicyTypeEnum.valueOf("CALLER_RUNS_POLICY"));
Assertions.assertEquals(RejectedPolicyTypeEnum.ABORT_POLICY, RejectedPolicyTypeEnum.valueOf("ABORT_POLICY")); Assertions.assertEquals(RejectedPolicyTypeEnum.ABORT_POLICY, RejectedPolicyTypeEnum.valueOf("ABORT_POLICY"));
Assertions.assertEquals(RejectedPolicyTypeEnum.DISCARD_POLICY, RejectedPolicyTypeEnum.valueOf("DISCARD_POLICY")); Assertions.assertEquals(RejectedPolicyTypeEnum.DISCARD_POLICY, RejectedPolicyTypeEnum.valueOf("DISCARD_POLICY"));
@ -63,7 +63,7 @@ class RejectedPolicyTypeEnumTest {
} }
@Test @Test
void testCreatePolicy() { public void testCreatePolicy() {
// check legal param: name and type // check legal param: name and type
Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> { Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> {
Assertions.assertNotNull(RejectedPolicyTypeEnum.createPolicy(each.getName())); Assertions.assertNotNull(RejectedPolicyTypeEnum.createPolicy(each.getName()));
@ -78,19 +78,17 @@ class RejectedPolicyTypeEnumTest {
} }
@Test @Test
void testGetRejectedNameByType() { public void testGetRejectedNameByType() {
// check legal range of type // check legal range of type
Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> Assertions.assertEquals(each.getName(), RejectedPolicyTypeEnum.getRejectedNameByType(each.getType())));
Assertions.assertEquals(each.getName(), RejectedPolicyTypeEnum.getRejectedNameByType(each.getType())));
// check illegal range of type // check illegal range of type
Assertions.assertEquals("AbortPolicy", RejectedPolicyTypeEnum.getRejectedNameByType(-1)); Assertions.assertEquals("AbortPolicy", RejectedPolicyTypeEnum.getRejectedNameByType(-1));
} }
@Test @Test
void testGetRejectedPolicyTypeEnumByName() { public void testGetRejectedPolicyTypeEnumByName() {
// check legal range of name // check legal range of name
Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> Arrays.stream(RejectedPolicyTypeEnum.values()).forEach(each -> Assertions.assertEquals(each, RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(each.getName())));
Assertions.assertEquals(each, RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(each.getName())));
// check illegal name // check illegal name
Assertions.assertEquals(RejectedPolicyTypeEnum.ABORT_POLICY, Assertions.assertEquals(RejectedPolicyTypeEnum.ABORT_POLICY,
RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName("XXX")); RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName("XXX"));

@ -19,14 +19,14 @@ package cn.hippo4j.common.function;
import cn.hippo4j.common.extension.function.NoArgsConsumer; import cn.hippo4j.common.extension.function.NoArgsConsumer;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import org.junit.jupiter.api.Test; import org.junit.Test;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
final class NoArgsConsumerTest { public final class NoArgsConsumerTest {
@Test @Test
void accept() { public void accept() {
AtomicBoolean checkValue = new AtomicBoolean(false); AtomicBoolean checkValue = new AtomicBoolean(false);
NoArgsConsumer noArgsConsumer = () -> checkValue.set(true); NoArgsConsumer noArgsConsumer = () -> checkValue.set(true);
noArgsConsumer.accept(); noArgsConsumer.accept();

@ -17,7 +17,7 @@
package cn.hippo4j.common.toolkit; package cn.hippo4j.common.toolkit;
import org.junit.jupiter.api.Test; import org.junit.Test;
public class UserContextTest { public class UserContextTest {

@ -18,46 +18,45 @@
package cn.hippo4j.common.toolkit.logtracing; package cn.hippo4j.common.toolkit.logtracing;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.BeforeEach; import org.junit.Before;
import org.junit.jupiter.api.Test; import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class LogMessageTest { public class LogMessageTest {
private final static String MESSAGE = "message"; private final static String MESSAGE = "message";
private final static String THROWABLE_MESSAGE = "throwable message"; private final static String THROWABLE_MESSAGE = "throwable message";
private LogMessage logMessage; private LogMessage logMessage;
@BeforeEach @Before
public void init() { public void init() {
logMessage = LogMessage.getInstance(); logMessage = LogMessage.getInstance();
} }
@Test @Test
void testGetInstanceShouldReturnANewLogMessageInstance() { public void testGetInstanceShouldReturnANewLogMessageInstance() {
final LogMessage newInstance = LogMessage.getInstance(); final LogMessage newInstance = LogMessage.getInstance();
assertNotNull(newInstance); assertNotNull(newInstance);
assertNotSame(logMessage, newInstance); assertNotSame(logMessage, newInstance);
} }
@Test @Test
void testToStringShouldHaveAnEmptyMessage() { public void testToStringShouldHaveAnEmptyMessage() {
assertEquals(Strings.EMPTY, logMessage.toString()); assertEquals(Strings.EMPTY, logMessage.toString());
} }
@Test @Test
void testSetMsgShouldSetAnewMessageInLogMessage() { public void testSetMsgShouldSetAnewMessageInLogMessage() {
logMessage.setMsg(MESSAGE); logMessage.setMsg(MESSAGE);
assertEquals(MESSAGE, logMessage.toString()); assertEquals(MESSAGE, logMessage.toString());
} }
@Test @Test
void testMsgShouldContainsMessageAndThrowableMessage() { public void testMsgShouldContainsMessageAndThrowableMessage() {
final String message = logMessage.msg(MESSAGE, new Throwable(THROWABLE_MESSAGE)); final String message = logMessage.msg(MESSAGE, new Throwable(THROWABLE_MESSAGE));
assertNotNull(message); assertNotNull(message);
assertTrue(message.contains(MESSAGE)); assertTrue(message.contains(MESSAGE));
@ -65,20 +64,20 @@ class LogMessageTest {
} }
@Test @Test
void testKvShouldPutKeyAndValue() { public void testKvShouldPutKeyAndValue() {
logMessage.kv("key", "value"); logMessage.kv("key", "value");
assertEquals("key=value", logMessage.toString()); assertEquals("key=value", logMessage.toString());
} }
@Test @Test
void testKvShouldPutAllKeyAndValuePairs() { public void testKvShouldPutAllKeyAndValuePairs() {
logMessage.kv("key1", "value1"); logMessage.kv("key1", "value1");
logMessage.kv("key2", "value2"); logMessage.kv("key2", "value2");
assertEquals("key1=value1||key2=value2", logMessage.toString()); assertEquals("key1=value1||key2=value2", logMessage.toString());
} }
@Test @Test
void testToStringShouldPrintMessageAndAllKeyAndValuePairs() { public void testToStringShouldPrintMessageAndAllKeyAndValuePairs() {
logMessage.setMsg(MESSAGE); logMessage.setMsg(MESSAGE);
logMessage.kv("key1", "value1"); logMessage.kv("key1", "value1");
logMessage.kv("key2", "value2"); logMessage.kv("key2", "value2");
@ -86,7 +85,7 @@ class LogMessageTest {
} }
@Test @Test
void testKv2StringShouldPrintMessageAndAllKeyAndValuePairs() { public void testKv2StringShouldPrintMessageAndAllKeyAndValuePairs() {
String result = logMessage.kv2String("key", "value"); String result = logMessage.kv2String("key", "value");
assertEquals("key=value", result); assertEquals("key=value", result);
} }

@ -17,24 +17,24 @@
package cn.hippo4j.core.executor.state; package cn.hippo4j.core.executor.state;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.runner.RunWith;
import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ExtendWith(MockitoExtension.class) @RunWith(MockitoJUnitRunner.class)
public class AbstractThreadPoolRuntimeTest { public class AbstractThreadPoolRuntimeTest {
@Test @Test
void testPoolRunState() { public void testPoolRunState() {
AbstractThreadPoolRuntime threadPoolRuntime = new AbstractThreadPoolRuntime() { AbstractThreadPoolRuntime threadPoolRuntime = new AbstractThreadPoolRuntime() {
@Override @Override

@ -18,15 +18,15 @@
package cn.hippo4j.auth.filter; package cn.hippo4j.auth.filter;
import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ReflectUtil;
import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
class JWTAuthenticationFilterTest { public class JWTAuthenticationFilterTest {
@Test @Test
void getMessageTest() { public void getMessageTest() {
JWTAuthenticationFilter filter = new JWTAuthenticationFilter(null); JWTAuthenticationFilter filter = new JWTAuthenticationFilter(null);
Assertions.assertEquals("用户不存在", ReflectUtil.invoke(filter, Assertions.assertEquals("用户不存在", ReflectUtil.invoke(filter,
"getMessage", new UsernameNotFoundException(""))); "getMessage", new UsernameNotFoundException("")));

@ -18,12 +18,12 @@
package cn.hippo4j.auth.service.impl; package cn.hippo4j.auth.service.impl;
import org.junit.Assert; import org.junit.Assert;
import org.junit.jupiter.api.Test; import org.junit.Test;
class UserServiceImplTest { public class UserServiceImplTest {
@Test @Test
void checkPasswordLength() { public void testCheckPasswordLength() {
// 密码为null、空串、过短、过长都会抛出异常 // 密码为null、空串、过短、过长都会抛出异常
UserServiceImpl userService = new UserServiceImpl(null, null, null); UserServiceImpl userService = new UserServiceImpl(null, null, null);
Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(null)); Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(null));

@ -18,8 +18,8 @@
package cn.hippo4j.auth.toolkit; package cn.hippo4j.auth.toolkit;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import org.junit.jupiter.api.BeforeEach; import org.junit.Before;
import org.junit.jupiter.api.Test; import org.junit.Test;
public final class JwtTokenUtilTest { public final class JwtTokenUtilTest {
@ -33,7 +33,7 @@ public final class JwtTokenUtilTest {
private String token; private String token;
@BeforeEach @Before
public void setUp() { public void setUp() {
token = JwtTokenUtil.createToken(userId, username, role, isRememberMe); token = JwtTokenUtil.createToken(userId, username, role, isRememberMe);
} }

@ -21,7 +21,7 @@ import cn.hippo4j.common.model.Result;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.server.common.base.exception.AbstractException; import cn.hippo4j.server.common.base.exception.AbstractException;
import cn.hippo4j.server.common.base.exception.ErrorCode; import cn.hippo4j.server.common.base.exception.ErrorCode;
import org.junit.jupiter.api.Test; import org.junit.Test;
import static cn.hippo4j.server.common.base.exception.ErrorCodeEnum.SERVICE_ERROR; import static cn.hippo4j.server.common.base.exception.ErrorCodeEnum.SERVICE_ERROR;

Loading…
Cancel
Save