Skip to content

Commit

Permalink
Migrate to AssertJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Apr 23, 2024
1 parent 440da79 commit 32734fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <slimane.amar at rte-france.com>
Expand All @@ -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;
Expand Down Expand Up @@ -524,10 +523,7 @@ void testDeleteElements() {

@Test
void testAccessControlInfos() {
List<UUID> 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() {
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/org/gridsuite/gateway/TokenValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 32734fb

Please sign in to comment.