添加日志依赖,方便测试时进行日志输出。

feature/net-util
ZhouXY108 2023-04-15 02:48:15 +08:00
parent 0fa1fc3964
commit de73ce4184
4 changed files with 36 additions and 19 deletions

View File

@ -38,8 +38,15 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>

View File

@ -2,21 +2,27 @@ package xyz.zhouxy.plusone.commons;
import static org.junit.jupiter.api.Assertions.assertEquals;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import xyz.zhouxy.plusone.commons.util.Enumeration;
import javax.annotation.Nonnull;
import java.util.Collection;
@Slf4j
class EnumerationTests {
@Test
void testEnumeration() {
assertEquals(EntityStatus.AVAILABLE, EntityStatus.of(0));
log.info(EntityStatus.constants().toString());
}
}
final class EntityStatus extends Enumeration<EntityStatus> {
private EntityStatus(int value, String name) {
private EntityStatus(int value, @Nonnull String name) {
super(value, name);
}
@ -24,16 +30,16 @@ final class EntityStatus extends Enumeration<EntityStatus> {
public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常");
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
AVAILABLE,
DISABLED);
private static final ValueSet<EntityStatus> ENUMERATION_VALUES = new ValueSet<>(
AVAILABLE, DISABLED);
@Nonnull
public static EntityStatus of(int value) {
return ENUMERATION_VALUES.get(value);
}
@Override
public String toString() {
return "EntityStatus" + super.toString();
@Nonnull
public static Collection<EntityStatus> constants() {
return ENUMERATION_VALUES.getValues();
}
}

View File

@ -3,8 +3,10 @@ package xyz.zhouxy.plusone.commons.util;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
@Slf4j
class NumberUtilTest {
@Test
void testSum() {
@ -12,24 +14,24 @@ class NumberUtilTest {
for (int i = 0; i < Integer.MAX_VALUE; i++) {
result += Short.MAX_VALUE;
}
System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE);
System.out.println("result: " + result);
log.info("Integer.MAX_VALUE: {}", Integer.MAX_VALUE);
log.info("result: {}", result);
assertFalse(Integer.MAX_VALUE > result);
result = 0;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
result += Short.MAX_VALUE;
}
System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE);
System.out.println("result: " + result);
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
log.info("result: {}", result);
assertTrue(Long.MAX_VALUE > result);
result = 0;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
result += Integer.MAX_VALUE;
}
System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE);
System.out.println("result: " + result);
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
log.info("result: {}", result);
assertTrue(Long.MAX_VALUE > result);
}
}

View File

@ -2,8 +2,10 @@ package xyz.zhouxy.plusone.commons.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
@Slf4j
class RestfulResultTest {
@Test
@ -11,24 +13,24 @@ class RestfulResultTest {
String str = null;
RestfulResult result = RestfulResult.successIf(str != null, "成功")
.orError();
System.out.println(result);
log.info(result.toString());
assertEquals(RestfulResult.DEFAULT_ERROR_STATUS, result.getStatus());
result = RestfulResult.successIf(str != null, "成功")
.orError(2333, "失败");
System.out.println(result);
log.info(result.toString());
assertEquals(2333, result.getStatus());
assertEquals("失败", result.getMessage());
str = "";
result = RestfulResult.successIf(str != null, "成功")
.orError();
System.out.println(result);
log.info(result.toString());
assertEquals(RestfulResult.SUCCESS_STATUS, result.getStatus());
result = RestfulResult.successIf(str != null, "成功", str)
.orError(2333, "失败");
System.out.println(result);
log.info(result.toString());
assertEquals("成功", result.getMessage());
}
}