01: package org.junit.internal.runners;
02:
03: import java.lang.reflect.InvocationTargetException;
04: import java.lang.reflect.Method;
05: import java.util.List;
06:
07: import org.junit.After;
08: import org.junit.Before;
09: import org.junit.Ignore;
10: import org.junit.Test;
11: import org.junit.Test.None;
12:
13: public class TestMethod {
14: private final Method fMethod;
15: private TestClass fTestClass;
16:
17: public TestMethod(Method method, TestClass testClass) {
18: fMethod = method;
19: fTestClass = testClass;
20: }
21:
22: public boolean isIgnored() {
23: return fMethod.getAnnotation(Ignore.class) != null;
24: }
25:
26: public long getTimeout() {
27: Test annotation = fMethod.getAnnotation(Test.class);
28: if (annotation == null)
29: return 0;
30: long timeout = annotation.timeout();
31: return timeout;
32: }
33:
34: protected Class<? extends Throwable> getExpectedException() {
35: Test annotation = fMethod.getAnnotation(Test.class);
36: if (annotation == null || annotation.expected() == None.class)
37: return null;
38: else
39: return annotation.expected();
40: }
41:
42: boolean isUnexpected(Throwable exception) {
43: return !getExpectedException().isAssignableFrom(
44: exception.getClass());
45: }
46:
47: boolean expectsException() {
48: return getExpectedException() != null;
49: }
50:
51: List<Method> getBefores() {
52: return fTestClass.getAnnotatedMethods(Before.class);
53: }
54:
55: List<Method> getAfters() {
56: return fTestClass.getAnnotatedMethods(After.class);
57: }
58:
59: public void invoke(Object test) throws IllegalArgumentException,
60: IllegalAccessException, InvocationTargetException {
61: fMethod.invoke(test);
62: }
63:
64: }
|