More tests

This commit is contained in:
Gary Gregory 2024-01-04 15:14:57 -05:00
parent e728fab132
commit 9ad6d947e9
1 changed files with 37 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -206,8 +207,23 @@ public class ExceptionUtilsTest extends AbstractLangTest {
@Test
public void testAsRuntimeException() {
final Exception expected = new InterruptedException();
final Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.asRuntimeException(expected));
assertSame(expected, actual);
assertSame(expected, assertThrows(Exception.class, () -> ExceptionUtils.asRuntimeException(expected)));
assertNotSame(expected, assertThrows(Exception.class, () -> ExceptionUtils.asRuntimeException(new InterruptedException())));
// API return typed to compile to Object
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final Object retVal = ExceptionUtils.asRuntimeException(expected);
});
// API return typed to compile to RuntimeException
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final RuntimeException retVal = ExceptionUtils.asRuntimeException(expected);
});
// API return typed to compile to RuntimeException subclass
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final IllegalStateException retVal = ExceptionUtils.asRuntimeException(expected);
});
}
@Test
@ -727,11 +743,28 @@ public class ExceptionUtilsTest extends AbstractLangTest {
assertThrows(NullPointerException.class, () -> ExceptionUtils.removeCommonFrames(null, null));
}
@SuppressWarnings("deprecation")
@Test
public void testRethrow() {
final Exception expected = new InterruptedException();
final Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected));
assertSame(expected, actual);
// API return typed to compile to Object
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final Object retVal = ExceptionUtils.rethrow(expected);
});
// API return typed to compile to Object subclass
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final String retVal = ExceptionUtils.rethrow(expected);
});
// API return typed to compile to primitive
assertThrows(expected.getClass(), () -> {
@SuppressWarnings("unused")
final int retVal = ExceptionUtils.rethrow(expected);
});
//
assertSame(expected, assertThrows(expected.getClass(), () -> ExceptionUtils.rethrow(expected)));
assertNotSame(expected, assertThrows(expected.getClass(), () -> ExceptionUtils.rethrow(new InterruptedException())));
}
@Test