Skip to content

Commit 365ecd4

Browse files
committed
Polishing
1 parent 8df45dd commit 365ecd4

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

spring-web/src/test/java/org/springframework/web/client/AbstractJettyServerTestCase.java

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ public class AbstractJettyServerTestCase {
5454

5555
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
5656

57-
protected static final MediaType textContentType = new MediaType("text", "plain",
58-
Collections.singletonMap("charset", "UTF-8"));
57+
protected static final MediaType textContentType =
58+
new MediaType("text", "plain", Collections.singletonMap("charset", "UTF-8"));
59+
60+
protected static final MediaType jsonContentType =
61+
new MediaType("application", "json", Collections.singletonMap("charset", "UTF-8"));
5962

60-
protected static final MediaType jsonContentType = new MediaType("application",
61-
"json", Collections.singletonMap("charset", "utf-8"));
6263

6364
private static Server jettyServer;
6465

@@ -69,7 +70,6 @@ public class AbstractJettyServerTestCase {
6970

7071
@BeforeClass
7172
public static void startJettyServer() throws Exception {
72-
7373
// Let server pick its own random, available port.
7474
jettyServer = new Server(0);
7575

@@ -119,13 +119,12 @@ private static class StatusCodeServlet extends GenericServlet {
119119

120120
private final int sc;
121121

122-
private StatusCodeServlet(int sc) {
122+
public StatusCodeServlet(int sc) {
123123
this.sc = sc;
124124
}
125125

126126
@Override
127-
public void service(ServletRequest request, ServletResponse response) throws
128-
ServletException, IOException {
127+
public void service(ServletRequest request, ServletResponse response) throws IOException {
129128
((HttpServletResponse) response).setStatus(sc);
130129
}
131130
}
@@ -137,12 +136,12 @@ private static class ErrorServlet extends GenericServlet {
137136

138137
private final int sc;
139138

140-
private ErrorServlet(int sc) {
139+
public ErrorServlet(int sc) {
141140
this.sc = sc;
142141
}
143142

144143
@Override
145-
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
144+
public void service(ServletRequest request, ServletResponse response) throws IOException {
146145
((HttpServletResponse) response).sendError(sc);
147146
}
148147
}
@@ -155,14 +154,13 @@ private static class GetServlet extends HttpServlet {
155154

156155
private final MediaType contentType;
157156

158-
private GetServlet(byte[] buf, MediaType contentType) {
157+
public GetServlet(byte[] buf, MediaType contentType) {
159158
this.buf = buf;
160159
this.contentType = contentType;
161160
}
162161

163162
@Override
164-
protected void doGet(HttpServletRequest request, HttpServletResponse response)
165-
throws ServletException, IOException {
163+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
166164
if (contentType != null) {
167165
response.setContentType(contentType.toString());
168166
}
@@ -175,28 +173,27 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
175173
@SuppressWarnings("serial")
176174
private static class PostServlet extends HttpServlet {
177175

178-
private final String s;
176+
private final String content;
179177

180178
private final String location;
181179

182180
private final byte[] buf;
183181

184182
private final MediaType contentType;
185183

186-
private PostServlet(String s, String location, byte[] buf, MediaType contentType) {
187-
this.s = s;
184+
public PostServlet(String content, String location, byte[] buf, MediaType contentType) {
185+
this.content = content;
188186
this.location = location;
189187
this.buf = buf;
190188
this.contentType = contentType;
191189
}
192190

193191
@Override
194-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
195-
throws ServletException, IOException {
192+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
196193
assertTrue("Invalid request content-length", request.getContentLength() > 0);
197194
assertNotNull("No content-type", request.getContentType());
198195
String body = FileCopyUtils.copyToString(request.getReader());
199-
assertEquals("Invalid request body", s, body);
196+
assertEquals("Invalid request body", content, body);
200197
response.setStatus(HttpServletResponse.SC_CREATED);
201198
response.setHeader("Location", baseUrl + location);
202199
response.setContentLength(buf.length);
@@ -213,14 +210,13 @@ private static class JsonPostServlet extends HttpServlet {
213210

214211
private final MediaType contentType;
215212

216-
private JsonPostServlet(String location, MediaType contentType) {
213+
public JsonPostServlet(String location, MediaType contentType) {
217214
this.location = location;
218215
this.contentType = contentType;
219216
}
220217

221218
@Override
222-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
223-
throws ServletException, IOException {
219+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
224220
assertTrue("Invalid request content-length", request.getContentLength() > 0);
225221
assertNotNull("No content-type", request.getContentType());
226222
String body = FileCopyUtils.copyToString(request.getReader());
@@ -239,13 +235,12 @@ private static class PutServlet extends HttpServlet {
239235

240236
private final String s;
241237

242-
private PutServlet(String s, byte[] buf, MediaType contentType) {
238+
public PutServlet(String s, byte[] buf, MediaType contentType) {
243239
this.s = s;
244240
}
245241

246242
@Override
247-
protected void doPut(HttpServletRequest request, HttpServletResponse response)
248-
throws ServletException, IOException {
243+
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
249244
assertTrue("Invalid request content-length", request.getContentLength() > 0);
250245
assertNotNull("No content-type", request.getContentType());
251246
String body = FileCopyUtils.copyToString(request.getReader());
@@ -259,7 +254,7 @@ protected void doPut(HttpServletRequest request, HttpServletResponse response)
259254
private static class UriServlet extends HttpServlet {
260255

261256
@Override
262-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
257+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
263258
resp.setContentType("text/plain");
264259
resp.setCharacterEncoding("utf-8");
265260
resp.getWriter().write(req.getRequestURI());
@@ -311,9 +306,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
311306
private static class FormServlet extends HttpServlet {
312307

313308
@Override
314-
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
315-
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE,
316-
req.getContentType());
309+
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
310+
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE, req.getContentType());
317311

318312
Map<String, String[]> parameters = req.getParameterMap();
319313
assertEquals(2, parameters.size());
@@ -334,7 +328,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
334328
private static class DeleteServlet extends HttpServlet {
335329

336330
@Override
337-
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
331+
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
338332
resp.setStatus(200);
339333
}
340334
}

0 commit comments

Comments
 (0)