fix(bug): change ObjectUtil.defaultIfXXX param type Supplier to Function

This commit is contained in:
youtiaoguagua
2022-09-11 00:16:46 +08:00
parent 4696576598
commit df98df70bb
12 changed files with 140 additions and 45 deletions

View File

@@ -15,15 +15,15 @@ import java.util.Map;
public class ObjectUtilTest {
@Test
public void equalsTest(){
public void equalsTest() {
Object a = null;
Object b = null;
Assert.assertTrue(ObjectUtil.equals(a, b));
}
@Test
public void lengthTest(){
int[] array = new int[]{1,2,3,4,5};
public void lengthTest() {
int[] array = new int[]{1, 2, 3, 4, 5};
int length = ObjectUtil.length(array);
Assert.assertEquals(5, length);
@@ -36,8 +36,8 @@ public class ObjectUtilTest {
}
@Test
public void containsTest(){
int[] array = new int[]{1,2,3,4,5};
public void containsTest() {
int[] array = new int[]{1, 2, 3, 4, 5};
final boolean contains = ObjectUtil.contains(array, 1);
Assert.assertTrue(contains);
@@ -73,6 +73,14 @@ public class ObjectUtilTest {
Instant result2 = ObjectUtil.defaultIfNull(nullValue,
() -> DateUtil.parse(nullValue, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant.now());
Assert.assertNotNull(result2);
Obj obj = new Obj();
Obj objNull = null;
String result3 = ObjectUtil.defaultIfNull(obj, (a) -> obj.doSomeThing(), "fail");
Assert.assertNotNull(result3);
String result4 = ObjectUtil.defaultIfNull(objNull, Obj::doSomeThing, "fail");
Assert.assertNotNull(result4);
}
@Test
@@ -88,14 +96,14 @@ public class ObjectUtilTest {
}
@Test
public void isBasicTypeTest(){
public void isBasicTypeTest() {
int a = 1;
final boolean basicType = ObjectUtil.isBasicType(a);
Assert.assertTrue(basicType);
}
@Test
public void isNotNullTest(){
public void isNotNullTest() {
String a = null;
Assert.assertFalse(ObjectUtil.isNotNull(a));
}