From 938d422802e431682a866c90f7269ca2fa85f790 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Wed, 12 Dec 2018 23:04:47 +0100 Subject: [PATCH] [SUREFIRE-1614] Fix corrupted stream warning --- .../junitplatform/JUnitPlatformProvider.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java index 177adef2cb..868b369103 100644 --- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java +++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java @@ -104,22 +104,29 @@ public Iterable> getSuites() public RunResult invoke( Object forkTestSet ) throws TestSetFailedException, ReporterException { + ReporterFactory reporterFactory = parameters.getReporterFactory(); + RunListener runListener = reporterFactory.createReporter(); + + ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) runListener ); + if ( forkTestSet instanceof TestsToRun ) { - return invokeAllTests( (TestsToRun) forkTestSet ); + invokeAllTests( (TestsToRun) forkTestSet, runListener ); } else if ( forkTestSet instanceof Class ) { - return invokeAllTests( TestsToRun.fromClass( (Class) forkTestSet ) ); + invokeAllTests( TestsToRun.fromClass( (Class) forkTestSet ), runListener ); } else if ( forkTestSet == null ) { - return invokeAllTests( scanClasspath() ); + invokeAllTests( scanClasspath(), runListener ); } else { throw new IllegalArgumentException( "Unexpected value of forkTestSet: " + forkTestSet ); } + + return reporterFactory.close(); } private TestsToRun scanClasspath() @@ -130,22 +137,10 @@ private TestsToRun scanClasspath() return parameters.getRunOrderCalculator().orderTestClasses( scannedClasses ); } - private RunResult invokeAllTests( TestsToRun testsToRun ) + private void invokeAllTests( TestsToRun testsToRun, RunListener runListener ) { - RunResult runResult; - ReporterFactory reporterFactory = parameters.getReporterFactory(); - try - { - RunListener runListener = reporterFactory.createReporter(); - ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) runListener ); - LauncherDiscoveryRequest discoveryRequest = buildLauncherDiscoveryRequest( testsToRun ); - launcher.execute( discoveryRequest, new RunListenerAdapter( runListener ) ); - } - finally - { - runResult = reporterFactory.close(); - } - return runResult; + LauncherDiscoveryRequest discoveryRequest = buildLauncherDiscoveryRequest( testsToRun ); + launcher.execute( discoveryRequest, new RunListenerAdapter( runListener ) ); } private LauncherDiscoveryRequest buildLauncherDiscoveryRequest( TestsToRun testsToRun )