Skip to content

Commit 43071b9

Browse files
committed
Polish formatting
1 parent 2bfcefa commit 43071b9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ public void notAnError() throws Exception {
8383
@Test
8484
public void notAnErrorButNotOK() throws Exception {
8585
this.chain = new MockFilterChain() {
86+
8687
@Override
8788
public void doFilter(ServletRequest request, ServletResponse response)
8889
throws IOException, ServletException {
8990
((HttpServletResponse) response).setStatus(201);
9091
super.doFilter(request, response);
9192
response.flushBuffer();
9293
}
94+
9395
};
9496
this.filter.doFilter(this.request, this.response, this.chain);
9597
assertThat(((HttpServletResponse) this.chain.getResponse()).getStatus())
@@ -103,12 +105,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
103105
public void unauthorizedWithErrorPath() throws Exception {
104106
this.filter.addErrorPages(new ErrorPage("/error"));
105107
this.chain = new MockFilterChain() {
108+
106109
@Override
107110
public void doFilter(ServletRequest request, ServletResponse response)
108111
throws IOException, ServletException {
109112
((HttpServletResponse) response).sendError(401, "UNAUTHORIZED");
110113
super.doFilter(request, response);
111114
}
115+
112116
};
113117
this.filter.doFilter(this.request, this.response, this.chain);
114118
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -127,12 +131,14 @@ public void responseCommitted() throws Exception {
127131
this.filter.addErrorPages(new ErrorPage("/error"));
128132
this.response.setCommitted(true);
129133
this.chain = new MockFilterChain() {
134+
130135
@Override
131136
public void doFilter(ServletRequest request, ServletResponse response)
132137
throws IOException, ServletException {
133138
((HttpServletResponse) response).sendError(400, "BAD");
134139
super.doFilter(request, response);
135140
}
141+
136142
};
137143
this.filter.doFilter(this.request, this.response, this.chain);
138144
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -147,12 +153,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
147153
@Test
148154
public void responseUncommittedWithoutErrorPage() throws Exception {
149155
this.chain = new MockFilterChain() {
156+
150157
@Override
151158
public void doFilter(ServletRequest request, ServletResponse response)
152159
throws IOException, ServletException {
153160
((HttpServletResponse) response).sendError(400, "BAD");
154161
super.doFilter(request, response);
155162
}
163+
156164
};
157165
this.filter.doFilter(this.request, this.response, this.chain);
158166
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -167,13 +175,15 @@ public void doFilter(ServletRequest request, ServletResponse response)
167175
@Test
168176
public void oncePerRequest() throws Exception {
169177
this.chain = new MockFilterChain() {
178+
170179
@Override
171180
public void doFilter(ServletRequest request, ServletResponse response)
172181
throws IOException, ServletException {
173182
((HttpServletResponse) response).sendError(400, "BAD");
174183
assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull();
175184
super.doFilter(request, response);
176185
}
186+
177187
};
178188
this.filter.init(new MockFilterConfig("FILTER"));
179189
this.filter.doFilter(this.request, this.response, this.chain);
@@ -183,12 +193,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
183193
public void globalError() throws Exception {
184194
this.filter.addErrorPages(new ErrorPage("/error"));
185195
this.chain = new MockFilterChain() {
196+
186197
@Override
187198
public void doFilter(ServletRequest request, ServletResponse response)
188199
throws IOException, ServletException {
189200
((HttpServletResponse) response).sendError(400, "BAD");
190201
super.doFilter(request, response);
191202
}
203+
192204
};
193205
this.filter.doFilter(this.request, this.response, this.chain);
194206
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -207,12 +219,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
207219
public void statusError() throws Exception {
208220
this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
209221
this.chain = new MockFilterChain() {
222+
210223
@Override
211224
public void doFilter(ServletRequest request, ServletResponse response)
212225
throws IOException, ServletException {
213226
((HttpServletResponse) response).sendError(400, "BAD");
214227
super.doFilter(request, response);
215228
}
229+
216230
};
217231
this.filter.doFilter(this.request, this.response, this.chain);
218232
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -231,13 +245,15 @@ public void doFilter(ServletRequest request, ServletResponse response)
231245
public void statusErrorWithCommittedResponse() throws Exception {
232246
this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
233247
this.chain = new MockFilterChain() {
248+
234249
@Override
235250
public void doFilter(ServletRequest request, ServletResponse response)
236251
throws IOException, ServletException {
237252
((HttpServletResponse) response).sendError(400, "BAD");
238253
response.flushBuffer();
239254
super.doFilter(request, response);
240255
}
256+
241257
};
242258
this.filter.doFilter(this.request, this.response, this.chain);
243259
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -250,12 +266,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
250266
public void exceptionError() throws Exception {
251267
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
252268
this.chain = new MockFilterChain() {
269+
253270
@Override
254271
public void doFilter(ServletRequest request, ServletResponse response)
255272
throws IOException, ServletException {
256273
super.doFilter(request, response);
257274
throw new RuntimeException("BAD");
258275
}
276+
259277
};
260278
this.filter.doFilter(this.request, this.response, this.chain);
261279
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -282,13 +300,15 @@ public void doFilter(ServletRequest request, ServletResponse response)
282300
public void exceptionErrorWithCommittedResponse() throws Exception {
283301
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
284302
this.chain = new MockFilterChain() {
303+
285304
@Override
286305
public void doFilter(ServletRequest request, ServletResponse response)
287306
throws IOException, ServletException {
288307
super.doFilter(request, response);
289308
response.flushBuffer();
290309
throw new RuntimeException("BAD");
291310
}
311+
292312
};
293313
this.filter.doFilter(this.request, this.response, this.chain);
294314
assertThat(this.response.getForwardedUrl()).isNull();
@@ -297,12 +317,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
297317
@Test
298318
public void statusCode() throws Exception {
299319
this.chain = new MockFilterChain() {
320+
300321
@Override
301322
public void doFilter(ServletRequest request, ServletResponse response)
302323
throws IOException, ServletException {
303324
assertThat(((HttpServletResponse) response).getStatus()).isEqualTo(200);
304325
super.doFilter(request, response);
305326
}
327+
306328
};
307329
this.filter.doFilter(this.request, this.response, this.chain);
308330
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -313,12 +335,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
313335
public void subClassExceptionError() throws Exception {
314336
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
315337
this.chain = new MockFilterChain() {
338+
316339
@Override
317340
public void doFilter(ServletRequest request, ServletResponse response)
318341
throws IOException, ServletException {
319342
super.doFilter(request, response);
320343
throw new IllegalStateException("BAD");
321344
}
345+
322346
};
323347
this.filter.doFilter(this.request, this.response, this.chain);
324348
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -356,12 +380,14 @@ public void responseIsCommittedWhenRequestIsAsyncAndExceptionIsThrown()
356380
this.filter.addErrorPages(new ErrorPage("/error"));
357381
this.request.setAsyncStarted(true);
358382
this.chain = new MockFilterChain() {
383+
359384
@Override
360385
public void doFilter(ServletRequest request, ServletResponse response)
361386
throws IOException, ServletException {
362387
super.doFilter(request, response);
363388
throw new RuntimeException("BAD");
364389
}
390+
365391
};
366392
this.filter.doFilter(this.request, this.response, this.chain);
367393
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -376,12 +402,14 @@ public void responseIsCommittedWhenRequestIsAsyncAndStatusIs400Plus()
376402
this.filter.addErrorPages(new ErrorPage("/error"));
377403
this.request.setAsyncStarted(true);
378404
this.chain = new MockFilterChain() {
405+
379406
@Override
380407
public void doFilter(ServletRequest request, ServletResponse response)
381408
throws IOException, ServletException {
382409
super.doFilter(request, response);
383410
((HttpServletResponse) response).sendError(400, "BAD");
384411
}
412+
385413
};
386414
this.filter.doFilter(this.request, this.response, this.chain);
387415
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -406,12 +434,14 @@ public void responseIsCommittedWhenExceptionIsThrownDuringAsyncDispatch()
406434
this.filter.addErrorPages(new ErrorPage("/error"));
407435
setUpAsyncDispatch();
408436
this.chain = new MockFilterChain() {
437+
409438
@Override
410439
public void doFilter(ServletRequest request, ServletResponse response)
411440
throws IOException, ServletException {
412441
super.doFilter(request, response);
413442
throw new RuntimeException("BAD");
414443
}
444+
415445
};
416446
this.filter.doFilter(this.request, this.response, this.chain);
417447
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -426,12 +456,14 @@ public void responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch()
426456
this.filter.addErrorPages(new ErrorPage("/error"));
427457
setUpAsyncDispatch();
428458
this.chain = new MockFilterChain() {
459+
429460
@Override
430461
public void doFilter(ServletRequest request, ServletResponse response)
431462
throws IOException, ServletException {
432463
super.doFilter(request, response);
433464
((HttpServletResponse) response).sendError(400, "BAD");
434465
}
466+
435467
};
436468
this.filter.doFilter(this.request, this.response, this.chain);
437469
assertThat(this.chain.getRequest()).isEqualTo(this.request);
@@ -493,12 +525,14 @@ public void doFilter(ServletRequest request, ServletResponse response)
493525
public void nestedServletExceptionIsUnwrapped() throws Exception {
494526
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
495527
this.chain = new MockFilterChain() {
528+
496529
@Override
497530
public void doFilter(ServletRequest request, ServletResponse response)
498531
throws IOException, ServletException {
499532
super.doFilter(request, response);
500533
throw new NestedServletException("Wrapper", new RuntimeException("BAD"));
501534
}
535+
502536
};
503537
this.filter.doFilter(this.request, this.response, this.chain);
504538
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
@@ -525,13 +559,15 @@ public void doFilter(ServletRequest request, ServletResponse response)
525559
public void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient()
526560
throws Exception {
527561
this.chain = new MockFilterChain() {
562+
528563
@Override
529564
public void doFilter(ServletRequest request, ServletResponse response)
530565
throws IOException, ServletException {
531566
((HttpServletResponse) response).sendError(400);
532567
response.getWriter().flush();
533568
super.doFilter(request, response);
534569
}
570+
535571
};
536572
this.filter.doFilter(this.request, this.response, this.chain);
537573
assertThat(this.response.getStatus()).isEqualTo(400);

0 commit comments

Comments
 (0)