You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/08/11 11:36:01 UTC

git commit: o Fix test that failed with some charsets

Updated Branches:
  refs/heads/master 9db8ce813 -> 00e861894


o Fix test that failed with some charsets


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/00e86189
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/00e86189
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/00e86189

Branch: refs/heads/master
Commit: 00e8618942b9b3b96b1cd225c7e0b4c8c8a63f6b
Parents: 9db8ce8
Author: Andreas Gudian <ag...@apache.org>
Authored: Sun Aug 11 11:35:46 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Sun Aug 11 11:35:46 2013 +0200

----------------------------------------------------------------------
 .../report/StatelessXMLReporterTest.java        | 44 ++++++++++++++++----
 1 file changed, 37 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/00e86189/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
index 8ed78c2..c0e3951 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 
 import junit.framework.AssertionFailedError;
@@ -48,6 +49,8 @@ public class StatelessXMLReporterTest
 
     private TestSetStats stats;
 
+    private File expectedReportFile;
+
     protected void setUp()
         throws Exception
     {
@@ -57,6 +60,17 @@ public class StatelessXMLReporterTest
         stats = new TestSetStats( false, true );
     }
 
+    @Override protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+
+        if ( expectedReportFile != null )
+        {
+            expectedReportFile.delete();
+        }
+    }
+
     public void testFileNameWithoutSuffix()
     {
         File reportDir = new File( "." );
@@ -67,11 +81,9 @@ public class StatelessXMLReporterTest
         stats.testSucceeded( testSetReportEntry );
         reporter.testSetCompleted( testSetReportEntry, stats );
 
-        File expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
+        expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
         assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
                     expectedReportFile.exists() );
-        //noinspection ResultOfMethodCallIgnored
-        expectedReportFile.delete();
     }
 
 
@@ -84,15 +96,27 @@ public class StatelessXMLReporterTest
         reportEntry = new SimpleReportEntry( this.getClass().getName(), testName, 12 );
         WrappedReportEntry testSetReportEntry =
             new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
-        File expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
+        expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
 
         stats.testSucceeded( testSetReportEntry );
         StackTraceWriter stackTraceWriter = new DeserializedStacktraceWriter( "A fud msg", "trimmed", "fail at foo" );
         Utf8RecodingDeferredFileOutputStream stdOut = new Utf8RecodingDeferredFileOutputStream( "fds" );
         byte[] stdOutBytes = "st]]>d-o\u00DCt<null>!\u0020\u0000\u001F".getBytes();
         stdOut.write( stdOutBytes, 0, stdOutBytes.length );
+
         Utf8RecodingDeferredFileOutputStream stdErr = new Utf8RecodingDeferredFileOutputStream( "fds" );
-        byte[] stdErrBytes = "std-örr?&-&amp;&#163;\u0020\u0000\u001F".getBytes();
+
+        String stdErrPrefix;
+        if ( defaultCharsetSupportsSpecialChar() )
+        {
+            stdErrPrefix = "std-\u0115rr";
+        }
+        else
+        {
+            stdErrPrefix = "std-err";
+        }
+
+        byte[] stdErrBytes = (stdErrPrefix + "?&-&amp;&#163;\u0020\u0000\u001F").getBytes();
         stdErr.write( stdErrBytes, 0, stdErrBytes.length );
         WrappedReportEntry t2 =
             new WrappedReportEntry( new SimpleReportEntry( Inner.class.getName(), testName2, stackTraceWriter, 13 ),
@@ -127,9 +151,15 @@ public class StatelessXMLReporterTest
         assertEquals( "A fud msg", errorNode.getAttribute( "message" ) );
         assertEquals( "fail at foo", errorNode.getAttribute( "type" ) );
         assertEquals( "st]]>d-o\u00DCt<null>! &amp#0;&amp#31;", tcb.getChild( "system-out" ).getValue() );
-        assertEquals( "std-örr?&-&amp;&#163; &amp#0;&amp#31;", tcb.getChild( "system-err" ).getValue() );
 
-        expectedReportFile.delete();
+
+        assertEquals( stdErrPrefix + "?&-&amp;&#163; &amp#0;&amp#31;", tcb.getChild( "system-err" ).getValue() );
+    }
+
+    private boolean defaultCharsetSupportsSpecialChar()
+    {
+        // some charsets are not able to deal with \u0115 on both ways of the conversion
+        return "\u0115".equals( new String( "\u0115".getBytes() ) );
     }
 
     class Inner