1b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpackage org.junit;
2b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot
3b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.annotation.ElementType;
4b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.annotation.Retention;
5b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.annotation.RetentionPolicy;
6b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.annotation.Target;
7b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot
8b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot/**
9b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * Annotates fields that contain rules. Such a field must be public, not
10b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * static, and a subtype of {@link org.junit.rules.TestRule}.
11b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * The {@link org.junit.runners.model.Statement} passed
12b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * to the {@link org.junit.rules.TestRule} will run any {@link Before} methods,
13b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * then the {@link Test} method, and finally any {@link After} methods,
14b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * throwing an exception if any of these fail.  If there are multiple
15b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * annotated {@link Rule}s on a class, they will be applied in an order
16b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * that depends on your JVM's implementation of the reflection API, which is
17b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * undefined, in general.
18b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot *
19b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * For example, here is a test class that creates a temporary folder before
20b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * each test method, and deletes it after each:
21b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot *
22b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * <pre>
23b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * public static class HasTempFolder {
24b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 	&#064;Rule
25b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 	public TemporaryFolder folder= new TemporaryFolder();
26b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot *
27b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 	&#064;Test
28b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 	public void testUsingTempFolder() throws IOException {
29b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 		File createdFile= folder.newFile(&quot;myfile.txt&quot;);
30b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 		File createdFolder= folder.newFolder(&quot;subfolder&quot;);
31b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 		// ...
32b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * 	}
33b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * }
34b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * </pre>
35b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot *
36b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * For more information and more examples, see
37b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * {@link org.junit.rules.TestRule}.
38b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot *
39b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * Note: for backwards compatibility, this annotation may also mark
40b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * fields of type {@link org.junit.rules.MethodRule}, which will be honored.  However,
41b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * this is a deprecated interface and feature.
42b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot */
43b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot@Retention(RetentionPolicy.RUNTIME)
44b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot@Target({ElementType.FIELD})
45b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpublic @interface Rule {
46b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot
47b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot}