View Javadoc
1   package org.junit.internal.runners;
2   
3   import java.lang.reflect.InvocationTargetException;
4   import java.lang.reflect.Method;
5   import java.util.List;
6   
7   import org.junit.After;
8   import org.junit.Before;
9   import org.junit.Ignore;
10  import org.junit.Test;
11  import org.junit.Test.None;
12  import org.junit.runners.BlockJUnit4ClassRunner;
13  
14  /**
15   * @deprecated Included for backwards compatibility with JUnit 4.4. Will be
16   *             removed in the next major release. Please use
17   *             {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}.
18   */
19  @Deprecated
20  public class TestMethod {
21      private final Method method;
22      private TestClass testClass;
23  
24      public TestMethod(Method method, TestClass testClass) {
25          this.method = method;
26          this.testClass = testClass;
27      }
28  
29      public boolean isIgnored() {
30          return method.getAnnotation(Ignore.class) != null;
31      }
32  
33      public long getTimeout() {
34          Test annotation = method.getAnnotation(Test.class);
35          if (annotation == null) {
36              return 0;
37          }
38          long timeout = annotation.timeout();
39          return timeout;
40      }
41  
42      protected Class<? extends Throwable> getExpectedException() {
43          Test annotation = method.getAnnotation(Test.class);
44          if (annotation == null || annotation.expected() == None.class) {
45              return null;
46          } else {
47              return annotation.expected();
48          }
49      }
50  
51      boolean isUnexpected(Throwable exception) {
52          return !getExpectedException().isAssignableFrom(exception.getClass());
53      }
54  
55      boolean expectsException() {
56          return getExpectedException() != null;
57      }
58  
59      List<Method> getBefores() {
60          return testClass.getAnnotatedMethods(Before.class);
61      }
62  
63      List<Method> getAfters() {
64          return testClass.getAnnotatedMethods(After.class);
65      }
66  
67      public void invoke(Object test) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
68          method.invoke(test);
69      }
70  
71  }