|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2018 the original author or authors. |
| 2 | + * Copyright 2012-2019 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.
|
@@ -49,64 +49,50 @@ public void testHome() throws Exception {
|
49 | 49 | public void testHealth() throws Exception {
|
50 | 50 | String url = "http://localhost:" + this.port + "/bootapp/actuator/health";
|
51 | 51 | System.out.println(url);
|
52 |
| - ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, |
53 |
| - String.class); |
| 52 | + ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, String.class); |
54 | 53 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
55 | 54 | assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
|
56 | 55 | }
|
57 | 56 |
|
58 | 57 | @Test
|
59 |
| - public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse() |
60 |
| - throws Exception { |
61 |
| - assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL, |
62 |
| - MediaType.APPLICATION_JSON); |
| 58 | + public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse() throws Exception { |
| 59 | + assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL, MediaType.APPLICATION_JSON); |
63 | 60 | }
|
64 | 61 |
|
65 | 62 | @Test
|
66 |
| - public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse() |
67 |
| - throws Exception { |
68 |
| - assertThatPathProducesExpectedResponse("/bootapp/exception", |
69 |
| - MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); |
| 63 | + public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse() throws Exception { |
| 64 | + assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.APPLICATION_JSON, |
| 65 | + MediaType.APPLICATION_JSON); |
70 | 66 | }
|
71 | 67 |
|
72 | 68 | @Test
|
73 |
| - public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse() |
74 |
| - throws Exception { |
75 |
| - assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML, |
76 |
| - MediaType.TEXT_HTML); |
| 69 | + public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception { |
| 70 | + assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML, MediaType.TEXT_HTML); |
77 | 71 | }
|
78 | 72 |
|
79 | 73 | @Test
|
80 |
| - public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse() |
81 |
| - throws Exception { |
82 |
| - assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL, |
83 |
| - MediaType.APPLICATION_JSON); |
| 74 | + public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse() throws Exception { |
| 75 | + assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL, MediaType.APPLICATION_JSON); |
84 | 76 | }
|
85 | 77 |
|
86 | 78 | @Test
|
87 | 79 | public void sendErrorForRequestAcceptingJsonProducesAJsonResponse() throws Exception {
|
88 |
| - assertThatPathProducesExpectedResponse("/bootapp/send-error", |
89 |
| - MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); |
| 80 | + assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.APPLICATION_JSON, |
| 81 | + MediaType.APPLICATION_JSON); |
90 | 82 | }
|
91 | 83 |
|
92 | 84 | @Test
|
93 |
| - public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse() |
94 |
| - throws Exception { |
95 |
| - assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML, |
96 |
| - MediaType.TEXT_HTML); |
| 85 | + public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception { |
| 86 | + assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML, MediaType.TEXT_HTML); |
97 | 87 | }
|
98 | 88 |
|
99 |
| - private void assertThatPathProducesExpectedResponse(String path, MediaType accept, |
100 |
| - MediaType contentType) { |
101 |
| - RequestEntity<Void> request = RequestEntity |
102 |
| - .get(URI.create("http://localhost:" + this.port + path)).accept(accept) |
103 |
| - .build(); |
| 89 | + private void assertThatPathProducesExpectedResponse(String path, MediaType accept, MediaType contentType) { |
| 90 | + RequestEntity<Void> request = RequestEntity.get(URI.create("http://localhost:" + this.port + path)) |
| 91 | + .accept(accept).build(); |
104 | 92 | ResponseEntity<String> response = this.rest.exchange(request, String.class);
|
105 | 93 | assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
106 | 94 | assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType()))
|
107 |
| - .as("%s is compatible with %s", contentType, |
108 |
| - response.getHeaders().getContentType()) |
109 |
| - .isTrue(); |
| 95 | + .as("%s is compatible with %s", contentType, response.getHeaders().getContentType()).isTrue(); |
110 | 96 | }
|
111 | 97 |
|
112 | 98 | }
|
0 commit comments