diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java index 1579c3479..50a678915 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java @@ -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,