From 59b91376b013d74309c4d6d7670d2ae94768684e Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 29 Mar 2021 23:57:55 -0700 Subject: [PATCH] Refactor the dataReadNotAllowed() test case method to use JUnit 4 Exception handling (try-catch with expected Exception) rather than JUnit 5's (Jupiter) assertThrows(..) method. --- ...rityClientApplicationIntegrationTests.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/spring-geode-samples/boot/security/src/test/java/example/app/security/BootGeodeSecurityClientApplicationIntegrationTests.java b/spring-geode-samples/boot/security/src/test/java/example/app/security/BootGeodeSecurityClientApplicationIntegrationTests.java index b8efa2c4..e8d1ea99 100644 --- a/spring-geode-samples/boot/security/src/test/java/example/app/security/BootGeodeSecurityClientApplicationIntegrationTests.java +++ b/spring-geode-samples/boot/security/src/test/java/example/app/security/BootGeodeSecurityClientApplicationIntegrationTests.java @@ -16,7 +16,6 @@ package example.app.security; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; @@ -77,20 +76,25 @@ public class BootGeodeSecurityClientApplicationIntegrationTests extends ForkingC @SuppressWarnings("unused") private GemfireTemplate customersTemplate; - @Test + @Test(expected = DataAccessResourceFailureException.class) public void dataReadNotAllowed() { - Exception exception = assertThrows(DataAccessResourceFailureException.class, - () -> this.customersTemplate.get(2L)); + try { + this.customersTemplate.get(2L); + } + catch (DataAccessResourceFailureException expected) { - assertThat(exception).hasCauseInstanceOf(ServerOperationException.class); - assertThat(exception.getCause()).hasMessageContaining("remote server"); - assertThat(exception.getCause()).hasCauseInstanceOf(NotAuthorizedException.class); - assertThat(exception.getCause().getCause()).hasMessageContaining("jdoe not authorized for DATA:READ"); - assertThat(exception.getCause().getCause()).hasCauseInstanceOf(UnauthorizedException.class); - assertThat(exception.getCause().getCause().getCause()) - .hasMessageContaining("Subject does not have permission [DATA:READ"); - assertThat(exception.getCause().getCause().getCause()).hasNoCause(); + assertThat(expected).hasCauseInstanceOf(ServerOperationException.class); + assertThat(expected.getCause()).hasMessageContaining("remote server"); + assertThat(expected.getCause()).hasCauseInstanceOf(NotAuthorizedException.class); + assertThat(expected.getCause().getCause()).hasMessageContaining("jdoe not authorized for DATA:READ"); + assertThat(expected.getCause().getCause()).hasCauseInstanceOf(UnauthorizedException.class); + assertThat(expected.getCause().getCause().getCause()) + .hasMessageContaining("Subject does not have permission [DATA:READ"); + assertThat(expected.getCause().getCause().getCause()).hasNoCause(); + + throw expected; + } } @Test