Browse Source

Don't die if Test.getName returns null, PR 29407

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278001 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
e81aadf85e
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

+ 8
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2004 The Apache Software Foundation
* Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,9 @@ import org.w3c.dom.Text;

public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants {

/** constant for unnnamed testsuites/cases */
private static final String UNKNOWN = "unknown";

private static DocumentBuilder getDocumentBuilder() {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();
@@ -103,7 +106,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
public void startTestSuite(JUnitTest suite) {
doc = getDocumentBuilder().newDocument();
rootElement = doc.createElement(TESTSUITE);
rootElement.setAttribute(ATTR_NAME, suite.getName());
String n = suite.getName();
rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n);

//add the timestamp
final String timestamp = DateUtils.format(new Date(),
@@ -190,8 +194,9 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
Element currentTest = null;
if (!failedTests.containsKey(test)) {
currentTest = doc.createElement(TESTCASE);
String n = JUnitVersionHelper.getTestCaseName(test);
currentTest.setAttribute(ATTR_NAME,
JUnitVersionHelper.getTestCaseName(test));
n == null ? UNKNOWN : n);
// a TestSuite can contain Tests from multiple classes,
// even tests with the same name - disambiguate them.
currentTest.setAttribute(ATTR_CLASSNAME,


Loading…
Cancel
Save