Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -51,24 +51,20 @@ public class MockMvcBuilders {
|
||||
* Build a {@link MockMvc} instance by registering one or more
|
||||
* {@code @Controller} instances and configuring Spring MVC infrastructure
|
||||
* programmatically.
|
||||
*
|
||||
* <p>This allows full control over the instantiation and initialization of
|
||||
* controllers and their dependencies, similar to plain unit tests while
|
||||
* also making it possible to test one controller at a time.
|
||||
*
|
||||
* <p>When this builder is used, the minimum infrastructure required by the
|
||||
* {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet}
|
||||
* to serve requests with annotated controllers is created automatically
|
||||
* and can be customized, resulting in configuration that is equivalent to
|
||||
* what MVC Java configuration provides except using builder-style methods.
|
||||
*
|
||||
* <p>If the Spring MVC configuration of an application is relatively
|
||||
* straight-forward — for example, when using the MVC namespace in
|
||||
* XML or MVC Java config — then using this builder might be a good
|
||||
* option for testing a majority of controllers. In such cases, a much
|
||||
* smaller number of tests can be used to focus on testing and verifying
|
||||
* the actual Spring MVC configuration.
|
||||
*
|
||||
* @param controllers one or more {@code @Controller} instances to test
|
||||
*/
|
||||
public static StandaloneMockMvcBuilder standaloneSetup(Object... controllers) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -32,8 +32,6 @@ import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.PropertyPlaceholderHelper;
|
||||
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
@@ -127,18 +125,16 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
|
||||
* @see MockMvcBuilders#standaloneSetup(Object...)
|
||||
*/
|
||||
protected StandaloneMockMvcBuilder(Object... controllers) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(controllers), "At least one controller is required");
|
||||
this.controllers = controllers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register one or more
|
||||
* {@link org.springframework.web.bind.annotation.ControllerAdvice
|
||||
* ControllerAdvice} instances to be used in tests.
|
||||
* <p>Normally {@code @ControllerAdvice} are auto-detected as long as they're
|
||||
* declared as Spring beans. However since the standalone setup does not load
|
||||
* any Spring configuration they need to be registered explicitly here
|
||||
* instead much like controllers.
|
||||
* Register one or more {@link org.springframework.web.bind.annotation.ControllerAdvice}
|
||||
* instances to be used in tests.
|
||||
* <p>Normally {@code @ControllerAdvice} are auto-detected as long as they're declared
|
||||
* as Spring beans. However since the standalone setup does not load any Spring config,
|
||||
* they need to be registered explicitly here instead much like controllers.
|
||||
* @since 4.2
|
||||
*/
|
||||
public StandaloneMockMvcBuilder setControllerAdvice(Object... controllerAdvice) {
|
||||
@@ -531,7 +527,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
|
||||
}
|
||||
|
||||
@Override
|
||||
public View resolveViewName(String viewName, Locale locale) throws Exception {
|
||||
public View resolveViewName(String viewName, Locale locale) {
|
||||
return this.view;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user