diff --git a/test/pom.xml b/test/pom.xml index fcc93eab..2711d64d 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -59,6 +59,11 @@ commons-lang3 test + + org.junit.jupiter + junit-jupiter-api + test + diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java index 5d6e6741..13aacce9 100644 --- a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java +++ b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; @@ -31,6 +32,7 @@ public abstract class AbstractStubTestCase extends AbstractProxyFactoryAgnosticTest { + // ***************************************************************************************************************** // Fields // ***************************************************************************************************************** @@ -68,18 +70,17 @@ protected void train(StubInterface trainee) assertEquals("World", proxy.one(null)); } - @Test(expected = IllegalStateException.class) + @Test public void testMixingArgumentMatchingStrategies() { - createProxy(new Trainer() - { - @Override - protected void train(StubInterface trainee) - { - when(trainee.three(isInstance(String.class), "World")) - .thenAnswer(ObjectProviderUtils.constant("World")); - } - }); + assertThrows(IllegalStateException.class, () -> + createProxy(new Trainer() { + @Override + protected void train(StubInterface trainee) { + when(trainee.three(isInstance(String.class), "World")) + .thenAnswer(ObjectProviderUtils.constant("World")); + } + })); } @Test @@ -134,23 +135,22 @@ protected void train(StubInterface trainee) assertEquals("One", proxy.stubs()[1].one("Whatever")); } - @Test(expected = IllegalStateException.class) + @Test public void testThenBeforeWhen() { - createProxy(new Trainer() - { - @Override - protected void train(StubInterface trainee) - { - thenThrow(new RuntimeException("Oops!")); - } - }); + assertThrows(IllegalStateException.class, () -> + createProxy(new Trainer() { + @Override + protected void train(StubInterface trainee) { + thenThrow(new RuntimeException("Oops!")); + } + })); } - @Test(expected = IllegalArgumentException.class) + @Test public void testThrowExceptionWithException() { - StubInterface proxy = createProxy(new Trainer() + final StubInterface proxy = createProxy(new Trainer() { @Override protected void train(StubInterface trainee) @@ -159,13 +159,13 @@ protected void train(StubInterface trainee) thenThrow(new IllegalArgumentException("Nope!")); } }); - proxy.voidMethod("Hello"); + assertThrows(IllegalArgumentException.class, () -> proxy.voidMethod("Hello")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testThrowExceptionWithProvidedException() { - StubInterface proxy = createProxy(new Trainer() + final StubInterface proxy = createProxy(new Trainer() { @Override protected void train(StubInterface trainee) @@ -174,10 +174,10 @@ protected void train(StubInterface trainee) thenThrow(ObjectProviderUtils.constant(new IllegalArgumentException("Nope!"))); } }); - proxy.voidMethod("Hello"); + assertThrows(IllegalArgumentException.class, () -> proxy.voidMethod("Hello")); } - @Test(expected = RuntimeException.class) + @Test public void testThrowingExceptionObject() { final StubInterface proxy = createProxy(new Trainer() @@ -188,10 +188,10 @@ protected void train(StubInterface trainee) when(trainee.one("Hello")).thenThrow(new RuntimeException("No way, Jose!")); } }); - proxy.one("Hello"); + assertThrows(RuntimeException.class, () -> proxy.one("Hello")); } - @Test(expected = RuntimeException.class) + @Test public void testThrowingProvidedException() { final StubInterface proxy = createProxy(new Trainer() @@ -203,27 +203,24 @@ protected void train(StubInterface trainee) ObjectProviderUtils.constant(new RuntimeException("No way, Jose!"))); } }); - proxy.one("Hello"); + assertThrows(RuntimeException.class, () -> proxy.one("Hello")); } - @Test(expected = IllegalStateException.class) + @Test public void testUsingWrongStub() { - createProxy(new Trainer() - { - @Override - protected void train(final StubInterface parent) - { - when(parent.stub()).thenStub(new Trainer() - { + assertThrows(IllegalStateException.class, () -> + createProxy(new Trainer() { @Override - protected void train(final StubInterface child) - { - when(parent.one("Hello")).thenReturn("World"); + protected void train(final StubInterface parent) { + when(parent.stub()).thenStub(new Trainer() { + @Override + protected void train(final StubInterface child) { + when(parent.one("Hello")).thenReturn("World"); + } + }); } - }); - } - }); + })); } @Test @@ -453,4 +450,5 @@ protected void train(StubInterface trainee) assertNotNull(proxy.stub()); assertEquals("World", proxy.stub().one("Hello")); } + }