From f1ec810caf8c6f795f1119a818689d365c07ca93 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 24 Sep 2019 18:21:23 -0700 Subject: [PATCH] Polish --- ...pertiesSampleActuatorApplicationTests.java | 13 ++- ...gementAddressActuatorApplicationTests.java | 11 ++- ...entPortSampleActuatorApplicationTests.java | 6 +- ...entPathSampleActuatorApplicationTests.java | 14 ++- ...AndPathSampleActuatorApplicationTests.java | 43 ++++----- ...entPortSampleActuatorApplicationTests.java | 30 +++--- ...agementSampleActuatorApplicationTests.java | 19 ++-- .../SampleActuatorApplicationTests.java | 91 ++++++++----------- ...letPathSampleActuatorApplicationTests.java | 22 ++--- ...hutdownSampleActuatorApplicationTests.java | 20 ++-- 10 files changed, 109 insertions(+), 160 deletions(-) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 41922918f7..da6256e470 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -44,11 +44,9 @@ class EndpointsPropertiesSampleActuatorApplicationTests { @Test void testCustomErrorPath() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/oops", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") Map body = entity.getBody(); assertThat(body.get("error")).isEqualTo("None"); assertThat(body.get("status")).isEqualTo(999); @@ -56,15 +54,16 @@ class EndpointsPropertiesSampleActuatorApplicationTests { @Test void testCustomContextPath() { - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) + ResponseEntity entity = this.restTemplate.withBasicAuth("user", "password") .getForEntity("/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"hello\":\"world\""); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java index b31b974824..b8dffdfc79 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java @@ -47,21 +47,22 @@ class ManagementAddressActuatorApplicationTests { @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); + ResponseEntity> entity = asMapEntity( + new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test void testHealth() { - ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", "password") .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java index fc32f7f942..d488501337 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java @@ -41,14 +41,10 @@ class ManagementDifferentPortSampleActuatorApplicationTests { @Test void linksEndpointShouldBeAvailable() { - ResponseEntity entity = new TestRestTemplate("user", getPassword()) + ResponseEntity entity = new TestRestTemplate("user", "password") .getForEntity("http://localhost:" + this.managementPort + "/", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"_links\""); } - private String getPassword() { - return "password"; - } - } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java index f33d1faf9d..d26d8b5be8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -43,7 +43,7 @@ class ManagementPathSampleActuatorApplicationTests { @Test void testHealth() { - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) + ResponseEntity entity = this.restTemplate.withBasicAuth("user", "password") .getForEntity("/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); @@ -51,17 +51,15 @@ class ManagementPathSampleActuatorApplicationTests { @Test void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/", Map.class); + ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index ecb4fedfda..51dd736fc8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -52,27 +52,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests { @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port, Map.class); + ResponseEntity> entity = asMapEntity( + new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil"); } @Test void testMetrics() { testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class); + ResponseEntity> entity = asMapEntity(new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test void testHealth() { - ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", "password") .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}"); @@ -82,14 +78,14 @@ class ManagementPortAndPathSampleActuatorApplicationTests { void testEnvNotFound() { String unknownProperty = "test-does-not-exist"; assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); - ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity( + ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", "password").getForEntity( "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } @Test void testMissing() { - ResponseEntity entity = new TestRestTemplate("user", getPassword()) + ResponseEntity entity = new TestRestTemplate("user", "password") .getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getBody()).contains("\"status\":404"); @@ -97,28 +93,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests { @Test void testErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port + "/error", Map.class); + ResponseEntity> entity = asMapEntity(new TestRestTemplate("user", "password") + .getForEntity("http://localhost:" + this.port + "/error", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); + assertThat(entity.getBody().get("status")).isEqualTo(999); } @Test void testManagementErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); + ResponseEntity> entity = asMapEntity(new TestRestTemplate("user", "password") + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); + assertThat(entity.getBody().get("status")).isEqualTo(999); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java index fa530a5d3f..eddf529511 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -47,27 +47,23 @@ class ManagementPortSampleActuatorApplicationTests { @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port, Map.class); + ResponseEntity> entity = asMapEntity( + new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil"); } @Test void testMetrics() { testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); + ResponseEntity> entity = asMapEntity(new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test void testHealth() { - ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", "password") .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); @@ -77,17 +73,15 @@ class ManagementPortSampleActuatorApplicationTests { @Test void testErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); + ResponseEntity> entity = asMapEntity(new TestRestTemplate("user", "password") + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); + assertThat(entity.getBody().get("status")).isEqualTo(999); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java index ab751a0c41..dc9e0d224b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java @@ -42,26 +42,23 @@ class NoManagementSampleActuatorApplicationTests { @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil"); } @Test void testMetricsNotAvailable() { testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/metrics", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java index b2e8c0c09e..796d873bb3 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java @@ -55,62 +55,51 @@ class SampleActuatorApplicationTests { @Test void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/", Map.class); + ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } @Test void testMetricsIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.getForEntity("/actuator/metrics", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class); + entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class); + entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics.json", Map.class); + entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics.json", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil"); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings("unchecked") void testMetrics() { testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/metrics", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/metrics", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - Map body = entity.getBody(); - assertThat(body).containsKey("names"); - assertThat((List) body.get("names")).contains("jvm.buffer.count"); - + assertThat(entity.getBody()).containsKey("names"); + List names = (List) entity.getBody().get("names"); + assertThat(names).contains("jvm.buffer.count"); } @Test void testEnv() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/env", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/env", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body).containsKey("propertySources"); + assertThat(entity.getBody()).containsKey("propertySources"); } @Test @@ -133,7 +122,7 @@ class SampleActuatorApplicationTests { @Test void testErrorPage() { - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo", + ResponseEntity entity = this.restTemplate.withBasicAuth("user", "password").getForEntity("/foo", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); @@ -145,7 +134,7 @@ class SampleActuatorApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity request = new HttpEntity(headers); - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", + ResponseEntity entity = this.restTemplate.withBasicAuth("user", "password").exchange("/foo", HttpMethod.GET, request, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); @@ -155,32 +144,26 @@ class SampleActuatorApplicationTests { @Test void testErrorPageDirectAccess() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/error", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("None"); - assertThat(body.get("status")).isEqualTo(999); + assertThat(entity.getBody().get("error")).isEqualTo("None"); + assertThat(entity.getBody().get("status")).isEqualTo(999); } @Test - @SuppressWarnings("unchecked") void testBeans() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/beans", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/beans", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).containsOnlyKeys("contexts"); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings("unchecked") void testConfigProps() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/configprops", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/configprops", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); Map body = entity.getBody(); Map contexts = (Map) body.get("contexts"); @@ -191,17 +174,15 @@ class SampleActuatorApplicationTests { @Test void testLegacy() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/legacy", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/legacy", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body).contains(entry("legacy", "legacy")); + assertThat(entity.getBody()).contains(entry("legacy", "legacy")); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java index bbe7fab573..8a99e7c62d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java @@ -42,19 +42,16 @@ class ServletPathSampleActuatorApplicationTests { @Test void testErrorPath() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/spring/error", Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/spring/error", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("None"); - assertThat(body.get("status")).isEqualTo(999); + assertThat(entity.getBody().get("error")).isEqualTo("None"); + assertThat(entity.getBody().get("status")).isEqualTo(999); } @Test void testHealth() { - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) + ResponseEntity entity = this.restTemplate.withBasicAuth("user", "password") .getForEntity("/spring/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); @@ -62,17 +59,16 @@ class ServletPathSampleActuatorApplicationTests { @Test void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.getForEntity("/spring/", Map.class); + ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/spring/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") Map body = entity.getBody(); assertThat(body.get("error")).isEqualTo("Unauthorized"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java index ee40206df6..1e63e15a75 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java @@ -47,11 +47,9 @@ class ShutdownSampleActuatorApplicationTests { @Test void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); + ResponseEntity> entity = asMapEntity( + this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") Map body = entity.getBody(); assertThat(body.get("message")).isEqualTo("Hello Phil"); } @@ -59,17 +57,15 @@ class ShutdownSampleActuatorApplicationTests { @Test @DirtiesContext void testShutdown() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .postForEntity("/actuator/shutdown", null, Map.class); + ResponseEntity> entity = asMapEntity(this.restTemplate.withBasicAuth("user", "password") + .postForEntity("/actuator/shutdown", null, Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(((String) body.get("message"))).contains("Shutting down"); + assertThat(((String) entity.getBody().get("message"))).contains("Shutting down"); } - private String getPassword() { - return "password"; + @SuppressWarnings({ "unchecked", "rawtypes" }) + static ResponseEntity> asMapEntity(ResponseEntity entity) { + return (ResponseEntity) entity; } @Configuration(proxyBeanMethods = false)