From 191bbc20dcb6769edc550a433e65fca25cdab85f Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 25 Apr 2017 17:23:20 -0400 Subject: [PATCH] StandaloneMockMvcBuilder allows custom HandlerMapping Issue: SPR-15472 --- .../setup/StandaloneMockMvcBuilder.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java index 9463e6e6f0..bd075cd906 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.function.Supplier; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanInitializationException; @@ -85,7 +86,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; */ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder { - private final Object[] controllers; + private final List controllers; private List controllerAdvice; @@ -121,6 +122,8 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder placeholderValues = new HashMap<>(); + private Supplier handlerMappingFactory = RequestMappingHandlerMapping::new; + /** * Protected constructor. Not intended for direct instantiation. @@ -128,7 +131,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder factory) { + Assert.notNull(factory, "RequestMappingHandlerMapping supplier is required."); + this.handlerMappingFactory = factory; + return this; + } + @Override protected WebApplicationContext initWebAppContext() { @@ -338,13 +352,13 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder