Add ifCan utility method

This commit is contained in:
2024-03-29 08:26:40 -05:00
parent d0de637dee
commit f3efb341fc
2 changed files with 42 additions and 0 deletions

View File

@ -25,7 +25,9 @@ package com.kingsrook.qqq.backend.core.utils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
@ -79,4 +81,20 @@ class ObjectUtilsTest
assertEquals("else", ObjectUtils.tryAndRequireNonNullElse(() -> null, "else"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testIfCan()
{
Object nullObject = null;
assertTrue(ObjectUtils.ifCan(() -> true));
assertTrue(ObjectUtils.ifCan(() -> "a".equals("a")));
assertFalse(ObjectUtils.ifCan(() -> 1 == 2));
assertFalse(ObjectUtils.ifCan(() -> nullObject.equals("a")));
assertFalse(ObjectUtils.ifCan(() -> null));
}
}