1package org.junit;
2
3import java.lang.annotation.ElementType;
4import java.lang.annotation.Retention;
5import java.lang.annotation.RetentionPolicy;
6import java.lang.annotation.Target;
7
8/**
9 * <p>The <code>Test</code> annotation tells JUnit that the <code>public void</code> method
10 * to which it is attached can be run as a test case. To run the method,
11 * JUnit first constructs a fresh instance of the class then invokes the
12 * annotated method. Any exceptions thrown by the test will be reported
13 * by JUnit as a failure. If no exceptions are thrown, the test is assumed
14 * to have succeeded.</p>
15 *
16 * <p>A simple test looks like this:
17 * <pre>
18 * public class Example {
19 *    <b>&#064;Test</b>
20 *    public void method() {
21 *       org.junit.Assert.assertTrue( new ArrayList().isEmpty() );
22 *    }
23 * }
24 * </pre>
25 * </p>
26 *
27 * <p>The <code>Test</code> annotation supports two optional parameters.
28 * The first, <code>expected</code>, declares that a test method should throw
29 * an exception. If it doesn't throw an exception or if it throws a different exception
30 * than the one declared, the test fails. For example, the following test succeeds:
31 * <pre>
32 *    &#064;Test(<b>expected=IndexOutOfBoundsException.class</b>) public void outOfBounds() {
33 *       new ArrayList&lt;Object&gt;().get(1);
34 *    }
35 * </pre></p>
36 *
37 * <p>The second optional parameter, <code>timeout</code>, causes a test to fail if it takes
38 * longer than a specified amount of clock time (measured in milliseconds). The following test fails:
39 * <pre>
40 *    &#064;Test(<b>timeout=100</b>) public void infinity() {
41 *       while(true);
42 *    }
43 * </pre></p>
44 */
45@Retention(RetentionPolicy.RUNTIME)
46@Target({ElementType.METHOD})
47public @interface Test {
48
49	/**
50	 * Default empty exception
51	 */
52	static class None extends Throwable {
53		private static final long serialVersionUID= 1L;
54		private None() {
55		}
56	}
57
58	/**
59	 * Optionally specify <code>expected</code>, a Throwable, to cause a test method to succeed iff
60	 * an exception of the specified class is thrown by the method.
61	 */
62	Class<? extends Throwable> expected() default None.class;
63
64	/**
65	 * Optionally specify <code>timeout</code> in milliseconds to cause a test method to fail if it
66	 * takes longer than that number of milliseconds.*/
67	long timeout() default 0L;
68}
69