001 package org.junit.rules; 002 003 import org.junit.Rule; 004 import org.junit.runners.model.FrameworkMethod; 005 import org.junit.runners.model.Statement; 006 007 /** 008 * A MethodRule is an alteration in how a test method is run and reported. 009 * Multiple {@link MethodRule}s can be applied to a test method. The 010 * {@link Statement} that executes the method is passed to each annotated 011 * {@link Rule} in turn, and each may return a substitute or modified 012 * {@link Statement}, which is passed to the next {@link Rule}, if any. For 013 * an example of how this can be useful, see {@link TestWatchman}. 014 * 015 * <p>Note that {@link MethodRule} has been replaced by {@link TestRule}, 016 * which has the added benefit of supporting class rules. 017 * 018 * @since 4.7 019 */ 020 public interface MethodRule { 021 /** 022 * Modifies the method-running {@link Statement} to implement an additional 023 * test-running rule. 024 * 025 * @param base The {@link Statement} to be modified 026 * @param method The method to be run 027 * @param target The object on which the method will be run. 028 * @return a new statement, which may be the same as {@code base}, 029 * a wrapper around {@code base}, or a completely new Statement. 030 */ 031 Statement apply(Statement base, FrameworkMethod method, Object target); 032 }