Skip to content

Commit c1c105e

Browse files
committed
JUnit5 assertThrows AbstractProxyFactoryTestCase
1 parent 7730c81 commit c1c105e

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.assertNotSame;
2424
import static org.junit.Assert.assertSame;
2525
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
2627

2728
import java.io.IOException;
2829
import java.io.Serializable;
@@ -45,6 +46,7 @@
4546
import org.apache.commons.proxy2.util.EchoImpl;
4647
import org.apache.commons.proxy2.util.SuffixInterceptor;
4748
import org.junit.Test;
49+
import org.junit.jupiter.api.function.Executable;
4850

4951
@SuppressWarnings("serial")
5052
public abstract class AbstractProxyFactoryTestCase extends AbstractTestCase
@@ -221,18 +223,32 @@ public void testInterceptingProxySerializable() throws Exception
221223
assertSerializable(proxy);
222224
}
223225

224-
@Test(expected = IOException.class)
225-
public void testInterceptorProxyWithCheckedException() throws Exception
226+
@Test
227+
public void testInterceptorProxyWithCheckedException()
226228
{
227229
final Echo proxy = factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
228-
proxy.ioException();
230+
// FIXME Simplification once upgraded to Java 1.8
231+
final Executable testMethod = new Executable() {
232+
@Override
233+
public void execute() throws Throwable {
234+
proxy.ioException();
235+
}
236+
};
237+
assertThrows(IOException.class, testMethod);
229238
}
230239

231-
@Test(expected = IllegalArgumentException.class)
232-
public void testInterceptorProxyWithUncheckedException() throws Exception
240+
@Test
241+
public void testInterceptorProxyWithUncheckedException()
233242
{
234243
final Echo proxy = factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
235-
proxy.illegalArgument();
244+
// FIXME Simplification once upgraded to Java 1.8
245+
final Executable testMethod = new Executable() {
246+
@Override
247+
public void execute() throws Throwable {
248+
proxy.illegalArgument();
249+
}
250+
};
251+
assertThrows(IllegalArgumentException.class, testMethod);
236252
}
237253

238254
@Test
@@ -326,18 +342,32 @@ public void testPrimitiveParameter()
326342
assertEquals(1, echo.echoBack(1));
327343
}
328344

329-
@Test(expected = IOException.class)
330-
public void testProxyWithCheckedException() throws Exception
345+
@Test
346+
public void testProxyWithCheckedException()
331347
{
332348
final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
333-
proxy.ioException();
349+
// FIXME Simplification once upgraded to Java 1.8
350+
final Executable testMethod = new Executable() {
351+
@Override
352+
public void execute() throws Throwable {
353+
proxy.ioException();
354+
}
355+
};
356+
assertThrows(IOException.class, testMethod);
334357
}
335358

336-
@Test(expected = IllegalArgumentException.class)
337-
public void testProxyWithUncheckedException() throws Exception
359+
@Test
360+
public void testProxyWithUncheckedException()
338361
{
339362
final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
340-
proxy.illegalArgument();
363+
// FIXME Simplification once upgraded to Java 1.8
364+
final Executable testMethod = new Executable() {
365+
@Override
366+
public void execute() throws Throwable {
367+
proxy.illegalArgument();
368+
}
369+
};
370+
assertThrows(IllegalArgumentException.class, testMethod);
341371
}
342372

343373
@Test

0 commit comments

Comments
 (0)