1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.assertions;
18
19 import static org.apache.juneau.assertions.Assertions.*;
20
21 import org.apache.juneau.*;
22 import org.apache.juneau.utest.utils.*;
23 import org.junit.jupiter.api.*;
24
25 @SuppressWarnings("serial")
26 @Deprecated
27 class Assertion_Test extends TestBase {
28
29
30
31
32
33 public static class A1 extends RuntimeException {
34 public A1(String msg, Throwable cause) { super(msg, cause); }
35 }
36
37 public static class A2 extends RuntimeException {
38 public A2(String msg, Throwable cause) { super(msg, cause); }
39 }
40
41 public static class A3 extends RuntimeException {
42 public A3(String msg) { throw new A2("fromA3", null); }
43 }
44
45 public static class A extends StringAssertion {
46 public A(Object text) { super(text); }
47 public A doError() { throw error(new A1("foo", null), "bar {0}", "baz"); }
48 }
49
50
51
52
53
54 @Test void a01_basicErrorHandling() {
55 var a = new A("");
56 a.setSilent();
57
58 assertThrown(a::doError)
59 .isExactType(BasicAssertionError.class)
60 .asMessage().is("bar baz")
61 .asCausedBy().isExactType(A1.class)
62 .asCausedBy().asMessage().is("foo")
63 .asCausedBy().asCausedBy().isNull();
64
65 a.setThrowable(A2.class);
66 assertThrown(a::doError)
67 .isExactType(A2.class)
68 .asMessage().is("bar baz")
69 .asCausedBy().isExactType(A1.class)
70 .asCausedBy().asMessage().is("foo")
71 .asCausedBy().asCausedBy().isNull();
72
73 a.setThrowable(A3.class);
74 assertThrown(a::doError)
75 .isExactType(BasicRuntimeException.class)
76 .asMessage().is("bar baz")
77 .asCausedBy().isExactType(A1.class)
78 .asCausedBy().asMessage().is("foo")
79 .asCausedBy().asCausedBy().isNull();
80 }
81
82 @SuppressWarnings("unused")
83 @Test void a02_out() {
84 var out = new CapturingPrintStream();
85
86 try {
87 assertString("x").setOut(out).isNull();
88 } catch (BasicAssertionError e) { }
89
90 assertString(out).isContains("Value was not null.");
91 }
92 }