diff options
author | Pete Bentley <prb@google.com> | 2021-02-24 10:26:16 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-24 10:26:16 +0000 |
commit | 82af4b8b1d440f44b6ebac4db1fd61ae1d35a15e (patch) | |
tree | 1331fa1b743d5d0a341f82ff555ce4c602f40ab9 /src/main/java/org/junit/Rule.java | |
parent | d5e30375603aa83d21d16fbef079caab4d24e4c1 (diff) | |
parent | d8911c6e959a1bda9b2b77d9aa0d35eea7a401f9 (diff) | |
download | junit-82af4b8b1d440f44b6ebac4db1fd61ae1d35a15e.tar.gz |
Merge changes I8f5cd126,Ifdb59336,I6abae5ae,I5ec909df am: d135966357 am: d8911c6e95
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1601635
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ib00d0e3bda09315496b61b51b207bd8981c947e7
Diffstat (limited to 'src/main/java/org/junit/Rule.java')
-rw-r--r-- | src/main/java/org/junit/Rule.java | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main/java/org/junit/Rule.java b/src/main/java/org/junit/Rule.java index 711235c..9370e94 100644 --- a/src/main/java/org/junit/Rule.java +++ b/src/main/java/org/junit/Rule.java @@ -16,12 +16,14 @@ import java.lang.annotation.Target; * to the {@link org.junit.rules.TestRule} will run any {@link Before} methods, * then the {@link Test} method, and finally any {@link After} methods, * throwing an exception if any of these fail. If there are multiple - * annotated {@link Rule}s on a class, they will be applied in order of fields first, then methods. + * annotated {@link Rule}s on a class, they will be applied in order of methods first, then fields. * However, if there are multiple fields (or methods) they will be applied in an order * that depends on your JVM's implementation of the reflection API, which is * undefined, in general. Rules defined by fields will always be applied - * before Rules defined by methods. You can use a {@link org.junit.rules.RuleChain} if you want - * to have control over the order in which the Rules are applied. + * after Rules defined by methods, i.e. the Statements returned by the former will + * be executed around those returned by the latter. + * + * <h3>Usage</h3> * <p> * For example, here is a test class that creates a temporary folder before * each test method, and deletes it after each: @@ -61,10 +63,39 @@ import java.lang.annotation.Target; * For more information and more examples, see * {@link org.junit.rules.TestRule}. * + * <h3>Ordering</h3> + * <p> + * You can use {@link #order()} if you want to have control over the order in + * which the Rules are applied. + * + * <pre> + * public class ThreeRules { + * @Rule(order = 0) + * public LoggingRule outer = new LoggingRule("outer rule"); + * + * @Rule(order = 1) + * public LoggingRule middle = new LoggingRule("middle rule"); + * + * @Rule(order = 2) + * public LoggingRule inner = new LoggingRule("inner rule"); + * + * // ... + * } + * </pre> + * * @since 4.7 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD}) public @interface Rule { -}
\ No newline at end of file + int DEFAULT_ORDER = -1; + + /** + * Specifies the order in which rules are applied. The rules with a higher value are inner. + * + * @since 4.13 + */ + int order() default DEFAULT_ORDER; + +} |