You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/10/01 11:58:46 UTC
[maven-surefire] 01/02: Resolve duplicated code in Adapter
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch SUREFIRE-1584
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 573e1ac86940183c6a679ca6b2b54ebbe122c223
Author: Col-E <mc...@gmu.edu>
AuthorDate: Tue Oct 1 07:50:49 2019 -0400
Resolve duplicated code in Adapter
---
.../surefire/junitplatform/RunListenerAdapter.java | 68 +++++++++-------------
1 file changed, 27 insertions(+), 41 deletions(-)
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
index 1205028..aeeb7ec 100644
--- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
@@ -214,6 +214,16 @@ final class RunListenerAdapter
return new PojoStackTraceWriter( realClassName, realMethodName, throwable );
}
+ private String[] toClassMethodName( TestIdentifier testIdentifier )
+ {
+ return toClassMethodName( testIdentifier, true );
+ }
+
+ public String[] toClassMethodNameWithoutPlan( TestIdentifier testIdentifier )
+ {
+ return toClassMethodName( testIdentifier, false );
+ }
+
/**
* <ul>
* <li>[0] class name - used in stacktrace parser</li>
@@ -223,9 +233,11 @@ final class RunListenerAdapter
* </ul>
*
* @param testIdentifier a class or method
+ * @param usePlan {@code true} for using the test-plan to fetch sources.
+ * {@code false} to rely on fallbacks.
* @return 4 elements string array
*/
- private String[] toClassMethodName( TestIdentifier testIdentifier )
+ private String[] toClassMethodName( TestIdentifier testIdentifier, boolean usePlan )
{
Optional<TestSource> testSource = testIdentifier.getSource();
String display = testIdentifier.getDisplayName();
@@ -235,45 +247,19 @@ final class RunListenerAdapter
MethodSource methodSource = testSource.map( MethodSource.class::cast ).get();
String realClassName = methodSource.getClassName();
- String[] source = testPlan.getParent( testIdentifier )
- .map( this::toClassMethodName )
- .map( s -> new String[] { s[0], s[1] } )
- .orElse( new String[] { realClassName, realClassName } );
-
- String methodName = methodSource.getMethodName();
- boolean useMethod = display.equals( methodName ) || display.equals( methodName + "()" );
- String resolvedMethodName = useMethod ? methodName : display;
-
- return new String[] { source[0], source[1], methodName, resolvedMethodName };
- }
- else if ( testSource.filter( ClassSource.class::isInstance ).isPresent() )
- {
- ClassSource classSource = testSource.map( ClassSource.class::cast ).get();
- String className = classSource.getClassName();
- String simpleClassName = className.substring( 1 + className.lastIndexOf( '.' ) );
- String source = display.equals( simpleClassName ) ? className : display;
- return new String[] { className, source, null, null };
- }
- else
- {
- String source = testPlan.getParent( testIdentifier )
- .map( TestIdentifier::getDisplayName )
- .orElse( display );
- return new String[] { source, source, display, display };
- }
- }
-
- public String[] toClassMethodNameWithoutPlan( TestIdentifier testIdentifier )
- {
- Optional<TestSource> testSource = testIdentifier.getSource();
- String display = testIdentifier.getDisplayName();
-
- if ( testSource.filter( MethodSource.class::isInstance ).isPresent() )
- {
- MethodSource methodSource = testSource.map( MethodSource.class::cast ).get();
- String realClassName = methodSource.getClassName();
+ String[] source;
+ if ( usePlan )
+ {
+ source = testPlan.getParent( testIdentifier )
+ .map( this::toClassMethodName )
+ .map( s -> new String[] { s[0], s[1] } )
+ .orElse( new String[] { realClassName, realClassName } );
+ }
+ else
+ {
+ source = new String[] {realClassName, realClassName};
+ }
- String[] source = new String[] {realClassName, realClassName};
String methodName = methodSource.getMethodName();
boolean useMethod = display.equals( methodName ) || display.equals( methodName + "()" );
String resolvedMethodName = useMethod ? methodName : display;
@@ -290,8 +276,8 @@ final class RunListenerAdapter
}
else
{
- String source = testPlan == null ? display : testPlan.getParent( testIdentifier ).map(
- TestIdentifier::getDisplayName ).orElse( display );
+ String source = !usePlan ? display : testPlan.getParent( testIdentifier )
+ .map( TestIdentifier::getDisplayName ).orElse( display );
return new String[] {source, source, display, display};
}
}