blob: de8df283afe09ff3f4814f6536b375c194894899 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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));
}
}
|