forked from plusone/plusone-commons
添加日志依赖,方便测试时进行日志输出。
parent
0fa1fc3964
commit
de73ce4184
7
pom.xml
7
pom.xml
|
@ -38,8 +38,15 @@
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.2.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
|
|
@ -2,21 +2,27 @@ package xyz.zhouxy.plusone.commons;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
class EnumerationTests {
|
class EnumerationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEnumeration() {
|
void testEnumeration() {
|
||||||
assertEquals(EntityStatus.AVAILABLE, EntityStatus.of(0));
|
assertEquals(EntityStatus.AVAILABLE, EntityStatus.of(0));
|
||||||
|
log.info(EntityStatus.constants().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class EntityStatus extends Enumeration<EntityStatus> {
|
final class EntityStatus extends Enumeration<EntityStatus> {
|
||||||
|
|
||||||
private EntityStatus(int value, String name) {
|
private EntityStatus(int value, @Nonnull String name) {
|
||||||
super(value, 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 AVAILABLE = new EntityStatus(0, "正常");
|
||||||
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
public static final EntityStatus DISABLED = new EntityStatus(1, "禁用");
|
||||||
|
|
||||||
private static final EnumerationValuesHolder<EntityStatus> ENUMERATION_VALUES = new EnumerationValuesHolder<>(
|
private static final ValueSet<EntityStatus> ENUMERATION_VALUES = new ValueSet<>(
|
||||||
AVAILABLE,
|
AVAILABLE, DISABLED);
|
||||||
DISABLED);
|
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public static EntityStatus of(int value) {
|
public static EntityStatus of(int value) {
|
||||||
return ENUMERATION_VALUES.get(value);
|
return ENUMERATION_VALUES.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Nonnull
|
||||||
public String toString() {
|
public static Collection<EntityStatus> constants() {
|
||||||
return "EntityStatus" + super.toString();
|
return ENUMERATION_VALUES.getValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
class NumberUtilTest {
|
class NumberUtilTest {
|
||||||
@Test
|
@Test
|
||||||
void testSum() {
|
void testSum() {
|
||||||
|
@ -12,24 +14,24 @@ class NumberUtilTest {
|
||||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||||
result += Short.MAX_VALUE;
|
result += Short.MAX_VALUE;
|
||||||
}
|
}
|
||||||
System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE);
|
log.info("Integer.MAX_VALUE: {}", Integer.MAX_VALUE);
|
||||||
System.out.println("result: " + result);
|
log.info("result: {}", result);
|
||||||
assertFalse(Integer.MAX_VALUE > result);
|
assertFalse(Integer.MAX_VALUE > result);
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||||
result += Short.MAX_VALUE;
|
result += Short.MAX_VALUE;
|
||||||
}
|
}
|
||||||
System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE);
|
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
|
||||||
System.out.println("result: " + result);
|
log.info("result: {}", result);
|
||||||
assertTrue(Long.MAX_VALUE > result);
|
assertTrue(Long.MAX_VALUE > result);
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||||
result += Integer.MAX_VALUE;
|
result += Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE);
|
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
|
||||||
System.out.println("result: " + result);
|
log.info("result: {}", result);
|
||||||
assertTrue(Long.MAX_VALUE > result);
|
assertTrue(Long.MAX_VALUE > result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package xyz.zhouxy.plusone.commons.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
class RestfulResultTest {
|
class RestfulResultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -11,24 +13,24 @@ class RestfulResultTest {
|
||||||
String str = null;
|
String str = null;
|
||||||
RestfulResult result = RestfulResult.successIf(str != null, "成功")
|
RestfulResult result = RestfulResult.successIf(str != null, "成功")
|
||||||
.orError();
|
.orError();
|
||||||
System.out.println(result);
|
log.info(result.toString());
|
||||||
assertEquals(RestfulResult.DEFAULT_ERROR_STATUS, result.getStatus());
|
assertEquals(RestfulResult.DEFAULT_ERROR_STATUS, result.getStatus());
|
||||||
|
|
||||||
result = RestfulResult.successIf(str != null, "成功")
|
result = RestfulResult.successIf(str != null, "成功")
|
||||||
.orError(2333, "失败");
|
.orError(2333, "失败");
|
||||||
System.out.println(result);
|
log.info(result.toString());
|
||||||
assertEquals(2333, result.getStatus());
|
assertEquals(2333, result.getStatus());
|
||||||
assertEquals("失败", result.getMessage());
|
assertEquals("失败", result.getMessage());
|
||||||
|
|
||||||
str = "";
|
str = "";
|
||||||
result = RestfulResult.successIf(str != null, "成功")
|
result = RestfulResult.successIf(str != null, "成功")
|
||||||
.orError();
|
.orError();
|
||||||
System.out.println(result);
|
log.info(result.toString());
|
||||||
assertEquals(RestfulResult.SUCCESS_STATUS, result.getStatus());
|
assertEquals(RestfulResult.SUCCESS_STATUS, result.getStatus());
|
||||||
|
|
||||||
result = RestfulResult.successIf(str != null, "成功", str)
|
result = RestfulResult.successIf(str != null, "成功", str)
|
||||||
.orError(2333, "失败");
|
.orError(2333, "失败");
|
||||||
System.out.println(result);
|
log.info(result.toString());
|
||||||
assertEquals("成功", result.getMessage());
|
assertEquals("成功", result.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue