test: complete assertions

This commit is contained in:
Anyul Rivas 2024-03-14 09:05:28 +01:00 committed by Dave Syer
parent 516722647a
commit 5941227ab3

View file

@ -35,6 +35,7 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity; import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -68,10 +69,10 @@ class CrashControllerIntegrationTests {
new ParameterizedTypeReference<Map<String, Object>>() { new ParameterizedTypeReference<Map<String, Object>>() {
}); });
assertThat(resp).isNotNull(); assertThat(resp).isNotNull();
assertThat(resp.getStatusCode().is5xxServerError()); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(resp.getBody().containsKey("timestamp")); assertThat(resp.getBody()).containsKey("timestamp");
assertThat(resp.getBody().containsKey("status")); assertThat(resp.getBody()).containsKey("status");
assertThat(resp.getBody().containsKey("error")); assertThat(resp.getBody()).containsKey("error");
assertThat(resp.getBody()).containsEntry("message", assertThat(resp.getBody()).containsEntry("message",
"Expected: controller used to showcase what happens when an exception is thrown"); "Expected: controller used to showcase what happens when an exception is thrown");
assertThat(resp.getBody()).containsEntry("path", "/oups"); assertThat(resp.getBody()).containsEntry("path", "/oups");
@ -84,7 +85,7 @@ class CrashControllerIntegrationTests {
ResponseEntity<String> resp = rest.exchange("http://localhost:" + port + "/oups", HttpMethod.GET, ResponseEntity<String> resp = rest.exchange("http://localhost:" + port + "/oups", HttpMethod.GET,
new HttpEntity<>(headers), String.class); new HttpEntity<>(headers), String.class);
assertThat(resp).isNotNull(); assertThat(resp).isNotNull();
assertThat(resp.getStatusCode().is5xxServerError()); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(resp.getBody()).isNotNull(); assertThat(resp.getBody()).isNotNull();
// html: // html:
assertThat(resp.getBody()).containsSubsequence("<body>", "<h2>", "Something happened...", "</h2>", "<p>", assertThat(resp.getBody()).containsSubsequence("<body>", "<h2>", "Something happened...", "</h2>", "<p>",