aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java')
-rw-r--r--container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java
new file mode 100644
index 00000000000..de8df283afe
--- /dev/null
+++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ExceptionWrapperTest.java
@@ -0,0 +1,51 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.http.server.jetty;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Check basic error message formatting. Do note these tests are sensitive to
+ * the line numbering in this file. (And that's a feature, not a bug.)
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class ExceptionWrapperTest {
+
+ @Test
+ public final void requireNoMessageIsOK() {
+ final Throwable t = new Throwable();
+ final ExceptionWrapper e = new ExceptionWrapper(t);
+ final String expected = "Throwable() at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:19)";
+
+ assertThat(e.getMessage(), equalTo(expected));
+ }
+
+ @Test
+ public final void requireAllWrappedLevelsShowUp() {
+ final Throwable t0 = new Throwable("t0");
+ final Throwable t1 = new Throwable("t1", t0);
+ final Throwable t2 = new Throwable("t2", t1);
+ final ExceptionWrapper e = new ExceptionWrapper(t2);
+ final String expected = "Throwable(\"t2\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:30):"
+ + " Throwable(\"t1\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:29):"
+ + " Throwable(\"t0\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:28)";
+
+ assertThat(e.getMessage(), equalTo(expected));
+ }
+
+ @Test
+ public final void requireMixOfMessageAndNoMessageWorks() {
+ final Throwable t0 = new Throwable("t0");
+ final Throwable t1 = new Throwable(t0);
+ final Throwable t2 = new Throwable("t2", t1);
+ final ExceptionWrapper e = new ExceptionWrapper(t2);
+ final String expected = "Throwable(\"t2\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:43):"
+ + " Throwable(\"java.lang.Throwable: t0\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:42):"
+ + " Throwable(\"t0\") at com.yahoo.jdisc.http.server.jetty.ExceptionWrapperTest(ExceptionWrapperTest.java:41)";
+
+ assertThat(e.getMessage(), equalTo(expected));
+ }
+}