1package org.junit;2import java.lang.annotation.ElementType;3import java.lang.annotation.Retention;4import java.lang.annotation.RetentionPolicy;5import java.lang.annotation.Target;6/**7 * Annotates static fields that contain rules. Such a field must be public,8 * static, and a subtype of {@link org.junit.rules.TestRule}. 9 * The {@link org.junit.runners.model.Statement} passed 10 * to the {@link org.junit.rules.TestRule} will run any {@link BeforeClass} methods, 11 * then the entire body of the test class (all contained methods, if it is12 * a standard JUnit test class, or all contained classes, if it is a 13 * {@link org.junit.runners.Suite}), and finally any {@link AfterClass} methods.14 * 15 * The statement passed to the {@link org.junit.rules.TestRule} will never throw an exception,16 * and throwing an exception from the {@link org.junit.rules.TestRule} will result in undefined17 * behavior. This means that some {@link org.junit.rules.TestRule}s, such as 18 * {@link org.junit.rules.ErrorCollector}, 19 * {@link org.junit.rules.ExpectedException}, 20 * and {@link org.junit.rules.Timeout},21 * have undefined behavior when used as {@link ClassRule}s.22 * 23 * If there are multiple24 * annotated {@link ClassRule}s on a class, they will be applied in an order25 * that depends on your JVM's implementation of the reflection API, which is26 * undefined, in general.27 *28 * For example, here is a test suite that connects to a server once before29 * all the test classes run, and disconnects after they are finished:30 * 31 * <pre>32 * 33 * @RunWith(Suite.class)34 * @SuiteClasses({A.class, B.class, C.class})35 * public class UsesExternalResource {36 * public static Server myServer= new Server();37 * 38 * @ClassRule39 * public static ExternalResource resource= new ExternalResource() {40 * @Override41 * protected void before() throws Throwable {42 * myServer.connect();43 * };44 * 45 * @Override46 * protected void after() {47 * myServer.disconnect();48 * };49 * };50 * }51 * </pre>52 * 53 * For more information and more examples, see {@link org.junit.rules.TestRule}. 54 */55@Retention(RetentionPolicy.RUNTIME)56@Target({ElementType.FIELD})57public @interface ClassRule {58}...