added tests for util class
This commit is contained in:
34
core/src/test/java/jef/util/UtilTest.java
Normal file
34
core/src/test/java/jef/util/UtilTest.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package jef.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class UtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tryGet_NoException() {
|
||||||
|
//setup
|
||||||
|
var object = new Object();
|
||||||
|
|
||||||
|
//test
|
||||||
|
var ret = Util.tryGet(() -> object);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
assertTrue(ret.isPresent());
|
||||||
|
assertEquals(object, ret.orElseThrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tryGet_Exception() {
|
||||||
|
//test
|
||||||
|
var ret = Util.tryGet(() -> {
|
||||||
|
throw new Exception();
|
||||||
|
});
|
||||||
|
|
||||||
|
//assert
|
||||||
|
assertFalse(ret.isPresent());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user