|
|
@@ -0,0 +1,71 @@
|
|
|
+/*
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ * @copyright Ranides Atterwim
|
|
|
+ * @license WTFPL
|
|
|
+ * @url http://ranides.net/projects/???
|
|
|
+ */
|
|
|
+package net.ranides.assira.trace;
|
|
|
+
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintStream;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import org.junit.Test;
|
|
|
+import static net.ranides.assira.junit.NewAssert.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ */
|
|
|
+public class ExceptionInspectorTest {
|
|
|
+
|
|
|
+ public ExceptionInspectorTest() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCauseStream() {
|
|
|
+ Exception e = new IOException(new RuntimeException(new IllegalArgumentException()));
|
|
|
+
|
|
|
+ List<String> s = ExceptionInspector.getCauseStream(e).map((f)->f.getClass().getName()).collect(Collectors.toList());
|
|
|
+ List<String> expected = Arrays.asList(
|
|
|
+ "java.io.IOException",
|
|
|
+ "java.lang.RuntimeException",
|
|
|
+ "java.lang.IllegalArgumentException"
|
|
|
+ );
|
|
|
+ assertEquals(expected, s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCauseList() {
|
|
|
+ Exception e = new IOException(new RuntimeException(new IllegalArgumentException()));
|
|
|
+
|
|
|
+ List<Throwable> s = ExceptionInspector.getCauseList(e);
|
|
|
+ List<Throwable> expected = Arrays.asList(
|
|
|
+ e,
|
|
|
+ e.getCause(),
|
|
|
+ e.getCause().getCause()
|
|
|
+ );
|
|
|
+ assertEquals(expected, s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testStacktrace() {
|
|
|
+ String st = ExceptionInspector.getStackTrace(new IOException());
|
|
|
+ assertTrue(st.contains("ExceptionInspectorTest"));
|
|
|
+ assertTrue(st.contains("org.junit."));
|
|
|
+ assertTrue(st.contains("org.apache.maven."));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRethrow() {
|
|
|
+ assertThrows(IOException.class, this::rm);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void rm() {
|
|
|
+ ExceptionInspector.rethrow(new IOException());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|