|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -84,13 +84,13 @@ void closeContext() {
|
84 | 84 | }
|
85 | 85 |
|
86 | 86 | @Test
|
87 |
| - @SuppressWarnings("rawtypes") |
| 87 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
88 | 88 | void testErrorForMachineClientDefault() {
|
89 | 89 | load();
|
90 | 90 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("?trace=true"), Map.class);
|
91 | 91 | assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", null, "", "/");
|
92 |
| - assertThat(entity.getBody().containsKey("exception")).isFalse(); |
93 |
| - assertThat(entity.getBody().containsKey("trace")).isFalse(); |
| 92 | + assertThat(entity.getBody()).doesNotContainKey("exception"); |
| 93 | + assertThat(entity.getBody()).doesNotContainKey("trace"); |
94 | 94 | }
|
95 | 95 |
|
96 | 96 | @Test
|
@@ -144,19 +144,19 @@ void testErrorForMachineClientAlwaysParamsWithoutMessage() {
|
144 | 144 | "No message available", "/noMessage");
|
145 | 145 | }
|
146 | 146 |
|
147 |
| - @SuppressWarnings("rawtypes") |
| 147 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
148 | 148 | private void exceptionWithStackTraceAndMessage(String path) {
|
149 | 149 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl(path), Map.class);
|
150 | 150 | assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class,
|
151 | 151 | "Expected!", "/");
|
152 |
| - assertThat(entity.getBody().containsKey("trace")).isTrue(); |
| 152 | + assertThat(entity.getBody()).containsKey("trace"); |
153 | 153 | }
|
154 | 154 |
|
155 |
| - @SuppressWarnings("rawtypes") |
| 155 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
156 | 156 | private void exceptionWithoutStackTraceAndMessage(String path) {
|
157 | 157 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl(path), Map.class);
|
158 | 158 | assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class, "", "/");
|
159 |
| - assertThat(entity.getBody().containsKey("trace")).isFalse(); |
| 159 | + assertThat(entity.getBody()).doesNotContainKey("trace"); |
160 | 160 | }
|
161 | 161 |
|
162 | 162 | @Test
|
@@ -265,57 +265,57 @@ void testBindingExceptionForMachineClientNeverMessage() {
|
265 | 265 | bindingExceptionWithoutMessage("?message=true");
|
266 | 266 | }
|
267 | 267 |
|
268 |
| - @SuppressWarnings({ "rawtypes" }) |
| 268 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
269 | 269 | private void bindingExceptionWithErrors(String param) {
|
270 | 270 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
|
271 | 271 | assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
|
272 |
| - assertThat(entity.getBody().containsKey("errors")).isTrue(); |
| 272 | + assertThat(entity.getBody()).containsKey("errors"); |
273 | 273 | }
|
274 | 274 |
|
275 |
| - @SuppressWarnings({ "rawtypes" }) |
| 275 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
276 | 276 | private void bindingExceptionWithoutErrors(String param) {
|
277 | 277 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
|
278 | 278 | assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
|
279 |
| - assertThat(entity.getBody().containsKey("errors")).isFalse(); |
| 279 | + assertThat(entity.getBody()).doesNotContainKey("errors"); |
280 | 280 | }
|
281 | 281 |
|
282 |
| - @SuppressWarnings({ "rawtypes" }) |
| 282 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
283 | 283 | private void bindingExceptionWithMessage(String param) {
|
284 | 284 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
|
285 | 285 | assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class,
|
286 | 286 | "Validation failed for object='test'. Error count: 1", "/bind");
|
287 |
| - assertThat(entity.getBody().containsKey("errors")).isFalse(); |
| 287 | + assertThat(entity.getBody()).doesNotContainKey("errors"); |
288 | 288 | }
|
289 | 289 |
|
290 |
| - @SuppressWarnings({ "rawtypes" }) |
| 290 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
291 | 291 | private void bindingExceptionWithoutMessage(String param) {
|
292 | 292 | ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
|
293 | 293 | assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
|
294 |
| - assertThat(entity.getBody().containsKey("errors")).isFalse(); |
| 294 | + assertThat(entity.getBody()).doesNotContainKey("errors"); |
295 | 295 | }
|
296 | 296 |
|
297 | 297 | @Test
|
298 |
| - @SuppressWarnings("rawtypes") |
| 298 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
299 | 299 | void testRequestBodyValidationForMachineClient() {
|
300 | 300 | load("--server.error.include-exception=true");
|
301 | 301 | RequestEntity request = RequestEntity.post(URI.create(createUrl("/bodyValidation")))
|
302 | 302 | .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body("{}");
|
303 | 303 | ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
|
304 | 304 | assertErrorAttributes(entity.getBody(), "400", "Bad Request", MethodArgumentNotValidException.class, "",
|
305 | 305 | "/bodyValidation");
|
306 |
| - assertThat(entity.getBody().containsKey("errors")).isFalse(); |
| 306 | + assertThat(entity.getBody()).doesNotContainKey("errors"); |
307 | 307 | }
|
308 | 308 |
|
309 | 309 | @Test
|
310 |
| - @SuppressWarnings("rawtypes") |
| 310 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
311 | 311 | void testBindingExceptionForMachineClientDefault() {
|
312 | 312 | load();
|
313 | 313 | RequestEntity request = RequestEntity.get(URI.create(createUrl("/bind?trace=true,message=true")))
|
314 | 314 | .accept(MediaType.APPLICATION_JSON).build();
|
315 | 315 | ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
|
316 |
| - assertThat(entity.getBody().containsKey("exception")).isFalse(); |
317 |
| - assertThat(entity.getBody().containsKey("trace")).isFalse(); |
318 |
| - assertThat(entity.getBody().containsKey("errors")).isFalse(); |
| 316 | + assertThat(entity.getBody()).doesNotContainKey("exception"); |
| 317 | + assertThat(entity.getBody()).doesNotContainKey("trace"); |
| 318 | + assertThat(entity.getBody()).doesNotContainKey("errors"); |
319 | 319 | }
|
320 | 320 |
|
321 | 321 | @Test
|
|
0 commit comments