springboot 单元测试


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");
    }

   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值