From de73ce4184e61d72001c9bb18c021ceb02268601 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 15 Apr 2023 02:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=B5=8B=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +++++++- .../plusone/commons/EnumerationTests.java | 22 ++++++++++++------- .../plusone/commons/util/NumberUtilTest.java | 14 +++++++----- .../commons/util/RestfulResultTest.java | 10 +++++---- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 9ebd1b5..3c3373a 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,15 @@ org.projectlombok lombok ${lombok.version} + compile true + + ch.qos.logback + logback-classic + 1.2.11 + test + org.junit.jupiter @@ -48,4 +55,4 @@ test - \ No newline at end of file + diff --git a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java index 6e950a7..6e6d552 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java @@ -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 { - 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 { public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常"); public static final EntityStatus DISABLED = new EntityStatus(1, "禁用"); - private static final EnumerationValuesHolder ENUMERATION_VALUES = new EnumerationValuesHolder<>( - AVAILABLE, - DISABLED); + private static final ValueSet 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 constants() { + return ENUMERATION_VALUES.getValues(); } -} \ No newline at end of file +} diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java b/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java index f330013..3c42b12 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java @@ -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); } } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/RestfulResultTest.java b/src/test/java/xyz/zhouxy/plusone/commons/util/RestfulResultTest.java index 177d05a..6255a67 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/util/RestfulResultTest.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/RestfulResultTest.java @@ -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()); } }