Commit aa81e508 authored by Anna.Kozlova's avatar Anna.Kozlova
Browse files

junit: reject tests without method name during building of a tree (IDEA-158727)

(cherry picked from commit f426e0ee)
parent 73d43411
Showing with 8 additions and 3 deletions
+8 -3
...@@ -34,7 +34,6 @@ public class JUnitTreeByDescriptionHierarchyTest { ...@@ -34,7 +34,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
@Test @Test
public void testEmptySuite() throws Exception { public void testEmptySuite() throws Exception {
doTest(Description.createSuiteDescription("empty suite"), "##teamcity[enteredTheMatrix]\n" + doTest(Description.createSuiteDescription("empty suite"), "##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeNode name='empty suite' locationHint='java:test://empty suite.empty suite']\n" +
"##teamcity[treeEnded]\n"); "##teamcity[treeEnded]\n");
} }
......
...@@ -306,6 +306,12 @@ public class JUnit4TestListener extends RunListener { ...@@ -306,6 +306,12 @@ public class JUnit4TestListener extends RunListener {
} }
private String getFullMethodName(Description description, Description parent) { private String getFullMethodName(Description description, Description parent) {
return getFullMethodName(description, parent, false);
}
private String getFullMethodName(Description description,
Description parent,
boolean acceptNull) {
String methodName = (String)myMethodNames.get(description); String methodName = (String)myMethodNames.get(description);
if (methodName == null) { if (methodName == null) {
methodName = JUnit4ReflectionUtil.getMethodName(description); methodName = JUnit4ReflectionUtil.getMethodName(description);
...@@ -313,7 +319,7 @@ public class JUnit4TestListener extends RunListener { ...@@ -313,7 +319,7 @@ public class JUnit4TestListener extends RunListener {
methodName = getShortName(JUnit4ReflectionUtil.getClassName(description)) + "." + methodName; methodName = getShortName(JUnit4ReflectionUtil.getClassName(description)) + "." + methodName;
} }
if (methodName == null && description.getChildren().isEmpty()) { if (!acceptNull && methodName == null && description.getChildren().isEmpty()) {
methodName = getShortName(description.getDisplayName()); methodName = getShortName(description.getDisplayName());
} }
...@@ -463,7 +469,7 @@ public class JUnit4TestListener extends RunListener { ...@@ -463,7 +469,7 @@ public class JUnit4TestListener extends RunListener {
String className = JUnit4ReflectionUtil.getClassName(description); String className = JUnit4ReflectionUtil.getClassName(description);
if (description.isTest()) { if (description.isTest()) {
final String methodName = getFullMethodName((Description)description, parent); final String methodName = getFullMethodName((Description)description, parent, true);
if (methodName != null ) { if (methodName != null ) {
if (isWarning(methodName, className) && parent != null) { if (isWarning(methodName, className) && parent != null) {
className = JUnit4ReflectionUtil.getClassName(parent); className = JUnit4ReflectionUtil.getClassName(parent);
......
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