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
* limitations under the License.
*/
package org.springframework.http.server.reactive;
import java.util.Arrays;
@ -35,11 +36,11 @@ import static org.junit.Assert.fail;
/**
* Unit tests for {@link HttpHandlerAdapterSupport}.
*
* @author Rossen Stoyanchev
*/
public class HttpHandlerAdapterSupportTests {
@Test
public void invalidContextPath() throws Exception {
testInvalidContextPath(" ", "contextPath must not be empty");
@ -94,7 +95,7 @@ public class HttpHandlerAdapterSupportTests {
@Test
public void matchWithNativeContextPath() throws Exception {
MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, "/yet/another/path");
request.setContextPath("/yet"); // contextPath in underlying request
request.setContextPath("/yet"); // contextPath in underlying request
TestHttpHandler handler = new TestHttpHandler();
Map<String, HttpHandler> map = Collections.singletonMap("/another/path", handler);
@ -139,7 +140,6 @@ public class HttpHandlerAdapterSupportTests {
@SuppressWarnings("WeakerAccess")
private static class TestHttpHandlerAdapter extends HttpHandlerAdapterSupport {
public TestHttpHandlerAdapter(Map<String, HttpHandler> handlerMap) {
super(handlerMap);
}
@ -156,14 +156,14 @@ public class HttpHandlerAdapterSupportTests {
}
}
@SuppressWarnings("WeakerAccess")
private static class TestHttpHandler implements HttpHandler {
private ServerHttpRequest request;
public boolean wasInvoked() {
return this.request != null;
return (this.request != null);
}
public ServerHttpRequest getRequest() {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.filter;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@ -32,20 +32,18 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* Unit tests for {@link ForwardedHeaderFilter}.
*
* @author Rossen Stoyanchev
* @author Eddú Meléndez
* @author Rob Winch
*/
public class ForwardedHeaderFilterTests {
private static final String X_FORWARDED_PROTO = "x-forwarded-proto"; // SPR-14372 (case insensitive)
private static final String X_FORWARDED_PROTO = "x-forwarded-proto"; // SPR-14372 (case insensitive)
private static final String X_FORWARDED_HOST = "x-forwarded-host";
private static final String X_FORWARDED_PORT = "x-forwarded-port";
private static final String X_FORWARDED_PREFIX = "x-forwarded-prefix";
@ -133,9 +131,7 @@ public class ForwardedHeaderFilterTests {
@Test
public void caseInsensitiveForwardedPrefix() throws Exception {
this.request = new MockHttpServletRequest() {
// Make it case-sensitive (SPR-14372)
@Override
public String getHeader(String header) {
Enumeration<String> names = getHeaderNames();
@ -359,6 +355,7 @@ public class ForwardedHeaderFilterTests {
assertEquals("../foo/bar", redirectedUrl);
}
private String sendRedirect(final String location) throws ServletException, IOException {
MockHttpServletResponse response = doWithFiltersAndGetResponse(this.filter, new OncePerRequestFilter() {
@Override
@ -367,10 +364,10 @@ public class ForwardedHeaderFilterTests {
response.sendRedirect(location);
}
});
return response.getRedirectedUrl();
}
@SuppressWarnings("serial")
private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
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");
* 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
* 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.LogFactory;
@ -34,10 +34,7 @@ import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* @author Rossen Stoyanchev
@ -46,7 +43,6 @@ public class FilteringWebHandlerTests {
private static Log logger = LogFactory.getLog(FilteringWebHandlerTests.class);
private MockServerHttpRequest request;
private MockServerHttpResponse response;
@ -58,6 +54,7 @@ public class FilteringWebHandlerTests {
this.response = new MockServerHttpResponse();
}
@Test
public void multipleFilters() throws Exception {
StubWebHandler webHandler = new StubWebHandler();
@ -122,6 +119,7 @@ public class FilteringWebHandlerTests {
assertEquals("boo", savedException.getMessage());
}
private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
return WebHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
}
@ -146,6 +144,7 @@ public class FilteringWebHandlerTests {
}
}
private static class ShortcircuitingFilter extends TestFilter {
@Override
@ -154,6 +153,7 @@ public class FilteringWebHandlerTests {
}
}
private static class AsyncFilter extends TestFilter {
@Override
@ -169,6 +169,7 @@ public class FilteringWebHandlerTests {
}
}
private static class ExceptionFilter implements WebFilter {
@Override
@ -177,6 +178,7 @@ public class FilteringWebHandlerTests {
}
}
private static class TestExceptionHandler implements WebExceptionHandler {
private Throwable ex;
@ -188,6 +190,7 @@ public class FilteringWebHandlerTests {
}
}
private static class StubWebHandler implements WebHandler {
private volatile boolean invoked;