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.assertj;
018
019import java.util.function.Supplier;
020
021import org.springframework.boot.test.context.runner.ApplicationContextRunner;
022import org.springframework.context.ApplicationContext;
023import org.springframework.context.ConfigurableApplicationContext;
024
025/**
026 * An {@link ApplicationContext} that additionally supports AssertJ style assertions. Can
027 * be used to decorate an existing application context or an application context that
028 * failed to start.
029 * <p>
030 * See {@link ApplicationContextAssertProvider} for more details.
031 *
032 * @author Phillip Webb
033 * @since 2.0.0
034 * @see ApplicationContextRunner
035 * @see ApplicationContext
036 */
037public interface AssertableApplicationContext
038                extends ApplicationContextAssertProvider<ConfigurableApplicationContext>,
039                ConfigurableApplicationContext {
040
041        /**
042         * Factory method to create a new {@link AssertableApplicationContext} instance.
043         * @param contextSupplier a supplier that will either return a fully configured
044         * {@link ConfigurableApplicationContext} or throw an exception if the context fails
045         * to start.
046         * @return an {@link AssertableApplicationContext} instance
047         */
048        static AssertableApplicationContext get(
049                        Supplier<? extends ConfigurableApplicationContext> contextSupplier) {
050                return ApplicationContextAssertProvider.get(AssertableApplicationContext.class,
051                                ConfigurableApplicationContext.class, contextSupplier);
052        }
053
054}