25
25
import org .slf4j .LoggerFactory ;
26
26
27
27
import java .util .function .Supplier ;
28
+ import java .util .regex .Pattern ;
29
+
28
30
import org .slf4j .event .Level ;
29
31
30
32
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -38,6 +40,7 @@ public void testAssertExceptionContainsNullEx() throws Throwable {
38
40
try {
39
41
assertExceptionContains ("" , null );
40
42
} catch (AssertionError e ) {
43
+ // AssertionError not actually thrown
41
44
if (!e .toString ().contains (E_NULL_THROWABLE )) {
42
45
throw e ;
43
46
}
@@ -49,6 +52,7 @@ public void testAssertExceptionContainsNullString() throws Throwable {
49
52
try {
50
53
assertExceptionContains ("" , new BrokenException ());
51
54
} catch (AssertionError e ) {
55
+ // AssertionError not actually thrown
52
56
if (!e .toString ().contains (E_NULL_THROWABLE_STRING )) {
53
57
throw e ;
54
58
}
@@ -76,6 +80,51 @@ public void testAssertExceptionContainsWorking() throws Throwable {
76
80
assertExceptionContains ("Expected" , new Exception ("Expected" ));
77
81
}
78
82
83
+ @ Test
84
+ public void testAssertExceptionMatchesNullEx () throws Throwable {
85
+ try {
86
+ assertExceptionMatches (null , null );
87
+ } catch (AssertionError e ) {
88
+ // AssertionError not actually thrown
89
+ if (!e .toString ().contains (E_NULL_THROWABLE )) {
90
+ throw e ;
91
+ }
92
+ }
93
+ }
94
+
95
+ @ Test
96
+ public void testAssertExceptionMatchesNullString () throws Throwable {
97
+ try {
98
+ assertExceptionMatches (null , new BrokenException ());
99
+ } catch (AssertionError e ) {
100
+ // AssertionError not actually thrown
101
+ if (!e .toString ().contains (E_NULL_THROWABLE_STRING )) {
102
+ throw e ;
103
+ }
104
+ }
105
+ }
106
+
107
+ @ Test
108
+ public void testAssertExceptionMatchesWrongText () throws Throwable {
109
+ try {
110
+ assertExceptionMatches (Pattern .compile (".*Expected.*" ), new Exception ("(actual)" ));
111
+ } catch (AssertionError e ) {
112
+ String s = e .toString ();
113
+ if (!s .contains (E_UNEXPECTED_EXCEPTION )
114
+ || !s .contains ("(actual)" ) ) {
115
+ throw e ;
116
+ }
117
+ if (e .getCause () == null ) {
118
+ throw new AssertionError ("No nested cause in assertion" , e );
119
+ }
120
+ }
121
+ }
122
+
123
+ @ Test
124
+ public void testAssertExceptionMatchesWorking () throws Throwable {
125
+ assertExceptionMatches (Pattern .compile (".*Expected.*" ), new Exception ("Expected" ));
126
+ }
127
+
79
128
private static class BrokenException extends Exception {
80
129
public BrokenException () {
81
130
}
0 commit comments