Polishing

This commit is contained in:
Juergen Hoeller 2016-12-21 14:42:43 +01:00
parent 598122fe8a
commit b54aee27be
3 changed files with 21 additions and 21 deletions

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.http.server.reactive; package org.springframework.http.server.reactive;
import java.util.Arrays; import java.util.Arrays;
@ -35,11 +36,11 @@ import static org.junit.Assert.fail;
/** /**
* Unit tests for {@link HttpHandlerAdapterSupport}. * Unit tests for {@link HttpHandlerAdapterSupport}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class HttpHandlerAdapterSupportTests { public class HttpHandlerAdapterSupportTests {
@Test @Test
public void invalidContextPath() throws Exception { public void invalidContextPath() throws Exception {
testInvalidContextPath(" ", "contextPath must not be empty"); testInvalidContextPath(" ", "contextPath must not be empty");
@ -139,7 +140,6 @@ public class HttpHandlerAdapterSupportTests {
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
private static class TestHttpHandlerAdapter extends HttpHandlerAdapterSupport { private static class TestHttpHandlerAdapter extends HttpHandlerAdapterSupport {
public TestHttpHandlerAdapter(Map<String, HttpHandler> handlerMap) { public TestHttpHandlerAdapter(Map<String, HttpHandler> handlerMap) {
super(handlerMap); super(handlerMap);
} }
@ -156,14 +156,14 @@ public class HttpHandlerAdapterSupportTests {
} }
} }
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
private static class TestHttpHandler implements HttpHandler { private static class TestHttpHandler implements HttpHandler {
private ServerHttpRequest request; private ServerHttpRequest request;
public boolean wasInvoked() { public boolean wasInvoked() {
return this.request != null; return (this.request != null);
} }
public ServerHttpRequest getRequest() { public ServerHttpRequest getRequest() {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.filter; package org.springframework.web.filter;
import java.io.IOException; import java.io.IOException;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -32,13 +32,11 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* Unit tests for {@link ForwardedHeaderFilter}. * Unit tests for {@link ForwardedHeaderFilter}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Rob Winch * @author Rob Winch
@ -133,9 +131,7 @@ public class ForwardedHeaderFilterTests {
@Test @Test
public void caseInsensitiveForwardedPrefix() throws Exception { public void caseInsensitiveForwardedPrefix() throws Exception {
this.request = new MockHttpServletRequest() { this.request = new MockHttpServletRequest() {
// Make it case-sensitive (SPR-14372) // Make it case-sensitive (SPR-14372)
@Override @Override
public String getHeader(String header) { public String getHeader(String header) {
Enumeration<String> names = getHeaderNames(); Enumeration<String> names = getHeaderNames();
@ -359,6 +355,7 @@ public class ForwardedHeaderFilterTests {
assertEquals("../foo/bar", redirectedUrl); assertEquals("../foo/bar", redirectedUrl);
} }
private String sendRedirect(final String location) throws ServletException, IOException { private String sendRedirect(final String location) throws ServletException, IOException {
MockHttpServletResponse response = doWithFiltersAndGetResponse(this.filter, new OncePerRequestFilter() { MockHttpServletResponse response = doWithFiltersAndGetResponse(this.filter, new OncePerRequestFilter() {
@Override @Override
@ -367,10 +364,10 @@ public class ForwardedHeaderFilterTests {
response.sendRedirect(location); response.sendRedirect(location);
} }
}); });
return response.getRedirectedUrl(); return response.getRedirectedUrl();
} }
@SuppressWarnings("serial")
private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException { private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain(new HttpServlet() {}, filters); FilterChain filterChain = new MockFilterChain(new HttpServlet() {}, filters);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.server.handler;
package org.springframework.web.server.handler;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -34,10 +34,7 @@ import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.WebHandler; import org.springframework.web.server.WebHandler;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -46,7 +43,6 @@ public class FilteringWebHandlerTests {
private static Log logger = LogFactory.getLog(FilteringWebHandlerTests.class); private static Log logger = LogFactory.getLog(FilteringWebHandlerTests.class);
private MockServerHttpRequest request; private MockServerHttpRequest request;
private MockServerHttpResponse response; private MockServerHttpResponse response;
@ -58,6 +54,7 @@ public class FilteringWebHandlerTests {
this.response = new MockServerHttpResponse(); this.response = new MockServerHttpResponse();
} }
@Test @Test
public void multipleFilters() throws Exception { public void multipleFilters() throws Exception {
StubWebHandler webHandler = new StubWebHandler(); StubWebHandler webHandler = new StubWebHandler();
@ -122,6 +119,7 @@ public class FilteringWebHandlerTests {
assertEquals("boo", savedException.getMessage()); assertEquals("boo", savedException.getMessage());
} }
private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) { private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
return WebHttpHandlerBuilder.webHandler(webHandler).filters(filters).build(); return WebHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
} }
@ -146,6 +144,7 @@ public class FilteringWebHandlerTests {
} }
} }
private static class ShortcircuitingFilter extends TestFilter { private static class ShortcircuitingFilter extends TestFilter {
@Override @Override
@ -154,6 +153,7 @@ public class FilteringWebHandlerTests {
} }
} }
private static class AsyncFilter extends TestFilter { private static class AsyncFilter extends TestFilter {
@Override @Override
@ -169,6 +169,7 @@ public class FilteringWebHandlerTests {
} }
} }
private static class ExceptionFilter implements WebFilter { private static class ExceptionFilter implements WebFilter {
@Override @Override
@ -177,6 +178,7 @@ public class FilteringWebHandlerTests {
} }
} }
private static class TestExceptionHandler implements WebExceptionHandler { private static class TestExceptionHandler implements WebExceptionHandler {
private Throwable ex; private Throwable ex;
@ -188,6 +190,7 @@ public class FilteringWebHandlerTests {
} }
} }
private static class StubWebHandler implements WebHandler { private static class StubWebHandler implements WebHandler {
private volatile boolean invoked; private volatile boolean invoked;