Repository: maven-surefire Updated Branches: refs/heads/master 1d9fdf665 -> 26a773387
[SUREFIRE] refactoring and suppressed printing " null" if Exception.getMessage() returns NULL Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/26a77338 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/26a77338 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/26a77338 Branch: refs/heads/master Commit: 26a773387e8e811ccff685cd8baf00fdc213d707 Parents: 1d9fdf6 Author: tibordigana <tibo...@lycos.com> Authored: Fri Dec 11 09:04:01 2015 +0100 Committer: tibordigana <tibo...@lycos.com> Committed: Fri Dec 11 09:04:01 2015 +0100 ---------------------------------------------------------------------- .../surefire/StartupReportConfiguration.java | 48 ++++++-------------- .../booterclient/output/ForkClient.java | 4 +- .../report/ConsoleOutputFileReporter.java | 2 +- .../plugin/surefire/report/ConsoleReporter.java | 3 +- .../surefire/report/DefaultReporterFactory.java | 25 ++++------ .../surefire/report/StatelessXmlReporter.java | 4 +- .../surefire/report/TestSetRunListener.java | 1 - .../plugin/surefire/report/TestSetStats.java | 4 +- .../surefire/util/DirectoryScannerTest.java | 8 ++-- .../surefire/report/SmartStackTraceParser.java | 39 ++++++++-------- 10 files changed, 55 insertions(+), 83 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java index 5e34acb..5717f70 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java @@ -21,11 +21,10 @@ package org.apache.maven.plugin.surefire; import java.io.File; import java.io.PrintStream; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter; import org.apache.maven.plugin.surefire.report.ConsoleReporter; @@ -78,7 +77,8 @@ public class StartupReportConfiguration public static final String PLAIN_REPORT_FORMAT = ConsoleReporter.PLAIN; - private final Map<String, Map<String, List<WrappedReportEntry>>> testClassMethodRunHistoryMap; + private final Map<String, Map<String, List<WrappedReportEntry>>> testClassMethodRunHistoryMap + = new ConcurrentHashMap<String, Map<String, List<WrappedReportEntry>>>(); @SuppressWarnings( "checkstyle:parameternumber" ) public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat, @@ -100,9 +100,6 @@ public class StartupReportConfiguration this.originalSystemOut = System.out; this.originalSystemErr = System.err; this.rerunFailingTestsCount = rerunFailingTestsCount; - this.testClassMethodRunHistoryMap = - Collections.synchronizedMap( - new HashMap<String, Map<String, List<WrappedReportEntry>>>() ); } public static StartupReportConfiguration defaultValue() @@ -161,21 +158,17 @@ public class StartupReportConfiguration public StatelessXmlReporter instantiateStatelessXmlReporter() { - if ( !isDisableXmlReport() ) - { - return new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace, - rerunFailingTestsCount, testClassMethodRunHistoryMap ); - } - return null; + return isDisableXmlReport() + ? null + : new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace, + rerunFailingTestsCount, testClassMethodRunHistoryMap ); } public FileReporter instantiateFileReporter() { - if ( isUseFile() && isBriefOrPlainFormat() ) - { - return new FileReporter( reportsDirectory, getReportNameSuffix() ); - } - return null; + return isUseFile() && isBriefOrPlainFormat() + ? new FileReporter( reportsDirectory, getReportNameSuffix() ) + : null; } public boolean isBriefOrPlainFormat() @@ -196,24 +189,14 @@ public class StartupReportConfiguration public TestcycleConsoleOutputReceiver instantiateConsoleOutputFileReporter() { - if ( isRedirectTestOutputToFile() ) - { - return new ConsoleOutputFileReporter( reportsDirectory, getReportNameSuffix() ); - } - else - { - return new DirectConsoleOutput( originalSystemOut, originalSystemErr ); - } + return isRedirectTestOutputToFile() + ? new ConsoleOutputFileReporter( reportsDirectory, getReportNameSuffix() ) + : new DirectConsoleOutput( originalSystemOut, originalSystemErr ); } public StatisticsReporter instantiateStatisticsReporter() { - if ( requiresRunHistory ) - { - final File target = getStatisticsFile(); - return new StatisticsReporter( target ); - } - return null; + return requiresRunHistory ? new StatisticsReporter( getStatisticsFile() ) : null; } public File getStatisticsFile() @@ -221,13 +204,11 @@ public class StartupReportConfiguration return new File( reportsDirectory.getParentFile().getParentFile(), ".surefire-" + this.configurationHash ); } - public Properties getTestVmSystemProperties() { return testVmSystemProperties; } - public boolean isTrimStackTrace() { return trimStackTrace; @@ -247,5 +228,4 @@ public class StartupReportConfiguration { return originalSystemOut; } - } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index 4d01b1a..6b0794f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -289,14 +289,12 @@ public class ForkClient private StackTraceWriter deserializeStackTraceWriter( StringTokenizer tokens ) { - StackTraceWriter stackTraceWriter; String stackTraceMessage = nullableCsv( tokens.nextToken() ); String smartStackTrace = nullableCsv( tokens.nextToken() ); String stackTrace = tokens.hasMoreTokens() ? nullableCsv( tokens.nextToken() ) : null; - stackTraceWriter = stackTrace != null + return stackTrace != null ? new DeserializedStacktraceWriter( stackTraceMessage, smartStackTrace, stackTrace ) : null; - return stackTraceWriter; } private String nullableCsv( String source ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java index 25afe73..d7e0df7 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java @@ -53,7 +53,7 @@ public class ConsoleOutputFileReporter public void testSetStarting( ReportEntry reportEntry ) { close(); - this.reportEntryName = reportEntry.getName(); + reportEntryName = reportEntry.getName(); } public void testSetCompleted( ReportEntry report ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java index d0849bf..eabb447 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java @@ -44,11 +44,10 @@ public class ConsoleReporter private final PrintWriter writer; - public ConsoleReporter( PrintStream originalSystemOut ) { OutputStreamWriter out = new OutputStreamWriter( new BufferedOutputStream( originalSystemOut, BUFFER_SIZE ) ); - this.writer = new PrintWriter( out ); + writer = new PrintWriter( out ); } public void testSetStarting( ReportEntry report ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java index 2af0b40..13bcc96 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java @@ -72,7 +72,16 @@ public class DefaultReporterFactory public RunListener createReporter() { - return createTestSetRunListener(); + TestSetRunListener testSetRunListener = + new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(), + reportConfiguration.instantiateFileReporter(), + reportConfiguration.instantiateStatelessXmlReporter(), + reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter, + reportConfiguration.isTrimStackTrace(), + ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ), + reportConfiguration.isBriefOrPlainFormat() ); + addListener( testSetRunListener ); + return testSetRunListener; } public void mergeFromOtherFactories( Collection<DefaultReporterFactory> factories ) @@ -86,20 +95,6 @@ public class DefaultReporterFactory } } - public RunListener createTestSetRunListener() - { - TestSetRunListener testSetRunListener = - new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(), - reportConfiguration.instantiateFileReporter(), - reportConfiguration.instantiateStatelessXmlReporter(), - reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter, - reportConfiguration.isTrimStackTrace(), - ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ), - reportConfiguration.isBriefOrPlainFormat() ); - addListener( testSetRunListener ); - return testSetRunListener; - } - final void addListener( TestSetRunListener listener ) { listeners.add( listener ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index 1489f20..94c8d06 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -20,6 +20,7 @@ package org.apache.maven.plugin.surefire.report; */ import org.apache.maven.shared.utils.io.IOUtil; +import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import org.apache.maven.shared.utils.xml.XMLWriter; import org.apache.maven.surefire.report.ReportEntry; import org.apache.maven.surefire.report.ReporterException; @@ -124,8 +125,7 @@ public class StatelessXmlReporter OutputStreamWriter fw = getWriter( outputStream ); try { - org.apache.maven.shared.utils.xml.XMLWriter ppw = - new org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter( fw ); + XMLWriter ppw = new PrettyPrintXMLWriter( fw ); ppw.setEncoding( ENCODING ); createTestSuiteElement( ppw, testSetReportEntry, testSetStats, reportNameSuffix, http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java index 497a316..2bb187f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java @@ -165,7 +165,6 @@ public class TestSetRunListener public void testStarting( ReportEntry report ) { detailsForThis.testStart(); - } public void testSucceeded( ReportEntry reportEntry ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java index 790dbf5..2a1782e 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java @@ -89,7 +89,8 @@ public class TestSetStats { testStartAt = testEndAt; } - return reportEntry.getElapsed() != null ? reportEntry.getElapsed() : testEndAt - testStartAt; + Integer elapsedTime = reportEntry.getElapsed(); + return elapsedTime != null ? elapsedTime : testEndAt - testStartAt; } public void testSucceeded( WrappedReportEntry reportEntry ) @@ -97,7 +98,6 @@ public class TestSetStats finishTest( reportEntry ); } - public void testError( WrappedReportEntry reportEntry ) { errors += 1; http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java index 20d9f19..de6e706 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java @@ -27,6 +27,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.File; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -40,16 +41,15 @@ import static org.junit.runners.Parameterized.*; @RunWith( Parameterized.class ) public class DirectoryScannerTest { - @Parameters( name = "\"{0}\" should count {1} classes" ) - public static Object[][] data() { - return new Object[][] { + public static Iterable<Object[]> data() { + return Arrays.asList( new Object[][] { { "**/*ZT*A.java", is( 3 ) }, { "**/*ZT*A.java#testMethod", is( 3 ) }, { "**/*ZT?A.java#testMethod, !*ZT2A", is( 2 ) }, { "**/*ZT?A.java#testMethod, !*ZT2A#testMethod", is( 3 ) }, { "#testMethod", is( greaterThanOrEqualTo( 3 ) ) }, - }; + } ); } @Parameter( 0 ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/26a77338/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java index 6f4f058..8ad2369 100644 --- a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java +++ b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java @@ -20,11 +20,12 @@ package org.apache.maven.surefire.report; */ import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.maven.shared.utils.StringUtils; +import static java.util.Arrays.asList; +import static org.apache.maven.shared.utils.StringUtils.chompLast; +import static org.apache.maven.shared.utils.StringUtils.isNotEmpty; /** * @author Kristian Rosenvold @@ -40,11 +41,11 @@ public class SmartStackTraceParser private final String simpleName; - private String testClassName; + private final String testClassName; private final Class testClass; - private String testMethodName; + private final String testMethodName; public SmartStackTraceParser( Class testClass, Throwable throwable ) { @@ -94,7 +95,7 @@ public class SmartStackTraceParser if ( stackTraceElements.isEmpty() ) { result.append( simpleName ); - if ( StringUtils.isNotEmpty( testMethodName ) ) + if ( isNotEmpty( testMethodName ) ) { result.append( "." ) .append( testMethodName ); @@ -136,16 +137,17 @@ public class SmartStackTraceParser } Throwable target = throwable.getTarget(); - if ( target instanceof AssertionError ) + String exception = target.getClass().getName(); + if ( target instanceof AssertionError + || "junit.framework.AssertionFailedError".equals( exception ) + || "junit.framework.ComparisonFailure".equals( exception ) ) { - result.append( " " ) - .append( throwable.getMessage() ); - } - else if ( "junit.framework.AssertionFailedError".equals( target.getClass().getName() ) - || "junit.framework.ComparisonFailure".equals( target.getClass().getName() ) ) - { - result.append( " " ); - result.append( throwable.getMessage() ); + String msg = throwable.getMessage(); + if ( isNotEmpty( msg ) ) + { + result.append( " " ) + .append( msg ); + } } else { @@ -156,16 +158,16 @@ public class SmartStackTraceParser return result.toString(); } - private String getMinimalThrowableMiniMessage( Throwable throwable ) + private static String getMinimalThrowableMiniMessage( Throwable throwable ) { String name = throwable.getClass().getSimpleName(); if ( name.endsWith( "Exception" ) ) { - return StringUtils.chompLast( name, "Exception" ); + return chompLast( name, "Exception" ); } if ( name.endsWith( "Error" ) ) { - return StringUtils.chompLast( name, "Error" ); + return chompLast( name, "Error" ); } return name; } @@ -234,7 +236,6 @@ public class SmartStackTraceParser } n = n.getCause(); - } while ( n != null ); return t; @@ -280,7 +281,7 @@ public class SmartStackTraceParser while ( cause != null ) { resp += "Caused by: "; - resp += toString( cause, Arrays.asList( cause.getStackTrace() ), filter ); + resp += toString( cause, asList( cause.getStackTrace() ), filter ); cause = cause.getCause(); } return resp;