增加Assert的equals及notEquals

This commit is contained in:
mo_chou_555
2022-05-03 12:31:55 +08:00
parent 50d77194c8
commit 2a9eaa6a7f
2 changed files with 121 additions and 2 deletions

View File

@@ -1,9 +1,10 @@
package cn.hutool.core.lang;
import cn.hutool.core.util.StrUtil;
import org.junit.Test;
public class AssertTest {
@Test
public void isNullTest(){
String a = null;
@@ -33,6 +34,30 @@ public class AssertTest {
public void isTrueTest3() {
int i = -1;
//noinspection ConstantConditions
Assert.isTrue(i > 0, ()-> new IndexOutOfBoundsException("relation message to return"));
Assert.isTrue(i > 0, () -> new IndexOutOfBoundsException("relation message to return"));
}
@Test
public void isEqualsTest() {
//String a="ab";
//final String b = new String("abc");
String a = null;
final String b = null;
Assert.isEquals(a, b);
Assert.isEquals(a, b, "{}不等于{}", a, b);
Assert.isEquals(a, b, () -> new RuntimeException(StrUtil.format("{}和{}不相等", a, b)));
}
@Test
public void notEqualsTest() {
//String c="19";
//final String d = new String("19");
String c = null;
final String d = null;
//Assert.notEquals(c,d);
//Assert.notEquals(c,d,"{}等于{}",c,d);
Assert.notEquals(c, d, () -> new RuntimeException(StrUtil.format("{}和{}相等", c, d)));
}
}