diff options
author | Paul Duffin <paulduffin@google.com> | 2016-12-14 11:13:37 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2016-12-15 18:53:12 +0000 |
commit | 4dd042caba6f0ee54f604a409df7152b3e8205bb (patch) | |
tree | fd9aa7f11b8c8f927c9e98fd828e60086895ca5e /src/main/java/org/junit/ClassRule.java | |
parent | 50db5f5810104e1dd0b0294145e9d3e602bb2627 (diff) | |
download | junit-4dd042caba6f0ee54f604a409df7152b3e8205bb.tar.gz |
Moved source to match upstream file structure
Will make it simpler to update JUnit source.
Bug: 33613916
Test: make checkbuild
Change-Id: I76984a6defd3e40f34eea995e6ed865d32d53da3
Diffstat (limited to 'src/main/java/org/junit/ClassRule.java')
-rw-r--r-- | src/main/java/org/junit/ClassRule.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/org/junit/ClassRule.java b/src/main/java/org/junit/ClassRule.java new file mode 100644 index 0000000..97a111f --- /dev/null +++ b/src/main/java/org/junit/ClassRule.java @@ -0,0 +1,60 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotates static fields that contain rules. Such a field must be public, + * static, and a subtype of {@link org.junit.rules.TestRule}. + * The {@link org.junit.runners.model.Statement} passed + * to the {@link org.junit.rules.TestRule} will run any {@link BeforeClass} methods, + * then the entire body of the test class (all contained methods, if it is + * a standard JUnit test class, or all contained classes, if it is a + * {@link org.junit.runners.Suite}), and finally any {@link AfterClass} methods. + * + * The statement passed to the {@link org.junit.rules.TestRule} will never throw an exception, + * and throwing an exception from the {@link org.junit.rules.TestRule} will result in undefined + * behavior. This means that some {@link org.junit.rules.TestRule}s, such as + * {@link org.junit.rules.ErrorCollector}, + * {@link org.junit.rules.ExpectedException}, + * and {@link org.junit.rules.Timeout}, + * have undefined behavior when used as {@link ClassRule}s. + * + * If there are multiple + * annotated {@link ClassRule}s on a class, they will be applied in an order + * that depends on your JVM's implementation of the reflection API, which is + * undefined, in general. + * + * For example, here is a test suite that connects to a server once before + * all the test classes run, and disconnects after they are finished: + * + * <pre> + * + * @RunWith(Suite.class) + * @SuiteClasses({A.class, B.class, C.class}) + * public class UsesExternalResource { + * public static Server myServer= new Server(); + * + * @ClassRule + * public static ExternalResource resource= new ExternalResource() { + * @Override + * protected void before() throws Throwable { + * myServer.connect(); + * }; + * + * @Override + * protected void after() { + * myServer.disconnect(); + * }; + * }; + * } + * </pre> + * + * For more information and more examples, see {@link org.junit.rules.TestRule}. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface ClassRule { +} |