added tests for util class

This commit is contained in:
wea_ondara
2022-11-24 14:15:52 +01:00
parent 65570d0029
commit 237be45dc3

View 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());
}
}