Commit b7fcdb96 authored by Andrey Vokin's avatar Andrey Vokin Committed by intellij-monorepo-bot
Browse files

[junit] do not try to extract short test name from junit test names in case of...

[junit] do not try to extract short test name from junit test names in case of Cucumber run with JUnit

IDEA-153338 Cucumber for Java plugin > Scenario names are not displayed in test results

GitOrigin-RevId: f253035312cc253781db0fd77eb64c439d71cd19
parent 786016fe
Showing with 85 additions and 22 deletions
+85 -22
......@@ -44,6 +44,7 @@ public class JUnit4TestListener extends RunListener {
private Description myCurrentTest;
private final Map myWaitingQueue = new LinkedHashMap();
private static final JUnitNodeNamesManager NODE_NAMES_MANAGER = getNodeNamesManager();
public JUnit4TestListener() {
......@@ -61,16 +62,10 @@ public class JUnit4TestListener extends RunListener {
public void testRunStarted(Description description) throws Exception {
if (myRootName != null && !myRootName.startsWith("[")) {
int lastPointIdx = myRootName.lastIndexOf('.');
String name = myRootName;
String comment = null;
if (lastPointIdx >= 0) {
name = myRootName.substring(lastPointIdx + 1);
comment = myRootName.substring(0, lastPointIdx);
}
JUnitNodeNamesManager.TestNodePresentation rootNodePresentation = NODE_NAMES_MANAGER.getRootNodePresentation(myRootName);
myPrintStream.println("##teamcity[rootName name = \'" + escapeName(name) +
(comment != null ? ("\' comment = \'" + escapeName(comment)) : "") + "\'" +
myPrintStream.println("##teamcity[rootName name = \'" + escapeName(rootNodePresentation.getName()) +
(rootNodePresentation.getComment() != null ? ("\' comment = \'" + escapeName(rootNodePresentation.getComment())) : "") + "\'" +
" location = \'java:suite://" + escapeName(myRootName) +
"\']");
myRootName = getShortName(myRootName);
......@@ -544,19 +539,14 @@ public class JUnit4TestListener extends RunListener {
}
private static String getShortName(String fqName, boolean splitBySlash) {
if (fqName == null) return null;
final int idx = fqName.indexOf("[");
if (idx == 0) {
//param name
return fqName;
}
String fqNameWithoutParams = idx > 0 && fqName.endsWith("]") ? fqName.substring(0, idx) : fqName;
int classEnd = splitBySlash ? fqNameWithoutParams.indexOf('/') : -1;
if (classEnd >= 0) {
return fqName.substring(classEnd + 1);
}
return NODE_NAMES_MANAGER.getNodeName(fqName, splitBySlash);
}
int dotInClassFQNIdx = fqNameWithoutParams.lastIndexOf('.');
return dotInClassFQNIdx > -1 ? fqName.substring(dotInClassFQNIdx + 1) : fqName;
private static JUnitNodeNamesManager getNodeNamesManager() {
String junitNodeNamesManagerClassName = System.getProperty(JUnitNodeNamesManager.JUNIT_NODE_NAMES_MANAGER_ARGUMENT);
if (JUnitNodeNamesManager.TEXT_NODE_NAMES_MANAGER_NAME.equals(junitNodeNamesManagerClassName)) {
return JUnitNodeNamesManager.SIMPLE_NODE_NAMES_MANAGER;
}
return JUnitNodeNamesManager.JAVA_NODE_NAMES_MANAGER;
}
}
\ No newline at end of file
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.junit4;
public interface JUnitNodeNamesManager {
String JUNIT_NODE_NAMES_MANAGER_ARGUMENT = "nodeNamesHandler";
String TEXT_NODE_NAMES_MANAGER_NAME = "AsText";
TestNodePresentation getRootNodePresentation(String fullName);
String getNodeName(String fqName, boolean splitBySlash);
JUnitNodeNamesManager JAVA_NODE_NAMES_MANAGER = new JUnitNodeNamesManager() {
public TestNodePresentation getRootNodePresentation(String fullName) {
if (fullName == null) {
return new TestNodePresentation(null, null);
}
int lastPointIdx = fullName.lastIndexOf('.');
String name = fullName;
String comment = null;
if (lastPointIdx >= 0) {
name = fullName.substring(lastPointIdx + 1);
comment = fullName.substring(0, lastPointIdx);
}
return new TestNodePresentation(name, comment);
}
public String getNodeName(String fqName, boolean splitBySlash) {
if (fqName == null) return null;
final int idx = fqName.indexOf("[");
if (idx == 0) {
//param name
return fqName;
}
String fqNameWithoutParams = idx > 0 && fqName.endsWith("]") ? fqName.substring(0, idx) : fqName;
int classEnd = splitBySlash ? fqNameWithoutParams.indexOf('/') : -1;
if (classEnd >= 0) {
return fqName.substring(classEnd + 1);
}
int dotInClassFQNIdx = fqNameWithoutParams.lastIndexOf('.');
return dotInClassFQNIdx > -1 ? fqName.substring(dotInClassFQNIdx + 1) : fqName;
}
};
JUnitNodeNamesManager SIMPLE_NODE_NAMES_MANAGER = new JUnitNodeNamesManager() {
public JUnitNodeNamesManager.TestNodePresentation getRootNodePresentation(String fullName) {
return new JUnitNodeNamesManager.TestNodePresentation(fullName, null);
}
public String getNodeName(String fqName, boolean splitBySlash) {
return fqName;
}
};
class TestNodePresentation {
private final String myName;
private final String myComment;
public TestNodePresentation(String name, String comment) {
myName = name;
myComment = comment;
}
public String getName() {
return myName;
}
public String getComment() {
return myComment;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment