From 5e450a9bdb5c90ff5f4bc5d019781927abdc01e1 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 9 Oct 2024 18:45:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95=E5=90=8D?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/util/EnumTools.java | 2 +- .../zhouxy/plusone/commons/util/PreconditionsExt.java | 2 +- .../plusone/commons/util/PreconditionsExtTests.java | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumTools.java b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumTools.java index f77d7c2..882e75d 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumTools.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumTools.java @@ -46,7 +46,7 @@ public final class EnumTools { public static > E valueOf(Class clazz, int ordinal) { // NOSONAR 该方法弃用,但不删掉 Preconditions.checkNotNull(clazz, "Clazz must not be null."); E[] values = clazz.getEnumConstants(); - PreconditionsExt.check((ordinal >= 0 && ordinal < values.length), + PreconditionsExt.checkCondition((ordinal >= 0 && ordinal < values.length), () -> new EnumConstantNotPresentException(clazz, Integer.toString(ordinal))); return values[ordinal]; } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java index 69e7e9e..a0bdef3 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java @@ -32,7 +32,7 @@ import com.google.common.base.Preconditions; */ public class PreconditionsExt { - public static void check(boolean condition, @Nonnull Supplier e) throws E { + public static void checkCondition(boolean condition, @Nonnull Supplier e) throws E { if (!condition) { throw e.get(); } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/PreconditionsExtTests.java b/src/test/java/xyz/zhouxy/plusone/commons/util/PreconditionsExtTests.java index 1961427..a6114d0 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/util/PreconditionsExtTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/PreconditionsExtTests.java @@ -2,17 +2,20 @@ package xyz.zhouxy.plusone.commons.util; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.*; +@Slf4j class PreconditionsExtTests { @Test void testCheck() { assertThrows(TestException.class, () -> { - PreconditionsExt.check(false, () -> new TestException("Test error message.")); + PreconditionsExt.checkCondition(false, () -> new TestException("Test error message.")); }); } @@ -25,7 +28,7 @@ class PreconditionsExtTests { Object obj = new Object(); assertNotNull(obj); assertThrows(NullPointerException.class, - () -> PreconditionsExt.checkAllNotNull(new Object[]{obj, null})); + () -> PreconditionsExt.checkAllNotNull(new Object[] { obj, null })); assertThrows(NullPointerException.class, () -> PreconditionsExt.checkAllNotNull(obj, null)); List list = Arrays.asList(obj, null); @@ -33,7 +36,7 @@ class PreconditionsExtTests { assertThrows(NullPointerException.class, () -> PreconditionsExt.checkAllNotNull(list)); - PreconditionsExt.checkAllNotNull(new Object[]{obj, "Test"}); + PreconditionsExt.checkAllNotNull(new Object[] { obj, "Test" }); PreconditionsExt.checkAllNotNull(obj, "Test"); PreconditionsExt.checkAllNotNull(Arrays.asList(obj, "Test")); }