springboot 单元测试
*********************
相关类与接口
MockMvcBuilders
public final class MockMvcBuilders {
private MockMvcBuilders() {
}
public static DefaultMockMvcBuilder webAppContextSetup(WebApplicationContext context) {
return new DefaultMockMvcBuilder(context);
}
public static StandaloneMockMvcBuilder standaloneSetup(Object... controllers) {
return new StandaloneMockMvcBuilder(controllers);
}
}
DefaultMockMvcBuilder
public class DefaultMockMvcBuilder extends AbstractMockMvcBuilder<DefaultMockMvcBuilder> {
private final WebApplicationContext webAppContext;
protected DefaultMockMvcBuilder(WebApplicationContext webAppContext) {
Assert.notNull(webAppContext, "WebApplicationContext is required");
Assert.notNull(webAppContext.getServletContext(), "WebApplicationContext must have a ServletContext");
this.webAppContext = webAppContext;
}
protected WebApplicationContext initWebAppContext() {
AbstractMockMvcBuilder
public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>> extends MockMvcBuilderSupport implements ConfigurableMockMvcBuilder<B> {
private List<Filter> filters = new ArrayList();
@Nullable
private RequestBuilder defaultRequestBuilder;
@Nullable
private Charset defaultResponseCharacterEncoding;
private final List<ResultMatcher> globalResultMatchers = new ArrayList();
private final List<ResultHandler> globalResultHandlers = new ArrayList();
private final List<DispatcherServletCustomizer> dispatcherServletCustomizers = new ArrayList();
private final List<MockMvcConfigurer> configurers = new ArrayList(4);
public AbstractMockMvcBuilder() {
}
public final <T extends B> T addFilters(Filter... filters) {
public final <T extends B> T addFilter(Filter filter, String... urlPatterns) {
public final <T extends B> T defaultRequest(RequestBuilder requestBuilder) {
public final <T extends B> T defaultResponseCharacterEncoding(Charset defaultResponseCharacterEncoding) {
public final <T extends B> T alwaysExpect(ResultMatcher resultMatcher) {
public final <T extends B> T alwaysDo(ResultHandler resultHandler) {
public final <T extends B> T addDispatcherServletCustomizer(DispatcherServletCustomizer customizer) {
public final <T extends B> T dispatchOptions(boolean dispatchOptions) {
public final <T extends B> T apply(MockMvcConfigurer configurer) {
public final MockMvc build() {
protected <T extends B> T self() {
protected abstract WebApplicationContext initWebAppContext();
MockMvcBuilderSupport
public abstract class MockMvcBuilderSupport {
public MockMvcBuilderSupport() {
}
protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig, WebApplicationContext webAppContext, @Nullable RequestBuilder defaultRequestBuilder, @Nullable Charset defaultResponseCharacterEncoding, List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, @Nullable List<DispatcherServletCustomizer> dispatcherServletCustomizers) {
protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig, WebApplicationContext webAppContext, @Nullable RequestBuilder defaultRequestBuilder, List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, @Nullable List<DispatcherServletCustomizer> dispatcherServletCustomizers) {
************
静态内部类:MockMvcBuildException
private static class MockMvcBuildException extends NestedRuntimeException {
public MockMvcBuildException(String msg, Throwable cause) {
super(msg, cause);
}
}
}
ConfigurableMockMvcBuilder
public interface ConfigurableMockMvcBuilder<B extends ConfigurableMockMvcBuilder<B>> extends MockMvcBuilder {
<T extends B> T addFilters(Filter... filters);
<T extends B> T addFilter(Filter filter, String... urlPatterns);
<T extends B> T defaultRequest(RequestBuilder requestBuilder);
default <T extends B> T defaultResponseCharacterEncoding(Charset defaultResponseCharacterEncoding) {
throw new UnsupportedOperationException("defaultResponseCharacterEncoding is not supported by this MockMvcBuilder");
}