From 32734fb77c4bd79fb972fc688a4a357c1a181758 Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Tue, 23 Apr 2024 17:17:02 +0200 Subject: [PATCH] Migrate to AssertJ --- .../gateway/ElementAccessControlTest.java | 10 +++------- .../gridsuite/gateway/TokenValidationTest.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/gridsuite/gateway/ElementAccessControlTest.java b/src/test/java/org/gridsuite/gateway/ElementAccessControlTest.java index 0e63c3d..f51a76f 100644 --- a/src/test/java/org/gridsuite/gateway/ElementAccessControlTest.java +++ b/src/test/java/org/gridsuite/gateway/ElementAccessControlTest.java @@ -15,6 +15,7 @@ import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; +import org.assertj.core.api.WithAssertions; import org.gridsuite.gateway.dto.AccessControlInfos; import org.gridsuite.gateway.endpoints.ExploreServer; import org.junit.jupiter.api.BeforeEach; @@ -32,8 +33,6 @@ import java.util.UUID; import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Slimane Amar @@ -48,7 +47,7 @@ "gridsuite.services.sensitivity-analysis-server.base-uri=http://localhost:${wiremock.server.port}", }) @AutoConfigureWireMock(port = 0) -class ElementAccessControlTest { +class ElementAccessControlTest implements WithAssertions { @Value("${wiremock.server.port}") int port; @@ -524,10 +523,7 @@ void testDeleteElements() { @Test void testAccessControlInfos() { - List emptyList = List.of(); - - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> AccessControlInfos.create(emptyList)); - assertEquals("List of elements is empty", exception.getMessage()); + assertThatIllegalArgumentException().isThrownBy(() -> AccessControlInfos.create(List.of())).withMessage("List of elements is empty"); } private void initStubForJwk() { diff --git a/src/test/java/org/gridsuite/gateway/TokenValidationTest.java b/src/test/java/org/gridsuite/gateway/TokenValidationTest.java index 1f32a47..24d3376 100644 --- a/src/test/java/org/gridsuite/gateway/TokenValidationTest.java +++ b/src/test/java/org/gridsuite/gateway/TokenValidationTest.java @@ -18,7 +18,7 @@ import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.WithAssertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -73,7 +73,7 @@ "allowed-issuers=http://localhost:${wiremock.server.port}" }) @AutoConfigureWireMock(port = 0) -class TokenValidationTest { +class TokenValidationTest implements WithAssertions { @Value("${wiremock.server.port}") int port; @@ -186,11 +186,11 @@ private void testWebsocket(String name) throws InterruptedException { } } if (!done) { - Assertions.fail("Wiremock didn't receive the websocket connection"); + fail("Wiremock didn't receive the websocket connection"); } try { wsconnection.timeout(Duration.ofMillis(100)).block(); - Assertions.fail("websocket client was closed but should remain open"); + fail("websocket client was closed but should remain open"); } catch (Exception ignored) { //should timeout } @@ -550,7 +550,7 @@ void invalidToken() { .exchange() .expectStatus().isEqualTo(401); - //test with a incorrect Authorization value + //test with an incorrect Authorization value webClient .get().uri("case/v1/cases") .header("Authorization", token) @@ -559,9 +559,8 @@ void invalidToken() { // test without a token WebSocketClient client = new StandardWebSocketClient(); - client.execute(URI.create("ws://localhost:" + - this.localServerPort + "/study-notification/notify"), - ws -> ws.receive().then()).doOnSuccess(s -> Assertions.fail("Should have thrown")); + client.execute(URI.create("ws://localhost:" + this.localServerPort + "/study-notification/notify"), ws -> ws.receive().then()) + .doOnSuccess(s -> fail("Should have thrown")); } @Test