001/* 002 * Copyright 2002-2015 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.junit4.statements; 018 019import org.junit.runners.model.Statement; 020 021import org.springframework.test.context.TestContextManager; 022 023/** 024 * {@code RunBeforeTestClassCallbacks} is a custom JUnit {@link Statement} which allows 025 * the <em>Spring TestContext Framework</em> to be plugged into the JUnit execution chain 026 * by calling {@link TestContextManager#beforeTestClass() beforeTestClass()} on the 027 * supplied {@link TestContextManager}. 028 * 029 * @author Sam Brannen 030 * @since 3.0 031 * @see #evaluate() 032 * @see RunAfterTestMethodCallbacks 033 */ 034public class RunBeforeTestClassCallbacks extends Statement { 035 036 private final Statement next; 037 038 private final TestContextManager testContextManager; 039 040 041 /** 042 * Construct a new {@code RunBeforeTestClassCallbacks} statement. 043 * @param next the next {@code Statement} in the execution chain 044 * @param testContextManager the TestContextManager upon which to call 045 * {@code beforeTestClass()} 046 */ 047 public RunBeforeTestClassCallbacks(Statement next, TestContextManager testContextManager) { 048 this.next = next; 049 this.testContextManager = testContextManager; 050 } 051 052 053 /** 054 * Invoke {@link TestContextManager#beforeTestClass()} and then evaluate 055 * the next {@link Statement} in the execution chain (typically an instance 056 * of {@link org.junit.internal.runners.statements.RunBefores RunBefores}). 057 */ 058 @Override 059 public void evaluate() throws Throwable { 060 this.testContextManager.beforeTestClass(); 061 this.next.evaluate(); 062 } 063 064}