Repository: maven-surefire
Updated Branches:
  refs/heads/master 53a40eef4 -> 8ce08a7f5


[SUREFIRE-1112] Remove uneccessary newlines in console output for test results 
with no error


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/8ce08a7f
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/8ce08a7f
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/8ce08a7f

Branch: refs/heads/master
Commit: 8ce08a7f552cba06ceec6383b7636b4e77d1e0b9
Parents: 53a40ee
Author: tibordigana <tibo...@lycos.com>
Authored: Fri Nov 7 01:22:27 2014 +0100
Committer: tibordigana <tibo...@lycos.com>
Committed: Fri Nov 7 01:22:27 2014 +0100

----------------------------------------------------------------------
 .../surefire/report/DefaultReporterFactory.java | 89 ++++++++++----------
 .../report/DefaultReporterFactoryTest.java      |  8 +-
 2 files changed, 49 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8ce08a7f/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 dfbec97..35ef7e4 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
@@ -56,13 +56,13 @@ public class DefaultReporterFactory
         Collections.synchronizedList( new ArrayList<TestSetRunListener>() );
 
     // from "<testclass>.<testmethod>" -> statistics about all the runs for 
flaky tests
-    private Map<String, List<TestMethodStats>> flakyTests = null;
+    private Map<String, List<TestMethodStats>> flakyTests;
 
     // from "<testclass>.<testmethod>" -> statistics about all the runs for 
failed tests
-    private Map<String, List<TestMethodStats>> failedTests = null;
+    private Map<String, List<TestMethodStats>> failedTests;
 
     // from "<testclass>.<testmethod>" -> statistics about all the runs for 
error tests
-    private Map<String, List<TestMethodStats>> errorTests = null;
+    private Map<String, List<TestMethodStats>> errorTests;
 
     public DefaultReporterFactory( StartupReportConfiguration 
reportConfiguration )
     {
@@ -139,9 +139,13 @@ public class DefaultReporterFactory
             logger.info( "Results :" );
             logger.info( "" );
         }
-        printTestFailures( logger, TestResultType.failure );
-        printTestFailures( logger, TestResultType.error );
-        printTestFailures( logger, TestResultType.flake );
+        boolean printedFailures = printTestFailures( logger, 
TestResultType.failure );
+        printedFailures |= printTestFailures( logger, TestResultType.error );
+        printedFailures |= printTestFailures( logger, TestResultType.flake );
+        if ( printedFailures )
+        {
+            logger.info( "" );
+        }
         logger.info( globalStats.getSummary() );
         logger.info( "" );
     }
@@ -168,7 +172,7 @@ public class DefaultReporterFactory
     // Use default visibility for testing
     static TestResultType getTestResultType( List<ReportEntryType> 
reportEntryList, int rerunFailingTestsCount  )
     {
-        if ( reportEntryList == null || reportEntryList.size() == 0 )
+        if ( reportEntryList == null || reportEntryList.isEmpty() )
         {
             return TestResultType.unknown;
         }
@@ -202,13 +206,9 @@ public class DefaultReporterFactory
                 {
                     return TestResultType.error;
                 }
-                else if ( seenFailure )
-                {
-                    return TestResultType.failure;
-                }
                 else
                 {
-                    return TestResultType.skipped;
+                    return TestResultType.failure;
                 }
             }
         }
@@ -313,61 +313,62 @@ public class DefaultReporterFactory
      *
      * @param logger the logger used to log information
      * @param type   the type of results to be printed, could be error, 
failure or flake
+     * @return {@code true} if printed some lines
      */
     // Use default visibility for testing
-    void printTestFailures( DefaultDirectConsoleReporter logger, 
TestResultType type )
+    boolean printTestFailures( DefaultDirectConsoleReporter logger, 
TestResultType type )
     {
-        Map<String, List<TestMethodStats>> testStats;
-        if ( type == TestResultType.failure )
+        boolean printed = false;
+        final Map<String, List<TestMethodStats>> testStats;
+        switch ( type )
         {
-            testStats = failedTests;
-        }
-        else if ( type == TestResultType.error )
-        {
-            testStats = errorTests;
-        }
-        else if ( type == TestResultType.flake )
-        {
-            testStats = flakyTests;
-        }
-        else
-        {
-            logger.info( "" );
-            return;
+            case failure:
+                testStats = failedTests;
+                break;
+            case error:
+                testStats = errorTests;
+                break;
+            case flake:
+                testStats = flakyTests;
+                break;
+            default:
+                return printed;
         }
 
-        if ( testStats.size() > 0 )
+        if ( !testStats.isEmpty() )
         {
             logger.info( type.getLogPrefix() );
+            printed = true;
         }
 
         for ( Map.Entry<String, List<TestMethodStats>> entry : 
testStats.entrySet() )
         {
+            printed = true;
             List<TestMethodStats> testMethodStats = entry.getValue();
             if ( testMethodStats.size() == 1 )
             {
                 // No rerun, follow the original output format
                 logger.info( "  " + testMethodStats.get( 0 
).getStackTraceWriter().smartTrimmedStackTrace() );
-                continue;
             }
-
-            logger.info( entry.getKey() );
-
-            for ( int i = 0; i < testMethodStats.size(); i++ )
+            else
             {
-                StackTraceWriter failureStackTrace = testMethodStats.get( i 
).getStackTraceWriter();
-                if ( failureStackTrace == null )
-                {
-                    logger.info( "  Run " + ( i + 1 ) + ": PASS" );
-                }
-                else
+                logger.info( entry.getKey() );
+                for ( int i = 0; i < testMethodStats.size(); i++ )
                 {
-                    logger.info( "  Run " + ( i + 1 ) + ": " + 
failureStackTrace.smartTrimmedStackTrace() );
+                    StackTraceWriter failureStackTrace = testMethodStats.get( 
i ).getStackTraceWriter();
+                    if ( failureStackTrace == null )
+                    {
+                        logger.info( "  Run " + ( i + 1 ) + ": PASS" );
+                    }
+                    else
+                    {
+                        logger.info( "  Run " + ( i + 1 ) + ": " + 
failureStackTrace.smartTrimmedStackTrace() );
+                    }
                 }
+                logger.info( "" );
             }
-            logger.info( "" );
         }
-        logger.info( "" );
+        return printed;
     }
 
     // Describe the result of a given test

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8ce08a7f/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
index fe8b7c1..c71611d 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
@@ -119,19 +119,19 @@ public class DefaultReporterFactoryTest
         String[] expectedFlakeOutput =
             { "Flaked tests: ", TEST_FOUR, "  Run 1: " + ASSERTION_FAIL, "  
Run 2: PASS", "", TEST_ONE,
                 "  Run 1: " + ERROR, "  Run 2: " + ASSERTION_FAIL, "  Run 3: 
PASS", "", TEST_TWO, "  Run 1: " + ERROR,
-                "  Run 2: PASS", "", "" };
+                "  Run 2: PASS", "" };
         assertEquals( Arrays.asList( expectedFlakeOutput ), 
reporter.getMessages() );
 
         reporter = new DummyTestReporter();
         factory.printTestFailures( reporter, 
DefaultReporterFactory.TestResultType.error );
         String[] expectedFailureOutput =
-            { "Tests in error: ", TEST_THREE, "  Run 1: " + ASSERTION_FAIL, "  
Run 2: " + ERROR, "  Run 3: " + ERROR, "",
-                "" };
+            { "Tests in error: ", TEST_THREE, "  Run 1: " + ASSERTION_FAIL, "  
Run 2: " + ERROR, "  Run 3: " + ERROR, ""
+            };
         assertEquals( Arrays.asList( expectedFailureOutput ), 
reporter.getMessages() );
 
         reporter = new DummyTestReporter();
         factory.printTestFailures( reporter, 
DefaultReporterFactory.TestResultType.failure );
-        String[] expectedErrorOutput = { "" };
+        String[] expectedErrorOutput = { };
         assertEquals( Arrays.asList( expectedErrorOutput ), 
reporter.getMessages() );
     }
 

Reply via email to