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

This commit is contained in:
Anna.Kozlova
2016-07-20 20:42:49 +02:00
parent ad86a5171d
commit f426e0eeb8
2 changed files with 8 additions and 3 deletions
@@ -34,7 +34,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
@Test
public void testEmptySuite() throws Exception {
doTest(Description.createSuiteDescription("empty suite"), "##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeNode name='empty suite' locationHint='java:test://empty suite.empty suite']\n" +
"##teamcity[treeEnded]\n");
}
@@ -306,6 +306,12 @@ public class JUnit4TestListener extends RunListener {
}
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);
if (methodName == null) {
methodName = JUnit4ReflectionUtil.getMethodName(description);
@@ -313,7 +319,7 @@ public class JUnit4TestListener extends RunListener {
methodName = getShortName(JUnit4ReflectionUtil.getClassName(description)) + "." + methodName;
}
if (methodName == null && description.getChildren().isEmpty()) {
if (!acceptNull && methodName == null && description.getChildren().isEmpty()) {
methodName = getShortName(description.getDisplayName());
}
@@ -463,7 +469,7 @@ public class JUnit4TestListener extends RunListener {
String className = JUnit4ReflectionUtil.getClassName(description);
if (description.isTest()) {
final String methodName = getFullMethodName((Description)description, parent);
final String methodName = getFullMethodName((Description)description, parent, true);
if (methodName != null ) {
if (isWarning(methodName, className) && parent != null) {
className = JUnit4ReflectionUtil.getClassName(parent);