Skip to content

Commit fe0249b

Browse files
committed
Polishing
1 parent 2ac682e commit fe0249b

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,13 +33,11 @@
3333
import org.apache.commons.fileupload.FileUploadException;
3434
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
3535
import org.apache.commons.fileupload.servlet.ServletFileUpload;
36-
3736
import org.eclipse.jetty.server.Connector;
3837
import org.eclipse.jetty.server.NetworkConnector;
3938
import org.eclipse.jetty.server.Server;
4039
import org.eclipse.jetty.servlet.ServletContextHandler;
4140
import org.eclipse.jetty.servlet.ServletHolder;
42-
4341
import org.junit.AfterClass;
4442
import org.junit.BeforeClass;
4543

@@ -56,11 +54,12 @@ public class AbstractJettyServerTestCase {
5654

5755
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
5856

59-
protected static final MediaType textContentType = new MediaType("text", "plain",
60-
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"));
6162

62-
protected static final MediaType jsonContentType = new MediaType("application",
63-
"json", Collections.singletonMap("charset", "utf-8"));
6463

6564
private static Server jettyServer;
6665

@@ -71,7 +70,6 @@ public class AbstractJettyServerTestCase {
7170

7271
@BeforeClass
7372
public static void startJettyServer() throws Exception {
74-
7573
// Let server pick its own random, available port.
7674
jettyServer = new Server(0);
7775

@@ -114,54 +112,55 @@ public static void stopJettyServer() throws Exception {
114112
}
115113
}
116114

115+
117116
/** Servlet that sets the given status code. */
118117
@SuppressWarnings("serial")
119118
private static class StatusCodeServlet extends GenericServlet {
120119

121120
private final int sc;
122121

123-
private StatusCodeServlet(int sc) {
122+
public StatusCodeServlet(int sc) {
124123
this.sc = sc;
125124
}
126125

127126
@Override
128-
public void service(ServletRequest request, ServletResponse response) throws
129-
ServletException, IOException {
127+
public void service(ServletRequest request, ServletResponse response) throws IOException {
130128
((HttpServletResponse) response).setStatus(sc);
131129
}
132130
}
133131

132+
134133
/** Servlet that returns an error message for a given status code. */
135134
@SuppressWarnings("serial")
136135
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
}
149148

149+
150150
@SuppressWarnings("serial")
151151
private static class GetServlet extends HttpServlet {
152152

153153
private final byte[] buf;
154154

155155
private final MediaType contentType;
156156

157-
private GetServlet(byte[] buf, MediaType contentType) {
157+
public GetServlet(byte[] buf, MediaType contentType) {
158158
this.buf = buf;
159159
this.contentType = contentType;
160160
}
161161

162162
@Override
163-
protected void doGet(HttpServletRequest request, HttpServletResponse response)
164-
throws ServletException, IOException {
163+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
165164
if (contentType != null) {
166165
response.setContentType(contentType.toString());
167166
}
@@ -170,31 +169,31 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
170169
}
171170
}
172171

172+
173173
@SuppressWarnings("serial")
174174
private static class PostServlet extends HttpServlet {
175175

176-
private final String s;
176+
private final String content;
177177

178178
private final String location;
179179

180180
private final byte[] buf;
181181

182182
private final MediaType contentType;
183183

184-
private PostServlet(String s, String location, byte[] buf, MediaType contentType) {
185-
this.s = s;
184+
public PostServlet(String content, String location, byte[] buf, MediaType contentType) {
185+
this.content = content;
186186
this.location = location;
187187
this.buf = buf;
188188
this.contentType = contentType;
189189
}
190190

191191
@Override
192-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
193-
throws ServletException, IOException {
192+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
194193
assertTrue("Invalid request content-length", request.getContentLength() > 0);
195194
assertNotNull("No content-type", request.getContentType());
196195
String body = FileCopyUtils.copyToString(request.getReader());
197-
assertEquals("Invalid request body", s, body);
196+
assertEquals("Invalid request body", content, body);
198197
response.setStatus(HttpServletResponse.SC_CREATED);
199198
response.setHeader("Location", baseUrl + location);
200199
response.setContentLength(buf.length);
@@ -203,21 +202,21 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
203202
}
204203
}
205204

205+
206206
@SuppressWarnings("serial")
207207
private static class JsonPostServlet extends HttpServlet {
208208

209209
private final String location;
210210

211211
private final MediaType contentType;
212212

213-
private JsonPostServlet(String location, MediaType contentType) {
213+
public JsonPostServlet(String location, MediaType contentType) {
214214
this.location = location;
215215
this.contentType = contentType;
216216
}
217217

218218
@Override
219-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
220-
throws ServletException, IOException {
219+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
221220
assertTrue("Invalid request content-length", request.getContentLength() > 0);
222221
assertNotNull("No content-type", request.getContentType());
223222
String body = FileCopyUtils.copyToString(request.getReader());
@@ -230,18 +229,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
230229
}
231230
}
232231

232+
233233
@SuppressWarnings("serial")
234234
private static class PutServlet extends HttpServlet {
235235

236236
private final String s;
237237

238-
private PutServlet(String s, byte[] buf, MediaType contentType) {
238+
public PutServlet(String s, byte[] buf, MediaType contentType) {
239239
this.s = s;
240240
}
241241

242242
@Override
243-
protected void doPut(HttpServletRequest request, HttpServletResponse response)
244-
throws ServletException, IOException {
243+
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
245244
assertTrue("Invalid request content-length", request.getContentLength() > 0);
246245
assertNotNull("No content-type", request.getContentType());
247246
String body = FileCopyUtils.copyToString(request.getReader());
@@ -250,17 +249,19 @@ protected void doPut(HttpServletRequest request, HttpServletResponse response)
250249
}
251250
}
252251

252+
253253
@SuppressWarnings("serial")
254254
private static class UriServlet extends HttpServlet {
255255

256256
@Override
257-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
257+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
258258
resp.setContentType("text/plain");
259259
resp.setCharacterEncoding("utf-8");
260260
resp.getWriter().write(req.getRequestURI());
261261
}
262262
}
263263

264+
264265
@SuppressWarnings("serial")
265266
private static class MultipartServlet extends HttpServlet {
266267

@@ -300,13 +301,13 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
300301
}
301302
}
302303

304+
303305
@SuppressWarnings("serial")
304306
private static class FormServlet extends HttpServlet {
305307

306308
@Override
307-
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
308-
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE,
309-
req.getContentType());
309+
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
310+
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE, req.getContentType());
310311

311312
Map<String, String[]> parameters = req.getParameterMap();
312313
assertEquals(2, parameters.size());
@@ -322,15 +323,14 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
322323
}
323324
}
324325

326+
325327
@SuppressWarnings("serial")
326328
private static class DeleteServlet extends HttpServlet {
327329

328330
@Override
329-
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
330-
throws ServletException, IOException {
331+
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
331332
resp.setStatus(200);
332333
}
333-
334334
}
335335

336336
}

spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,22 @@ public class WebSocketStompClientTests {
5959
private static final Charset UTF_8 = Charset.forName("UTF-8");
6060

6161

62-
private TestWebSocketStompClient stompClient;
63-
6462
@Mock
6563
private TaskScheduler taskScheduler;
6664

6765
@Mock
6866
private ConnectionHandlingStompSession stompSession;
6967

68+
@Mock
69+
private WebSocketSession webSocketSession;
70+
71+
72+
private TestWebSocketStompClient stompClient;
73+
7074
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
7175

7276
private SettableListenableFuture<WebSocketSession> handshakeFuture;
7377

74-
@Mock
75-
private WebSocketSession webSocketSession;
76-
7778

7879
@Before
7980
public void setUp() throws Exception {
@@ -123,7 +124,7 @@ public void webSocketConnectionClosed() throws Exception {
123124
}
124125

125126
@Test
126-
@SuppressWarnings({ "unchecked", "rawtypes" })
127+
@SuppressWarnings({"unchecked", "rawtypes"})
127128
public void handleWebSocketMessage() throws Exception {
128129
String text = "SEND\na:alpha\n\nMessage payload\0";
129130
connect().handleMessage(this.webSocketSession, new TextMessage(text));
@@ -141,7 +142,7 @@ public void handleWebSocketMessage() throws Exception {
141142
}
142143

143144
@Test
144-
@SuppressWarnings({ "unchecked", "rawtypes" })
145+
@SuppressWarnings({"unchecked", "rawtypes"})
145146
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
146147
WebSocketHandler webSocketHandler = connect();
147148

@@ -166,7 +167,7 @@ public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
166167
}
167168

168169
@Test
169-
@SuppressWarnings({ "unchecked", "rawtypes" })
170+
@SuppressWarnings({"unchecked", "rawtypes"})
170171
public void handleWebSocketMessageBinary() throws Exception {
171172
String text = "SEND\na:alpha\n\nMessage payload\0";
172173
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(UTF_8)));
@@ -249,7 +250,7 @@ public void heartbeatDefaultValueSetWithoutScheduler() throws Exception {
249250
fail("Expected IllegalStateException");
250251
}
251252
catch (IllegalStateException ex) {
252-
// Ignore
253+
// ignore
253254
}
254255
}
255256

@@ -290,7 +291,7 @@ public void writeInactivityBeforeDelayHasElapsed() throws Exception {
290291
}
291292

292293
@Test
293-
@SuppressWarnings({ "rawtypes", "unchecked" })
294+
@SuppressWarnings({"rawtypes", "unchecked"})
294295
public void cancelInactivityTasks() throws Exception {
295296
TcpConnection<byte[]> tcpConnection = getTcpConnection();
296297

0 commit comments

Comments
 (0)