Polish WebHttpHandlerBuilder

This commit is contained in:
Rossen Stoyanchev
2017-03-10 10:00:56 -05:00
parent b799013567
commit 2cd6240dab
7 changed files with 129 additions and 136 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.web.server.handler;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Mono;
@@ -90,7 +92,7 @@ public class ExceptionHandlingHttpHandlerTests {
}
private WebHandler createWebHandler(WebExceptionHandler... handlers) {
return new ExceptionHandlingWebHandler(this.targetHandler, handlers);
return new ExceptionHandlingWebHandler(this.targetHandler, Arrays.asList(handlers));
}
@@ -101,11 +103,11 @@ public class ExceptionHandlingHttpHandlerTests {
private final boolean raise;
public StubWebHandler(RuntimeException exception) {
StubWebHandler(RuntimeException exception) {
this(exception, false);
}
public StubWebHandler(RuntimeException exception, boolean raise) {
StubWebHandler(RuntimeException exception, boolean raise) {
this.exception = exception;
this.raise = raise;
}

View File

@@ -16,6 +16,10 @@
package org.springframework.web.server.handler;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
@@ -110,9 +114,13 @@ public class FilteringWebHandlerTests {
@Test
public void handleErrorFromFilter() throws Exception {
TestExceptionHandler exceptionHandler = new TestExceptionHandler();
HttpHandler handler = WebHttpHandlerBuilder.webHandler(new StubWebHandler())
.filters(new ExceptionFilter()).exceptionHandlers(exceptionHandler).build();
handler.handle(this.request, this.response).block();
List<ExceptionFilter> filters = Collections.singletonList(new ExceptionFilter());
List<WebExceptionHandler> exceptionHandlers = Collections.singletonList(exceptionHandler);
WebHttpHandlerBuilder.webHandler(new StubWebHandler())
.filters(filters).exceptionHandlers(exceptionHandlers).build()
.handle(this.request, this.response)
.block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
@@ -123,7 +131,7 @@ public class FilteringWebHandlerTests {
private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
return WebHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
return WebHttpHandlerBuilder.webHandler(webHandler).filters(Arrays.asList(filters)).build();
}