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