Skip to content

Commit d64820c

Browse files
committed
test: verify custom error DTO for void ResponseEntities
1 parent 205a3a0 commit d64820c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

sda-commons-web-autoconfigure/src/test/java/org/sdase/commons/spring/boot/web/security/handler/ObscuringErrorHandlerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ void shouldGetResponseEntityWithBody() {
101101
.containsExactly(HttpStatus.CREATED, "This will not be altered.");
102102
}
103103

104+
@Test
105+
void shouldGetErrorResponseFromVoidReturnType() {
106+
var headers = new HttpHeaders();
107+
headers.setContentType(MediaType.APPLICATION_JSON);
108+
ResponseEntity<ApiError> exchange =
109+
client.exchange(
110+
getServerBaseUrl() + "/api/voidError",
111+
HttpMethod.GET,
112+
new HttpEntity<>(headers),
113+
ApiError.class);
114+
assertThat(exchange)
115+
.isNotNull()
116+
.extracting(ResponseEntity::getStatusCode, r -> r.getBody().getTitle())
117+
.containsExactly(HttpStatus.NOT_FOUND, "HTTP Error 404 occurred.");
118+
}
119+
104120
@Test
105121
void shouldGetResource() {
106122
var headers = new HttpHeaders();

sda-commons-web-autoconfigure/src/test/java/org/sdase/commons/spring/boot/web/security/test/SecurityTestApp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public ResponseEntity<TestResource> header(
6969
return new ResponseEntity<>(new TestResource(), headers, HttpStatus.OK);
7070
}
7171

72+
@GetMapping(value = "/voidError")
73+
public ResponseEntity<Void> voidError() {
74+
return ResponseEntity.notFound().build();
75+
}
76+
7277
@GetMapping(value = "caller", produces = "text/plain")
7378
public String identifyCaller(@Context HttpServletRequest request) {
7479
return request.getRemoteAddr();

0 commit comments

Comments
 (0)