Repository: maven-surefire
Updated Branches:
  refs/heads/master ce6264f2d -> d7bf6ce49 (forced update)


[SUREFIRE-1305] surefire fails on parallel tests when newline character is in 
test description


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

Branch: refs/heads/master
Commit: d7bf6ce49043a3301494fdd26c538afad4e1938d
Parents: 569e754
Author: Tibor17 <tibo...@lycos.com>
Authored: Sat Dec 3 22:26:42 2016 +0100
Committer: Tibor17 <tibo...@lycos.com>
Committed: Sat Dec 3 22:26:42 2016 +0100

----------------------------------------------------------------------
 .../util/internal/TestClassMethodNameUtils.java |  1 +
 .../common/junit4/JUnit4RunListener.java        | 25 ++++----------------
 .../common/junit4/JUnit4StackTraceWriter.java   |  8 +++----
 3 files changed, 9 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d7bf6ce4/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/TestClassMethodNameUtils.java
----------------------------------------------------------------------
diff --git 
a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/TestClassMethodNameUtils.java
 
b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/TestClassMethodNameUtils.java
new file mode 100644
index 0000000..29b4f51
--- /dev/null
+++ 
b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/TestClassMethodNameUtils.java
@@ -0,0 +1 @@
+package org.apache.maven.surefire.util.internal;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * JUnit Description parser.
 * Used by JUnit Version lower than 4.
 7.
 *
 * @author <a href="mailto:tibordig...@apache.org";>Tibor Digana (tibor17)</a>
 * @since 2.19.2
 */
public final class TestClassMethodNameUtils
{
    private static final Pattern METHOD_CLASS_PATTERN = Pattern.compile( 
"([\\s\\S]*)\\((.*)\\)" );

    private TestClassMethodNameUtils()
    {
        throw new IllegalStateException( "no instantiable constructor" );
    }

    public static String extractClassName( String displayName )
    {
        Matcher m = METHOD_CLASS_PATTERN.matcher( displayName );
        return m.matches() ? m.group( 2 ) : displayName;
    }

    public static String extractMethodName( String displayName )
    {
        int i = displayName.indexOf( "(" );
        return i >= 0 ? displayName.substring( 0, i ) : displayName;
    }
}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d7bf6ce4/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
----------------------------------------------------------------------
diff --git 
a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
 
b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
index dd004fa..1d365cf 100644
--- 
a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
+++ 
b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
@@ -28,14 +28,13 @@ import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import static 
org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.isFailureInsideJUnitItself;
 import static 
org.apache.maven.surefire.common.junit4.JUnit4Reflector.getAnnotatedIgnoreValue;
 import static org.apache.maven.surefire.report.SimpleReportEntry.assumption;
 import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
 import static org.apache.maven.surefire.report.SimpleReportEntry.withException;
+import static 
org.apache.maven.surefire.util.internal.TestClassMethodNameUtils.extractClassName;
+import static 
org.apache.maven.surefire.util.internal.TestClassMethodNameUtils.extractMethodName;
 
 /**
  * RunListener for JUnit4, delegates to our own RunListener
@@ -44,8 +43,6 @@ import static 
org.apache.maven.surefire.report.SimpleReportEntry.withException;
 public class JUnit4RunListener
     extends org.junit.runner.notification.RunListener
 {
-    private static final Pattern METHOD_CLASS_PATTERN = Pattern.compile( 
"([\\s\\S]*)\\((.*)\\)" );
-
     protected final RunListener reporter;
 
     /**
@@ -183,26 +180,12 @@ public class JUnit4RunListener
 
     protected String extractDescriptionClassName( Description description )
     {
-        return extractClassName( description );
+        return extractClassName( description.getDisplayName() );
     }
 
     protected String extractDescriptionMethodName( Description description )
     {
-        return extractMethodName( description );
-    }
-
-    public static String extractClassName( Description description )
-    {
-        String displayName = description.getDisplayName();
-        Matcher m = METHOD_CLASS_PATTERN.matcher( displayName );
-        return m.matches() ? m.group( 2 ) : displayName;
-    }
-
-    public static String extractMethodName( Description description )
-    {
-        String displayName = description.getDisplayName();
-        int i = displayName.indexOf( "(" );
-        return i >= 0 ? displayName.substring( 0, i ) : displayName;
+        return extractMethodName( description.getDisplayName() );
     }
 
     public static void rethrowAnyTestMechanismFailures( Result run )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d7bf6ce4/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4StackTraceWriter.java
----------------------------------------------------------------------
diff --git 
a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4StackTraceWriter.java
 
b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4StackTraceWriter.java
index a4690ca..33f499e 100644
--- 
a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4StackTraceWriter.java
+++ 
b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4StackTraceWriter.java
@@ -24,8 +24,8 @@ import org.apache.maven.surefire.report.SmartStackTraceParser;
 import org.apache.maven.surefire.report.StackTraceWriter;
 import org.junit.runner.notification.Failure;
 
-import static 
org.apache.maven.surefire.common.junit4.JUnit4RunListener.extractClassName;
-import static 
org.apache.maven.surefire.common.junit4.JUnit4RunListener.extractMethodName;
+import static 
org.apache.maven.surefire.util.internal.TestClassMethodNameUtils.extractClassName;
+import static 
org.apache.maven.surefire.util.internal.TestClassMethodNameUtils.extractMethodName;
 import static 
org.apache.maven.surefire.report.SmartStackTraceParser.stackTraceWithFocusOnClassAsString;
 
 /**
@@ -79,12 +79,12 @@ public class JUnit4StackTraceWriter
 
     protected String getTestClassName()
     {
-        return extractClassName( junitFailure.getDescription() );
+        return extractClassName( 
junitFailure.getDescription().getDisplayName() );
     }
 
     protected String getTestMethodName()
     {
-        return extractMethodName( junitFailure.getDescription() );
+        return extractMethodName( 
junitFailure.getDescription().getDisplayName() );
     }
 
     @SuppressWarnings( "ThrowableResultOfMethodCallIgnored" )

Reply via email to