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.ConsoleLogger;
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 ConsoleLogger consoleLogger;
038
039    public PowerUnitProviderListener(ConsoleLogger consoleLogger,
040            RunListener rl, Class<?> underTest) {
041        this.rl = rl;
042        this.underTest = underTest;
043        this.consoleLogger = consoleLogger;
044    }
045
046    @Override
047    public void notifyStart(TestContext<T> context) {
048        rl.testStarting(new CategorizedReportEntry(
049                underTest.getCanonicalName(), context.getFullTestName(),
050                context.getTestCategories()));
051    }
052
053    @Override
054    public void notifySuccess(TestContext<T> context) {
055        rl.testSucceeded(new CategorizedReportEntry(underTest
056                .getCanonicalName(), context.getFullTestName(), context
057                .getTestCategories()));
058    }
059
060    @Override
061    public void notifyFailure(TestContext<T> context, Throwable cause) {
062        rl.testFailed(new CategorizedReportEntry(underTest.getCanonicalName(),
063                context.getFullTestName(), context.getTestCategories(),
064                new LegacyPojoStackTraceWriter(underTest.getCanonicalName(),
065                        context.getFullTestName(), cause), null));
066    }
067
068    @Override
069    public void notifySetStart(String setName, String groups) {
070        rl.testSetStarting(new CategorizedReportEntry(underTest
071                .getCanonicalName(), setName, groups));
072    }
073
074    @Override
075    public void notifySetEnd(String setName, String groups) {
076        rl.testSetCompleted(new CategorizedReportEntry(underTest
077                .getCanonicalName(), setName, groups));
078    }
079
080    @Override
081    public void notifySkipped(TestContext<T> context) {
082        rl.testSkipped(new CategorizedReportEntry(underTest.getCanonicalName(),
083                context.getFullTestName(), context.getTestCategories()));
084    }
085
086    @Override
087    public void notifyError(TestContext<T> context, Throwable cause) {
088        rl.testError(new CategorizedReportEntry(underTest.getCanonicalName(),
089                context.getFullTestName(), context.getTestCategories(),
090                new LegacyPojoStackTraceWriter(underTest.getCanonicalName(),
091                        context.getFullTestName(), cause), null));
092    }
093
094    @Override
095    public void notifyParameterStart(String setName, String parameterName) {
096        // Do nothing
097    }
098
099    @Override
100    public void notifyParameterEnd(String setName, String parameterName) {
101        // Do nothing
102    }
103}