001/*
002 * Copyright 2002-2017 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 *      https://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.test.context.junit.jupiter;
018
019import org.junit.jupiter.api.extension.ConditionEvaluationResult;
020import org.junit.jupiter.api.extension.ExtensionContext;
021
022/**
023 * {@code DisabledIfCondition} is an {@link org.junit.jupiter.api.extension.ExecutionCondition}
024 * that supports the {@link DisabledIf @DisabledIf} annotation when using the <em>Spring
025 * TestContext Framework</em> in conjunction with JUnit 5's <em>Jupiter</em> programming model.
026 *
027 * <p>Any attempt to use the {@code DisabledIfCondition} without the presence of
028 * {@link DisabledIf @DisabledIf} will result in an <em>enabled</em>
029 * {@link ConditionEvaluationResult}.
030 *
031 * @author Sam Brannen
032 * @since 5.0
033 * @see DisabledIf
034 * @see EnabledIf
035 * @see SpringExtension
036 */
037public class DisabledIfCondition extends AbstractExpressionEvaluatingCondition {
038
039        /**
040         * Containers and tests are disabled if {@code @DisabledIf} is present on the
041         * corresponding test class or test method and the configured expression evaluates
042         * to {@code true}.
043         */
044        @Override
045        public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
046                return evaluateAnnotation(DisabledIf.class, DisabledIf::expression, DisabledIf::reason,
047                                DisabledIf::loadContext, false, context);
048        }
049
050}