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