diff options
author | Gary Gregory <garydgregory@gmail.com> | 2022-06-18 13:02:50 -0400 |
---|---|---|
committer | Gary Gregory <garydgregory@gmail.com> | 2022-06-18 13:02:50 -0400 |
commit | 7912894eb8545ea076732a95dc0124d6426b3e76 (patch) | |
tree | 2890162008a74fdb6d96eefb68658c9636807847 /src/test/java/org/apache | |
parent | df0296f7c2c4507b79754a564fb1dd45f54c8732 (diff) | |
download | apache-commons-lang-7912894eb8545ea076732a95dc0124d6426b3e76.tar.gz |
Sort members
Diffstat (limited to 'src/test/java/org/apache')
-rw-r--r-- | src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java | 68 |
1 files changed, 34 insertions, 34 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 767e3d9d9..38b6127d1 100644 --- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java @@ -287,6 +287,39 @@ public class ExceptionUtilsTest { } @Test + @DisplayName("getStackFrames returns empty string array when the argument is null") + public void testgetStackFramesHappyPath() { + final String[] actual = ExceptionUtils.getStackFrames(new Throwable() { + private static final long serialVersionUID = 1L; + + // provide static stack trace to make test stable + @Override + public void printStackTrace(final PrintWriter s) { + s.write("org.apache.commons.lang3.exception.ExceptionUtilsTest$1\n" + + "\tat org.apache.commons.lang3.exception.ExceptionUtilsTest.testgetStackFramesGappyPath(ExceptionUtilsTest.java:706)\n" + + "\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + + "\tat com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)\n" + + "\tat com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)\n"); + } + }); + + assertArrayEquals(new String[]{ + "org.apache.commons.lang3.exception.ExceptionUtilsTest$1", + "\tat org.apache.commons.lang3.exception.ExceptionUtilsTest.testgetStackFramesGappyPath(ExceptionUtilsTest.java:706)", + "\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", + "\tat com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)", + "\tat com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)" + }, actual); + } + + @Test + @DisplayName("getStackFrames returns the string array of the stack frames when there is a real exception") + public void testgetStackFramesNullArg() { + final String[] actual = ExceptionUtils.getStackFrames((Throwable) null); + assertEquals(0, actual.length); + } + + @Test public void testGetThrowableCount_Throwable() { assertEquals(0, ExceptionUtils.getThrowableCount(null)); assertEquals(1, ExceptionUtils.getThrowableCount(withoutCause)); @@ -464,6 +497,7 @@ public class ExceptionUtilsTest { assertEquals(0, ExceptionUtils.indexOfType(withCause, Throwable.class)); } + @Test public void testIndexOfType_ThrowableClassInt() { assertEquals(-1, ExceptionUtils.indexOfType(null, null, 0)); @@ -500,7 +534,6 @@ public class ExceptionUtilsTest { // internally this method calls stream method anyway } - @Test public void testPrintRootCauseStackTrace_ThrowableStream() { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); @@ -690,37 +723,4 @@ public class ExceptionUtilsTest { final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable())); assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class)); } - - @Test - @DisplayName("getStackFrames returns the string array of the stack frames when there is a real exception") - public void testgetStackFramesNullArg() { - final String[] actual = ExceptionUtils.getStackFrames((Throwable) null); - assertEquals(0, actual.length); - } - - @Test - @DisplayName("getStackFrames returns empty string array when the argument is null") - public void testgetStackFramesHappyPath() { - final String[] actual = ExceptionUtils.getStackFrames(new Throwable() { - private static final long serialVersionUID = 1L; - - // provide static stack trace to make test stable - @Override - public void printStackTrace(final PrintWriter s) { - s.write("org.apache.commons.lang3.exception.ExceptionUtilsTest$1\n" + - "\tat org.apache.commons.lang3.exception.ExceptionUtilsTest.testgetStackFramesGappyPath(ExceptionUtilsTest.java:706)\n" + - "\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + - "\tat com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)\n" + - "\tat com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)\n"); - } - }); - - assertArrayEquals(new String[]{ - "org.apache.commons.lang3.exception.ExceptionUtilsTest$1", - "\tat org.apache.commons.lang3.exception.ExceptionUtilsTest.testgetStackFramesGappyPath(ExceptionUtilsTest.java:706)", - "\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", - "\tat com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)", - "\tat com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)" - }, actual); - } } |