add methods

This commit is contained in:
Looly 2022-05-05 09:20:02 +08:00
parent 5b61f07259
commit 56b0c907e9
3 changed files with 12 additions and 11 deletions

View File

@ -3,7 +3,7 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.0.M5 (2022-04-28) # 5.8.0.M5 (2022-05-05)
### ❌不兼容特性 ### ❌不兼容特性
* 【extra 】 升级jakarta.validation-api到3.x包名变更导致不能向下兼容 * 【extra 】 升级jakarta.validation-api到3.x包名变更导致不能向下兼容
@ -12,6 +12,7 @@
### 🐣新特性 ### 🐣新特性
* 【core 】 Singleton增加部分方法pr#609@Gitee * 【core 】 Singleton增加部分方法pr#609@Gitee
* 【core 】 BeanUtil增加beanToMap重载pr#2292@Github * 【core 】 BeanUtil增加beanToMap重载pr#2292@Github
* 【core 】 Assert增加对应的equals及notEquals方法pr#612@Gitee
### 🐞Bug修复 ### 🐞Bug修复
* 【db 】 修复RedisDS无法设置maxWaitMillis问题issue#I54TZ9@Gitee * 【db 】 修复RedisDS无法设置maxWaitMillis问题issue#I54TZ9@Gitee

View File

@ -1060,8 +1060,8 @@ public class Assert {
* @param obj2 对象2 * @param obj2 对象2
* @throws IllegalArgumentException obj1 must be equals obj2 * @throws IllegalArgumentException obj1 must be equals obj2
*/ */
public static void isEquals(Object obj1, Object obj2) { public static void equals(Object obj1, Object obj2) {
isEquals(obj1, obj2, "({}) must be equals ({})", obj1, obj2); equals(obj1, obj2, "({}) must be equals ({})", obj1, obj2);
} }
/** /**
@ -1076,8 +1076,8 @@ public class Assert {
* @param params 异常信息参数用于替换"{}"占位符 * @param params 异常信息参数用于替换"{}"占位符
* @throws IllegalArgumentException obj1 must be equals obj2 * @throws IllegalArgumentException obj1 must be equals obj2
*/ */
public static void isEquals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws IllegalArgumentException { public static void equals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
isEquals(obj1, obj2, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params))); equals(obj1, obj2, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
} }
/** /**
@ -1089,7 +1089,7 @@ public class Assert {
* @param <X> 异常类型 * @param <X> 异常类型
* @throws X obj1 must be equals obj2 * @throws X obj1 must be equals obj2
*/ */
public static <X extends Throwable> void isEquals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X { public static <X extends Throwable> void equals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X {
if (ObjectUtil.notEqual(obj1, obj2)) { if (ObjectUtil.notEqual(obj1, obj2)) {
throw errorSupplier.get(); throw errorSupplier.get();
} }

View File

@ -38,14 +38,14 @@ public class AssertTest {
} }
@Test @Test
public void isEqualsTest() { public void equalsTest() {
//String a="ab"; //String a="ab";
//final String b = new String("abc"); //final String b = new String("abc");
String a = null; String a = null;
final String b = null; final String b = null;
Assert.isEquals(a, b); Assert.equals(a, b);
Assert.isEquals(a, b, "{}不等于{}", a, b); Assert.equals(a, b, "{}不等于{}", a, b);
Assert.isEquals(a, b, () -> new RuntimeException(StrUtil.format("{}和{}不相等", a, b))); Assert.equals(a, b, () -> new RuntimeException(StrUtil.format("{}和{}不相等", a, b)));
} }
@Test @Test
@ -53,7 +53,7 @@ public class AssertTest {
//String c="19"; //String c="19";
//final String d = new String("19"); //final String d = new String("19");
String c = null; String c = null;
final String d = null; final String d = "null";
//Assert.notEquals(c,d); //Assert.notEquals(c,d);
//Assert.notEquals(c,d,"{}等于{}",c,d); //Assert.notEquals(c,d,"{}等于{}",c,d);
Assert.notEquals(c, d, () -> new RuntimeException(StrUtil.format("{}和{}相等", c, d))); Assert.notEquals(c, d, () -> new RuntimeException(StrUtil.format("{}和{}相等", c, d)));