001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }