001
014
015 package com.liferay.portal.kernel.test;
016
017 import java.lang.reflect.Method;
018
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import org.junit.internal.AssumptionViolatedException;
023 import org.junit.runners.model.MultipleFailureException;
024 import org.junit.runners.model.Statement;
025
026
029 public class RunAfterTestMethodCallback extends AbstractStatementCallback {
030
031 public RunAfterTestMethodCallback(
032 Object instance, Method method, Statement statement,
033 TestContextHandler testContextHandler) {
034
035 super(statement, testContextHandler);
036
037 _instance = instance;
038 _method = method;
039 }
040
041 @Override
042 public void evaluate() throws Throwable {
043 List<Throwable> throwables = new ArrayList<Throwable>();
044
045 Statement statement = getStatement();
046
047 if (statement != null) {
048 try {
049 statement.evaluate();
050 }
051 catch (Throwable t) {
052 if (!(t instanceof AssumptionViolatedException)) {
053 throwables.add(t);
054 }
055 }
056 }
057
058 try {
059 TestContextHandler testContextHandler = getTestContextHandler();
060
061 testContextHandler.runAfterTestMethod(_instance, _method);
062 }
063 catch (Exception e) {
064 throwables.add(e);
065 }
066
067 if (!throwables.isEmpty()) {
068 throw new MultipleFailureException(throwables);
069 }
070 }
071
072 private Object _instance;
073 private Method _method;
074
075 }