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.runner.Description; 8 import org.junit.runner.notification.Failure; 9 import org.junit.runner.notification.RunNotifier; 10 import org.junit.runners.BlockJUnit4ClassRunner; 11 12 /** 13 * @deprecated Included for backwards compatibility with JUnit 4.4. Will be 14 * removed in the next release. Please use 15 * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. 16 */ 17 @Deprecated 18 public 19 class ClassRoadie { 20 private RunNotifier fNotifier; 21 private TestClass fTestClass; 22 private Description fDescription; 23 private final Runnable fRunnable; 24 ClassRoadie(RunNotifier notifier, TestClass testClass, Description description, Runnable runnable)25 public ClassRoadie(RunNotifier notifier, TestClass testClass, 26 Description description, Runnable runnable) { 27 fNotifier= notifier; 28 fTestClass= testClass; 29 fDescription= description; 30 fRunnable= runnable; 31 } 32 runUnprotected()33 protected void runUnprotected() { 34 fRunnable.run(); 35 }; 36 addFailure(Throwable targetException)37 protected void addFailure(Throwable targetException) { 38 fNotifier.fireTestFailure(new Failure(fDescription, targetException)); 39 } 40 runProtected()41 public void runProtected() { 42 try { 43 runBefores(); 44 runUnprotected(); 45 } catch (FailedBefore e) { 46 } finally { 47 runAfters(); 48 } 49 } 50 runBefores()51 private void runBefores() throws FailedBefore { 52 try { 53 try { 54 List<Method> befores= fTestClass.getBefores(); 55 for (Method before : befores) 56 before.invoke(null); 57 } catch (InvocationTargetException e) { 58 throw e.getTargetException(); 59 } 60 } catch (org.junit.internal.AssumptionViolatedException e) { 61 throw new FailedBefore(); 62 } catch (Throwable e) { 63 addFailure(e); 64 throw new FailedBefore(); 65 } 66 } 67 runAfters()68 private void runAfters() { 69 List<Method> afters= fTestClass.getAfters(); 70 for (Method after : afters) 71 try { 72 after.invoke(null); 73 } catch (InvocationTargetException e) { 74 addFailure(e.getTargetException()); 75 } catch (Throwable e) { 76 addFailure(e); // Untested, but seems impossible 77 } 78 } 79 }