001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.test;
016    
017    import java.util.ArrayList;
018    import java.util.List;
019    
020    import org.junit.runners.model.MultipleFailureException;
021    import org.junit.runners.model.Statement;
022    
023    /**
024     * @author Miguel Pastor
025     */
026    public class RunAfterTestClassesCallback extends AbstractStatementCallback {
027    
028            public RunAfterTestClassesCallback(
029                    Statement statement, TestContextHandler testContextHandler) {
030    
031                    super(statement, testContextHandler);
032            }
033    
034            @Override
035            public void evaluate() throws Throwable {
036                    List<Throwable> throwables = new ArrayList<Throwable>();
037    
038                    Statement statement = getStatement();
039    
040                    if ( statement != null) {
041                            try {
042                                    statement.evaluate();
043                            }
044                            catch (Throwable t) {
045                                    throwables.add(t);
046                            }
047                    }
048    
049                    try {
050                            TestContextHandler testContextHandler = getTestContextHandler();
051    
052                            testContextHandler.runAfterTestClasses();
053                    }
054                    catch (Exception e) {
055                            throwables.add(e);
056                    }
057    
058                    if (!throwables.isEmpty()) {
059                            throw new MultipleFailureException(throwables);
060                    }
061            }
062    
063    }