Commit 43071b93 authored by Phillip Webb's avatar Phillip Webb

Polish formatting

parent 2bfcefa4
...@@ -83,6 +83,7 @@ public class ErrorPageFilterTests { ...@@ -83,6 +83,7 @@ public class ErrorPageFilterTests {
@Test @Test
public void notAnErrorButNotOK() throws Exception { public void notAnErrorButNotOK() throws Exception {
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
...@@ -90,6 +91,7 @@ public class ErrorPageFilterTests { ...@@ -90,6 +91,7 @@ public class ErrorPageFilterTests {
super.doFilter(request, response); super.doFilter(request, response);
response.flushBuffer(); response.flushBuffer();
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponse) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponse) this.chain.getResponse()).getStatus())
...@@ -103,12 +105,14 @@ public class ErrorPageFilterTests { ...@@ -103,12 +105,14 @@ public class ErrorPageFilterTests {
public void unauthorizedWithErrorPath() throws Exception { public void unauthorizedWithErrorPath() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
((HttpServletResponse) response).sendError(401, "UNAUTHORIZED"); ((HttpServletResponse) response).sendError(401, "UNAUTHORIZED");
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -127,12 +131,14 @@ public class ErrorPageFilterTests { ...@@ -127,12 +131,14 @@ public class ErrorPageFilterTests {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
this.response.setCommitted(true); this.response.setCommitted(true);
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -147,12 +153,14 @@ public class ErrorPageFilterTests { ...@@ -147,12 +153,14 @@ public class ErrorPageFilterTests {
@Test @Test
public void responseUncommittedWithoutErrorPage() throws Exception { public void responseUncommittedWithoutErrorPage() throws Exception {
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -167,6 +175,7 @@ public class ErrorPageFilterTests { ...@@ -167,6 +175,7 @@ public class ErrorPageFilterTests {
@Test @Test
public void oncePerRequest() throws Exception { public void oncePerRequest() throws Exception {
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
...@@ -174,6 +183,7 @@ public class ErrorPageFilterTests { ...@@ -174,6 +183,7 @@ public class ErrorPageFilterTests {
assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull(); assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull();
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.init(new MockFilterConfig("FILTER")); this.filter.init(new MockFilterConfig("FILTER"));
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
...@@ -183,12 +193,14 @@ public class ErrorPageFilterTests { ...@@ -183,12 +193,14 @@ public class ErrorPageFilterTests {
public void globalError() throws Exception { public void globalError() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -207,12 +219,14 @@ public class ErrorPageFilterTests { ...@@ -207,12 +219,14 @@ public class ErrorPageFilterTests {
public void statusError() throws Exception { public void statusError() throws Exception {
this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -231,6 +245,7 @@ public class ErrorPageFilterTests { ...@@ -231,6 +245,7 @@ public class ErrorPageFilterTests {
public void statusErrorWithCommittedResponse() throws Exception { public void statusErrorWithCommittedResponse() throws Exception {
this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
...@@ -238,6 +253,7 @@ public class ErrorPageFilterTests { ...@@ -238,6 +253,7 @@ public class ErrorPageFilterTests {
response.flushBuffer(); response.flushBuffer();
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -250,12 +266,14 @@ public class ErrorPageFilterTests { ...@@ -250,12 +266,14 @@ public class ErrorPageFilterTests {
public void exceptionError() throws Exception { public void exceptionError() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
throw new RuntimeException("BAD"); throw new RuntimeException("BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -282,6 +300,7 @@ public class ErrorPageFilterTests { ...@@ -282,6 +300,7 @@ public class ErrorPageFilterTests {
public void exceptionErrorWithCommittedResponse() throws Exception { public void exceptionErrorWithCommittedResponse() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
...@@ -289,6 +308,7 @@ public class ErrorPageFilterTests { ...@@ -289,6 +308,7 @@ public class ErrorPageFilterTests {
response.flushBuffer(); response.flushBuffer();
throw new RuntimeException("BAD"); throw new RuntimeException("BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getForwardedUrl()).isNull(); assertThat(this.response.getForwardedUrl()).isNull();
...@@ -297,12 +317,14 @@ public class ErrorPageFilterTests { ...@@ -297,12 +317,14 @@ public class ErrorPageFilterTests {
@Test @Test
public void statusCode() throws Exception { public void statusCode() throws Exception {
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
assertThat(((HttpServletResponse) response).getStatus()).isEqualTo(200); assertThat(((HttpServletResponse) response).getStatus()).isEqualTo(200);
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -313,12 +335,14 @@ public class ErrorPageFilterTests { ...@@ -313,12 +335,14 @@ public class ErrorPageFilterTests {
public void subClassExceptionError() throws Exception { public void subClassExceptionError() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
throw new IllegalStateException("BAD"); throw new IllegalStateException("BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -356,12 +380,14 @@ public class ErrorPageFilterTests { ...@@ -356,12 +380,14 @@ public class ErrorPageFilterTests {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
this.request.setAsyncStarted(true); this.request.setAsyncStarted(true);
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
throw new RuntimeException("BAD"); throw new RuntimeException("BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -376,12 +402,14 @@ public class ErrorPageFilterTests { ...@@ -376,12 +402,14 @@ public class ErrorPageFilterTests {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
this.request.setAsyncStarted(true); this.request.setAsyncStarted(true);
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -406,12 +434,14 @@ public class ErrorPageFilterTests { ...@@ -406,12 +434,14 @@ public class ErrorPageFilterTests {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
setUpAsyncDispatch(); setUpAsyncDispatch();
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
throw new RuntimeException("BAD"); throw new RuntimeException("BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -426,12 +456,14 @@ public class ErrorPageFilterTests { ...@@ -426,12 +456,14 @@ public class ErrorPageFilterTests {
this.filter.addErrorPages(new ErrorPage("/error")); this.filter.addErrorPages(new ErrorPage("/error"));
setUpAsyncDispatch(); setUpAsyncDispatch();
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
((HttpServletResponse) response).sendError(400, "BAD"); ((HttpServletResponse) response).sendError(400, "BAD");
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(this.chain.getRequest()).isEqualTo(this.request);
...@@ -493,12 +525,14 @@ public class ErrorPageFilterTests { ...@@ -493,12 +525,14 @@ public class ErrorPageFilterTests {
public void nestedServletExceptionIsUnwrapped() throws Exception { public void nestedServletExceptionIsUnwrapped() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
super.doFilter(request, response); super.doFilter(request, response);
throw new NestedServletException("Wrapper", new RuntimeException("BAD")); throw new NestedServletException("Wrapper", new RuntimeException("BAD"));
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
...@@ -525,6 +559,7 @@ public class ErrorPageFilterTests { ...@@ -525,6 +559,7 @@ public class ErrorPageFilterTests {
public void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient() public void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient()
throws Exception { throws Exception {
this.chain = new MockFilterChain() { this.chain = new MockFilterChain() {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
...@@ -532,6 +567,7 @@ public class ErrorPageFilterTests { ...@@ -532,6 +567,7 @@ public class ErrorPageFilterTests {
response.getWriter().flush(); response.getWriter().flush();
super.doFilter(request, response); super.doFilter(request, response);
} }
}; };
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getStatus()).isEqualTo(400); assertThat(this.response.getStatus()).isEqualTo(400);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment