You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by ca...@apache.org on 2005/11/23 07:38:02 UTC
svn commit: r348387 - in /maven/surefire/trunk: surefire-booter/
surefire/src/main/java/org/codehaus/surefire/report/
surefire/src/test/java/org/codehaus/surefire/report/
Author: carlos
Date: Tue Nov 22 22:37:59 2005
New Revision: 348387
URL: http://svn.apache.org/viewcvs?rev=348387&view=rev
Log:
XMLReporter crashes in testFailed and testError when report.getThrowable().getMessage() is null
PR: SUREFIRE-11
Added:
maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/
maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java (with props)
Modified:
maven/surefire/trunk/surefire-booter/pom.xml
maven/surefire/trunk/surefire/src/main/java/org/codehaus/surefire/report/XMLReporter.java
Modified: maven/surefire/trunk/surefire-booter/pom.xml
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/pom.xml?rev=348387&r1=348386&r2=348387&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/pom.xml (original)
+++ maven/surefire/trunk/surefire-booter/pom.xml Tue Nov 22 22:37:59 2005
@@ -12,7 +12,7 @@
<dependency>
<groupId>surefire</groupId>
<artifactId>surefire</artifactId>
- <version>1.4</version>
+ <version>1.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Modified: maven/surefire/trunk/surefire/src/main/java/org/codehaus/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire/src/main/java/org/codehaus/surefire/report/XMLReporter.java?rev=348387&r1=348386&r2=348387&view=diff
==============================================================================
--- maven/surefire/trunk/surefire/src/main/java/org/codehaus/surefire/report/XMLReporter.java (original)
+++ maven/surefire/trunk/surefire/src/main/java/org/codehaus/surefire/report/XMLReporter.java Tue Nov 22 22:37:59 2005
@@ -23,6 +23,7 @@
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.Properties;
+import java.util.StringTokenizer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -46,6 +47,16 @@
private long batteryStartTime;
+ public void setTestCase( Xpp3Dom testCase )
+ {
+ this.testCase = testCase;
+ }
+
+ public Xpp3Dom getTestCase()
+ {
+ return testCase;
+ }
+
public void runStarting( int testCount )
{
@@ -132,29 +143,40 @@
Xpp3Dom error = createElement (testCase, "error");
- String message = StringUtils.replace(report.getThrowable().getMessage(),"<","<");
-
- message = StringUtils.replace(message,">", ">");
-
- message = StringUtils.replace( message, "\"", """ );
-
- if( message != null && !message.equals( "" ) )
- {
- error.setAttribute("message", message);
-
- error.setAttribute("type", stackTrace.substring(0, stackTrace.indexOf(":")));
- }
- else
- {
- error.setAttribute("type", stackTrace.substring(0, stackTrace.indexOf("Exception") + 9 ));
- }
+ Throwable t = report.getThrowable();
+
+ if ( t != null )
+ {
+
+ String message = t.getMessage();
+
+ if ( ( message != null ) && ( !message.equals( "" ) ) )
+ {
+
+ message = StringUtils.replace( report.getThrowable().getMessage(), "<", "<" );
+
+ message = StringUtils.replace( message, ">", ">" );
+
+ message = StringUtils.replace( message, "\"", """ );
+
+ error.setAttribute( "message", message );
+
+ error.setAttribute( "type", stackTrace.substring( 0, stackTrace.indexOf( ":" ) ) );
+ }
+
+ else
+ {
+ error.setAttribute( "type", new StringTokenizer( stackTrace ).nextToken() );
+ }
+
+ }
+
+ error.setValue( stackTrace );
error.setValue(stackTrace);
createElement(testCase, "system-out").setValue(stdOut);
- createElement(testCase, "system-err").setValue(stdErr);
-
long runTime = endTime - startTime;
testCase.setAttribute("time", elapsedTimeAsString( runTime ));
@@ -168,16 +190,33 @@
Xpp3Dom failure = createElement (testCase, "failure");
- String message = StringUtils.replace(report.getThrowable().getMessage(),"<","<");
-
- message = StringUtils.replace(message,">", ">");
-
- message = StringUtils.replace( message, "\"", """ );
+ Throwable t = report.getThrowable();
+
+ if ( t != null )
+ {
+
+ String message = t.getMessage();
+
+ if ( ( message != null ) && ( !message.equals( "" ) ) )
+ {
+
+ message = StringUtils.replace( report.getThrowable().getMessage(), "<", "<" );
- failure.setAttribute("message", message);
-
- failure.setAttribute("type", stackTrace.substring(0, stackTrace.indexOf(":")));
+ message = StringUtils.replace( message, ">", ">" );
+ message = StringUtils.replace( message, "\"", """ );
+
+ failure.setAttribute( "message", message );
+
+ failure.setAttribute( "type", stackTrace.substring( 0, stackTrace.indexOf( ":" ) ) );
+ }
+
+ else
+ {
+ failure.setAttribute( "type", new StringTokenizer( stackTrace ).nextToken() );
+ }
+ }
+
failure.setValue(getStackTrace(report));
createElement(testCase, "system-out").setValue(stdOut);
Added: maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java?rev=348387&view=auto
==============================================================================
--- maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java (added)
+++ maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java Tue Nov 22 22:37:59 2005
@@ -0,0 +1,71 @@
+package org.codehaus.surefire.report;
+
+/*
+ * Copyright 2001-2005 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+public class XMLReporterTest
+ extends TestCase
+{
+
+ private XMLReporter reporter;
+
+ private ReportEntry reportEntry;
+
+ private Xpp3Dom testCase;
+
+ private String message;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ reporter = new XMLReporter();
+ message = "junit.framework.AssertionFailedError";
+ reportEntry = new ReportEntry( this, "XMLReporterTest", message, new AssertionFailedError() );
+ reporter.setTestCase( new Xpp3Dom( "" ) );
+ }
+
+ /*
+ * Test method for 'org.codehaus.surefire.report.XMLReporter.testError(ReportEntry, String, String)'
+ */
+ public void testTestError()
+ {
+ reporter.testError( reportEntry, "", "" );
+ assertResult(reporter, message);
+ }
+
+ /*
+ * Test method for 'org.codehaus.surefire.report.XMLReporter.testFailed(ReportEntry, String, String)'
+ */
+ public void testTestFailed()
+ {
+ reporter.testError( reportEntry, "", "" );
+ assertResult(reporter, message);
+ }
+
+ private void assertResult(XMLReporter reporter, String message)
+ {
+ Xpp3Dom result = reporter.getTestCase();
+ Xpp3Dom child = result.getChild( "error" );
+ assertEquals( message, child.getAttribute( "type" ) );
+ }
+
+}
Propchange: maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/surefire/trunk/surefire/src/test/java/org/codehaus/surefire/report/XMLReporterTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"