@@ -103,7 +103,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
103103 @ Test public void
104104 throwableIsOfMatchingInstance () {
105105 assertThat (
106- () -> { throw new IllegalStateException (); },
106+ new Executable () {
107+ @ Override
108+ public void execute () {
109+ throw new IllegalStateException ();
110+ }
111+ },
107112 throwsInstanceOf (IllegalStateException .class )
108113 );
109114 }
@@ -115,7 +120,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
115120 + " but: threw but <java.lang.IllegalStateException> is a java.lang.IllegalStateException" ;
116121 try {
117122 assertThat (
118- () -> { throw new IllegalStateException (); },
123+ new Executable () {
124+ @ Override
125+ public void execute () {
126+ throw new IllegalStateException ();
127+ }
128+ },
119129 throwsInstanceOf (IOException .class )
120130 );
121131 fail ("should have failed" );
@@ -128,7 +138,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
128138 @ Test public void
129139 throwableHasMatchingMessage () {
130140 assertThat (
131- () -> { throw new Exception ("message" ); },
141+ new Executable () {
142+ @ Override
143+ public void execute () throws Exception {
144+ throw new Exception ("message" );
145+ }
146+ },
132147 doesThrow (withMessage (equalTo ("message" )))
133148 );
134149 }
@@ -140,7 +155,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
140155 + " but: threw but message was \" actual message\" " ;
141156 try {
142157 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+ },
144164 doesThrow (withMessage ("expected message" ))
145165 );
146166 fail ("should have failed" );
@@ -157,7 +177,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
157177 + endLine + " but: did not throw" ;
158178 try {
159179 assertThat (
160- () -> {}, // Do nothing
180+ new Executable () {
181+ @ Override
182+ public void execute () {
183+ // Do nothing
184+ }
185+ },
161186 throwsInstanceOf (NoSuchMethodError .class )
162187 );
163188 fail ("should have failed" );
@@ -169,9 +194,15 @@ public void describeMismatch(Object item, Description mismatchDescription) {
169194
170195 @ Test public void
171196 throwableCauseMatches () {
197+ Matcher <? extends Throwable > instanceOfMatcher = instanceOf (XMLStreamException .class );
172198 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 ))
175206 );
176207 }
177208
@@ -181,9 +212,15 @@ public void describeMismatch(Object item, Description mismatchDescription) {
181212 String expectedMessage = endLine + "Expected: throws because of an instance of java.lang.NullPointerException"
182213 + endLine + " but: threw but cause <java.lang.IllegalArgumentException> is a java.lang.IllegalArgumentException" ;
183214 try {
215+ Matcher <? extends Throwable > instanceOfMatcher = instanceOf (NullPointerException .class );
184216 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 ))
187224 );
188225 fail ("should have failed" );
189226 }
@@ -201,7 +238,12 @@ public void describeMismatch(Object item, Description mismatchDescription) {
201238 try {
202239 assertThat (
203240 "Custom message" ,
204- () -> { throw new IllegalArgumentException (); },
241+ new Executable () {
242+ @ Override
243+ public void execute () {
244+ throw new IllegalArgumentException ();
245+ }
246+ },
205247 throwsInstanceOf (NullPointerException .class )
206248 );
207249 fail ("should have failed" );
0 commit comments