@@ -103,7 +103,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
103
103
@ Test public void
104
104
throwableIsOfMatchingInstance () {
105
105
assertThat (
106
- () -> { throw new IllegalStateException (); },
106
+ new Executable () {
107
+ @ Override
108
+ public void execute () {
109
+ throw new IllegalStateException ();
110
+ }
111
+ },
107
112
throwsInstanceOf (IllegalStateException .class )
108
113
);
109
114
}
@@ -115,7 +120,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
115
120
+ " but: threw but <java.lang.IllegalStateException> is a java.lang.IllegalStateException" ;
116
121
try {
117
122
assertThat (
118
- () -> { throw new IllegalStateException (); },
123
+ new Executable () {
124
+ @ Override
125
+ public void execute () {
126
+ throw new IllegalStateException ();
127
+ }
128
+ },
119
129
throwsInstanceOf (IOException .class )
120
130
);
121
131
fail ("should have failed" );
@@ -128,7 +138,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
128
138
@ Test public void
129
139
throwableHasMatchingMessage () {
130
140
assertThat (
131
- () -> { throw new Exception ("message" ); },
141
+ new Executable () {
142
+ @ Override
143
+ public void execute () throws Exception {
144
+ throw new Exception ("message" );
145
+ }
146
+ },
132
147
doesThrow (withMessage (equalTo ("message" )))
133
148
);
134
149
}
@@ -140,7 +155,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
140
155
+ " but: threw but message was \" actual message\" " ;
141
156
try {
142
157
assertThat (
143
- () -> { throw new Exception ("actual message" ); },
158
+ new Executable () {
159
+ @ Override
160
+ public void execute () throws Exception {
161
+ throw new Exception ("actual message" );
162
+ }
163
+ },
144
164
doesThrow (withMessage ("expected message" ))
145
165
);
146
166
fail ("should have failed" );
@@ -157,7 +177,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
157
177
+ endLine + " but: did not throw" ;
158
178
try {
159
179
assertThat (
160
- () -> {}, // Do nothing
180
+ new Executable () {
181
+ @ Override
182
+ public void execute () {
183
+ // Do nothing
184
+ }
185
+ },
161
186
throwsInstanceOf (NoSuchMethodError .class )
162
187
);
163
188
fail ("should have failed" );
@@ -169,9 +194,15 @@ public void describeMismatch(Object item, Description mismatchDescription) {
169
194
170
195
@ Test public void
171
196
throwableCauseMatches () {
197
+ Matcher <? extends Throwable > instanceOfMatcher = instanceOf (XMLStreamException .class );
172
198
assertThat (
173
- () -> { throw new RuntimeException (new XMLStreamException ()); },
174
- doesThrow (becauseOf (instanceOf (XMLStreamException .class )))
199
+ new Executable () {
200
+ @ Override
201
+ public void execute () {
202
+ throw new RuntimeException (new XMLStreamException ());
203
+ }
204
+ },
205
+ doesThrow (becauseOf (instanceOfMatcher ))
175
206
);
176
207
}
177
208
@@ -181,9 +212,15 @@ public void describeMismatch(Object item, Description mismatchDescription) {
181
212
String expectedMessage = endLine + "Expected: throws because of an instance of java.lang.NullPointerException"
182
213
+ endLine + " but: threw but cause <java.lang.IllegalArgumentException> is a java.lang.IllegalArgumentException" ;
183
214
try {
215
+ Matcher <? extends Throwable > instanceOfMatcher = instanceOf (NullPointerException .class );
184
216
assertThat (
185
- () -> { throw new RuntimeException (new IllegalArgumentException ()); },
186
- doesThrow (becauseOf (instanceOf (NullPointerException .class )))
217
+ new Executable () {
218
+ @ Override
219
+ public void execute () {
220
+ throw new RuntimeException (new IllegalArgumentException ());
221
+ }
222
+ },
223
+ doesThrow (becauseOf (instanceOfMatcher ))
187
224
);
188
225
fail ("should have failed" );
189
226
}
@@ -201,7 +238,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
201
238
try {
202
239
assertThat (
203
240
"Custom message" ,
204
- () -> { throw new IllegalArgumentException (); },
241
+ new Executable () {
242
+ @ Override
243
+ public void execute () {
244
+ throw new IllegalArgumentException ();
245
+ }
246
+ },
205
247
throwsInstanceOf (NullPointerException .class )
206
248
);
207
249
fail ("should have failed" );
0 commit comments