• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.junit.rules;
2 
3 import org.junit.Rule;
4 import org.junit.runners.model.FrameworkMethod;
5 import org.junit.runners.model.Statement;
6 
7 /**
8  * A MethodRule is an alteration in how a test method is run and reported.
9  * Multiple {@link MethodRule}s can be applied to a test method. The
10  * {@link Statement} that executes the method is passed to each annotated
11  * {@link Rule} in turn, and each may return a substitute or modified
12  * {@link Statement}, which is passed to the next {@link Rule}, if any. For
13  * an example of how this can be useful, see {@link TestWatchman}.
14  *
15  * <p>Note that {@link MethodRule} has been replaced by {@link TestRule},
16  * which has the added benefit of supporting class rules.
17  *
18  * @since 4.7
19  */
20 public interface MethodRule {
21     /**
22      * Modifies the method-running {@link Statement} to implement an additional
23      * test-running rule.
24      *
25      * @param base The {@link Statement} to be modified
26      * @param method The method to be run
27      * @param target The object on which the method will be run.
28      * @return a new statement, which may be the same as {@code base},
29      *         a wrapper around {@code base}, or a completely new Statement.
30      */
apply(Statement base, FrameworkMethod method, Object target)31     Statement apply(Statement base, FrameworkMethod method, Object target);
32 }
33