Skip to content

Commit f1ec810

Browse files
committed
Polish
1 parent 323a78c commit f1ec810

10 files changed

+109
-160
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,26 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
4444

4545
@Test
4646
void testCustomErrorPath() {
47-
@SuppressWarnings("rawtypes")
48-
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops",
49-
Map.class);
47+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
48+
this.restTemplate.withBasicAuth("user", "password").getForEntity("/oops", Map.class));
5049
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
51-
@SuppressWarnings("unchecked")
5250
Map<String, Object> body = entity.getBody();
5351
assertThat(body.get("error")).isEqualTo("None");
5452
assertThat(body.get("status")).isEqualTo(999);
5553
}
5654

5755
@Test
5856
void testCustomContextPath() {
59-
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
57+
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
6058
.getForEntity("/admin/health", String.class);
6159
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
6260
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
6361
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
6462
}
6563

66-
private String getPassword() {
67-
return "password";
64+
@SuppressWarnings({ "unchecked", "rawtypes" })
65+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
66+
return (ResponseEntity) entity;
6867
}
6968

7069
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ class ManagementAddressActuatorApplicationTests {
4747

4848
@Test
4949
void testHome() {
50-
@SuppressWarnings("rawtypes")
51-
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class);
50+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
51+
new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class));
5252
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
5353
}
5454

5555
@Test
5656
void testHealth() {
57-
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
57+
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
5858
.getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class);
5959
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
6060
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
6161
}
6262

63-
private String getPassword() {
64-
return "password";
63+
@SuppressWarnings({ "unchecked", "rawtypes" })
64+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
65+
return (ResponseEntity) entity;
6566
}
6667

6768
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ class ManagementDifferentPortSampleActuatorApplicationTests {
4141

4242
@Test
4343
void linksEndpointShouldBeAvailable() {
44-
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
44+
ResponseEntity<String> entity = new TestRestTemplate("user", "password")
4545
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
4646
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
4747
assertThat(entity.getBody()).contains("\"_links\"");
4848
}
4949

50-
private String getPassword() {
51-
return "password";
52-
}
53-
5450
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,23 @@ class ManagementPathSampleActuatorApplicationTests {
4343

4444
@Test
4545
void testHealth() {
46-
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
46+
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
4747
.getForEntity("/admin/health", String.class);
4848
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
4949
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
5050
}
5151

5252
@Test
5353
void testHomeIsSecure() {
54-
@SuppressWarnings("rawtypes")
55-
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class);
54+
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
5655
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
57-
@SuppressWarnings("unchecked")
58-
Map<String, Object> body = entity.getBody();
59-
assertThat(body.get("error")).isEqualTo("Unauthorized");
56+
assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized");
6057
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
6158
}
6259

63-
private String getPassword() {
64-
return "password";
60+
@SuppressWarnings({ "unchecked", "rawtypes" })
61+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
62+
return (ResponseEntity) entity;
6563
}
6664

6765
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
5252

5353
@Test
5454
void testHome() {
55-
@SuppressWarnings("rawtypes")
56-
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
57-
.getForEntity("http://localhost:" + this.port, Map.class);
55+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
56+
new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class));
5857
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
59-
@SuppressWarnings("unchecked")
60-
Map<String, Object> body = entity.getBody();
61-
assertThat(body.get("message")).isEqualTo("Hello Phil");
58+
assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
6259
}
6360

6461
@Test
6562
void testMetrics() {
6663
testHome(); // makes sure some requests have been made
67-
@SuppressWarnings("rawtypes")
68-
ResponseEntity<Map> entity = new TestRestTemplate()
69-
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
64+
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
65+
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class));
7066
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
7167
}
7268

7369
@Test
7470
void testHealth() {
75-
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
71+
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
7672
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
7773
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
7874
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}");
@@ -82,43 +78,38 @@ void testHealth() {
8278
void testEnvNotFound() {
8379
String unknownProperty = "test-does-not-exist";
8480
assertThat(this.environment.containsProperty(unknownProperty)).isFalse();
85-
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity(
81+
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password").getForEntity(
8682
"http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class);
8783
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
8884
}
8985

9086
@Test
9187
void testMissing() {
92-
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
88+
ResponseEntity<String> entity = new TestRestTemplate("user", "password")
9389
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
9490
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
9591
assertThat(entity.getBody()).contains("\"status\":404");
9692
}
9793

9894
@Test
9995
void testErrorPage() {
100-
@SuppressWarnings("rawtypes")
101-
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
102-
.getForEntity("http://localhost:" + this.port + "/error", Map.class);
96+
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
97+
.getForEntity("http://localhost:" + this.port + "/error", Map.class));
10398
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
104-
@SuppressWarnings("unchecked")
105-
Map<String, Object> body = entity.getBody();
106-
assertThat(body.get("status")).isEqualTo(999);
99+
assertThat(entity.getBody().get("status")).isEqualTo(999);
107100
}
108101

109102
@Test
110103
void testManagementErrorPage() {
111-
@SuppressWarnings("rawtypes")
112-
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
113-
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
104+
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
105+
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
114106
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
115-
@SuppressWarnings("unchecked")
116-
Map<String, Object> body = entity.getBody();
117-
assertThat(body.get("status")).isEqualTo(999);
107+
assertThat(entity.getBody().get("status")).isEqualTo(999);
118108
}
119109

120-
private String getPassword() {
121-
return "password";
110+
@SuppressWarnings({ "unchecked", "rawtypes" })
111+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
112+
return (ResponseEntity) entity;
122113
}
123114

124115
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,23 @@ class ManagementPortSampleActuatorApplicationTests {
4747

4848
@Test
4949
void testHome() {
50-
@SuppressWarnings("rawtypes")
51-
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
52-
.getForEntity("http://localhost:" + this.port, Map.class);
50+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
51+
new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class));
5352
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
54-
@SuppressWarnings("unchecked")
55-
Map<String, Object> body = entity.getBody();
56-
assertThat(body.get("message")).isEqualTo("Hello Phil");
53+
assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
5754
}
5855

5956
@Test
6057
void testMetrics() {
6158
testHome(); // makes sure some requests have been made
62-
@SuppressWarnings("rawtypes")
63-
ResponseEntity<Map> entity = new TestRestTemplate()
64-
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class);
59+
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
60+
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class));
6561
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
6662
}
6763

6864
@Test
6965
void testHealth() {
70-
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
66+
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
7167
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
7268
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
7369
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
@@ -77,17 +73,15 @@ void testHealth() {
7773

7874
@Test
7975
void testErrorPage() {
80-
@SuppressWarnings("rawtypes")
81-
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
82-
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
76+
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
77+
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
8378
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
84-
@SuppressWarnings("unchecked")
85-
Map<String, Object> body = entity.getBody();
86-
assertThat(body.get("status")).isEqualTo(999);
79+
assertThat(entity.getBody().get("status")).isEqualTo(999);
8780
}
8881

89-
private String getPassword() {
90-
return "password";
82+
@SuppressWarnings({ "unchecked", "rawtypes" })
83+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
84+
return (ResponseEntity) entity;
9185
}
9286

9387
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,23 @@ class NoManagementSampleActuatorApplicationTests {
4242

4343
@Test
4444
void testHome() {
45-
@SuppressWarnings("rawtypes")
46-
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
47-
Map.class);
45+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
46+
this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class));
4847
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
49-
@SuppressWarnings("unchecked")
50-
Map<String, Object> body = entity.getBody();
51-
assertThat(body.get("message")).isEqualTo("Hello Phil");
48+
assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
5249
}
5350

5451
@Test
5552
void testMetricsNotAvailable() {
5653
testHome(); // makes sure some requests have been made
57-
@SuppressWarnings("rawtypes")
58-
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics",
59-
Map.class);
54+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
55+
this.restTemplate.withBasicAuth("user", "password").getForEntity("/metrics", Map.class));
6056
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
6157
}
6258

63-
private String getPassword() {
64-
return "password";
59+
@SuppressWarnings({ "unchecked", "rawtypes" })
60+
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
61+
return (ResponseEntity) entity;
6562
}
6663

6764
}

0 commit comments

Comments
 (0)