001/**
002 * Powerunit - A JDK1.8 test framework
003 * Copyright (C) 2014 Mathieu Boretti.
004 *
005 * This file is part of Powerunit
006 *
007 * Powerunit is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * Powerunit is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>.
019 */
020package ch.powerunit.surefire;
021
022import org.apache.maven.surefire.report.CategorizedReportEntry;
023import org.apache.maven.surefire.report.ConsoleStream;
024import org.apache.maven.surefire.report.LegacyPojoStackTraceWriter;
025import org.apache.maven.surefire.report.RunListener;
026
027import ch.powerunit.TestContext;
028import ch.powerunit.TestResultListener;
029
030/**
031 * @author borettim
032 *
033 */
034public class PowerUnitProviderListener<T> implements TestResultListener<T> {
035        private final RunListener rl;
036        private final Class<?> underTest;
037        private final ConsoleStream consoleLogger;
038
039        public PowerUnitProviderListener(ConsoleStream consoleLogger, RunListener rl, Class<?> underTest) {
040                this.rl = rl;
041                this.underTest = underTest;
042                this.consoleLogger = consoleLogger;
043        }
044
045        @Override
046        public void notifyStart(TestContext<T> context) {
047                rl.testStarting(new CategorizedReportEntry(underTest.getCanonicalName(), context.getFullTestName(),
048                                context.getTestCategories()));
049        }
050
051        @Override
052        public void notifySuccess(TestContext<T> context) {
053                rl.testSucceeded(new CategorizedReportEntry(underTest.getCanonicalName(), context.getFullTestName(),
054                                context.getTestCategories()));
055        }
056
057        @Override
058        public void notifyFailure(TestContext<T> context, Throwable cause) {
059                rl.testFailed(new CategorizedReportEntry(underTest.getCanonicalName(), context.getFullTestName(),
060                                context.getTestCategories(),
061                                new LegacyPojoStackTraceWriter(underTest.getCanonicalName(), context.getFullTestName(), cause), null));
062        }
063
064        @Override
065        public void notifySetStart(String setName, String groups) {
066                rl.testSetStarting(new CategorizedReportEntry(underTest.getCanonicalName(), setName, groups));
067        }
068
069        @Override
070        public void notifySetEnd(String setName, String groups) {
071                rl.testSetCompleted(new CategorizedReportEntry(underTest.getCanonicalName(), setName, groups));
072        }
073
074        @Override
075        public void notifySkipped(TestContext<T> context) {
076                rl.testSkipped(new CategorizedReportEntry(underTest.getCanonicalName(), context.getFullTestName(),
077                                context.getTestCategories()));
078        }
079
080        @Override
081        public void notifyError(TestContext<T> context, Throwable cause) {
082                rl.testError(new CategorizedReportEntry(underTest.getCanonicalName(), context.getFullTestName(),
083                                context.getTestCategories(),
084                                new LegacyPojoStackTraceWriter(underTest.getCanonicalName(), context.getFullTestName(), cause), null));
085        }
086
087        @Override
088        public void notifyParameterStart(String setName, String parameterName) {
089                // Do nothing
090        }
091
092        @Override
093        public void notifyParameterEnd(String setName, String parameterName) {
094                // Do nothing
095        }
096}