001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.test.context.runner; 018 019import java.util.List; 020import java.util.function.Supplier; 021 022import org.springframework.boot.context.annotation.Configurations; 023import org.springframework.boot.test.context.assertj.AssertableApplicationContext; 024import org.springframework.boot.test.util.TestPropertyValues; 025import org.springframework.context.ApplicationContext; 026import org.springframework.context.ApplicationContextInitializer; 027import org.springframework.context.ConfigurableApplicationContext; 028import org.springframework.context.annotation.AnnotationConfigApplicationContext; 029 030/** 031 * An {@link AbstractApplicationContextRunner ApplicationContext runner} for a standard, 032 * non-web environment {@link ConfigurableApplicationContext}. 033 * <p> 034 * See {@link AbstractApplicationContextRunner} for details. 035 * 036 * @author Stephane Nicoll 037 * @author Andy Wilkinson 038 * @author Phillip Webb 039 * @since 2.0.0 040 */ 041public class ApplicationContextRunner extends 042 AbstractApplicationContextRunner<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> { 043 044 /** 045 * Create a new {@link ApplicationContextRunner} instance using an 046 * {@link AnnotationConfigApplicationContext} as the underlying source. 047 */ 048 public ApplicationContextRunner() { 049 this(AnnotationConfigApplicationContext::new); 050 } 051 052 /** 053 * Create a new {@link ApplicationContextRunner} instance using the specified 054 * {@code contextFactory} as the underlying source. 055 * @param contextFactory a supplier that returns a new instance on each call 056 */ 057 public ApplicationContextRunner( 058 Supplier<ConfigurableApplicationContext> contextFactory) { 059 super(contextFactory); 060 } 061 062 private ApplicationContextRunner( 063 Supplier<ConfigurableApplicationContext> contextFactory, 064 List<ApplicationContextInitializer<? super ConfigurableApplicationContext>> initializers, 065 TestPropertyValues environmentProperties, TestPropertyValues systemProperties, 066 ClassLoader classLoader, ApplicationContext parent, 067 List<Configurations> configurations) { 068 super(contextFactory, initializers, environmentProperties, systemProperties, 069 classLoader, parent, configurations); 070 } 071 072 @Override 073 protected ApplicationContextRunner newInstance( 074 Supplier<ConfigurableApplicationContext> contextFactory, 075 List<ApplicationContextInitializer<? super ConfigurableApplicationContext>> initializers, 076 TestPropertyValues environmentProperties, TestPropertyValues systemProperties, 077 ClassLoader classLoader, ApplicationContext parent, 078 List<Configurations> configurations) { 079 return new ApplicationContextRunner(contextFactory, initializers, 080 environmentProperties, systemProperties, classLoader, parent, 081 configurations); 082 } 083 084}