Home | History | Annotate | Download | only in statements
      1 package org.junit.internal.runners.statements;
      2 
      3 import java.util.ArrayList;
      4 import java.util.List;
      5 
      6 import org.junit.runners.model.FrameworkMethod;
      7 import org.junit.runners.model.MultipleFailureException;
      8 import org.junit.runners.model.Statement;
      9 
     10 public class RunAfters extends Statement {
     11     private final Statement next;
     12 
     13     private final Object target;
     14 
     15     private final List<FrameworkMethod> afters;
     16 
     17     public RunAfters(Statement next, List<FrameworkMethod> afters, Object target) {
     18         this.next = next;
     19         this.afters = afters;
     20         this.target = target;
     21     }
     22 
     23     @Override
     24     public void evaluate() throws Throwable {
     25         List<Throwable> errors = new ArrayList<Throwable>();
     26         try {
     27             next.evaluate();
     28         } catch (Throwable e) {
     29             errors.add(e);
     30         } finally {
     31             for (FrameworkMethod each : afters) {
     32                 try {
     33                     each.invokeExplosively(target);
     34                 } catch (Throwable e) {
     35                     errors.add(e);
     36                 }
     37             }
     38         }
     39         MultipleFailureException.assertEmpty(errors);
     40     }
     41 }