This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 9ad6d947e More tests
9ad6d947e is described below
commit 9ad6d947e9402e6940c90dc0c2b08c8fb44f202b
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Jan 4 15:14:57 2024 -0500
More tests
---
.../lang3/exception/ExceptionUtilsTest.java | 41 +++++++++++++++++++---
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git
a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
index 891513077..a18ff5a3d 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
@@ -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