Author: bago
Date: Sun Jan 30 16:28:23 2011
New Revision: 1065316

URL: http://svn.apache.org/viewvc?rev=1065316&view=rev
Log:
Small improvement in parsing error message and in test suites so to be able to 
generate expected results when missing. Added svn-ignore for "target".

Modified:
    
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
    
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
    james/mime4j/trunk/dom/   (props changed)
    
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java

Modified: 
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java?rev=1065316&r1=1065315&r2=1065316&view=diff
==============================================================================
--- 
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
 (original)
+++ 
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
 Sun Jan 30 16:28:23 2011
@@ -76,7 +76,7 @@ public class RawField {
                                colonIdx = i;
                                break;
                        } else if (j != 0x20 && j != 0x09) {
-                               throw new MimeException("Invalid header");
+                               throw new MimeException("Invalid header. 
Unexpected char after colon: "+j);
                        } else {
                                                obsolete = true;
                                        }

Modified: 
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java?rev=1065316&r1=1065315&r2=1065316&view=diff
==============================================================================
--- 
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
 (original)
+++ 
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
 Sun Jan 30 16:28:23 2011
@@ -20,7 +20,10 @@
 package org.apache.james.mime4j.parser;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.JarURLConnection;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -69,8 +72,14 @@ public class MimeStreamParserExampleMess
         String s = url.toString();
         String prefix = s.substring(0, s.lastIndexOf('.'));
         URL xmlFileUrl = new URL(prefix + ".xml");
-        String expected = IOUtils.toString(xmlFileUrl.openStream(), 
"ISO8859-1");
-        assertEquals(expected, result);
+        try {
+               InputStream openStream = xmlFileUrl.openStream();
+                       String expected = IOUtils.toString(openStream, 
"ISO8859-1");
+               assertEquals(expected, result);
+        } catch (FileNotFoundException e) {
+               IOUtils.write(result, new 
FileOutputStream(xmlFileUrl.getPath()+".expected"));
+               fail("Expected file created.");
+        }
     }
 
     public static Test suite() throws IOException, URISyntaxException {

Propchange: james/mime4j/trunk/dom/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Jan 30 16:28:23 2011
@@ -1,3 +1,5 @@
 .settings
 .classpath
 .project
+
+target

Modified: 
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java?rev=1065316&r1=1065315&r2=1065316&view=diff
==============================================================================
--- 
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
 (original)
+++ 
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
 Sun Jan 30 16:28:23 2011
@@ -20,6 +20,8 @@
 package org.apache.james.mime4j.dom;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.JarURLConnection;
@@ -109,8 +111,13 @@ public class MessageParserTest extends T
         URL xmlFileUrl = new URL(prefix + "_decoded.xml");
         
         String result = getStructure(m, prefix, "1");
-        String expected = IOUtils.toString(xmlFileUrl.openStream(), 
"ISO8859-1");
-        assertEquals(expected, result);
+        try {
+               String expected = IOUtils.toString(xmlFileUrl.openStream(), 
"ISO8859-1");
+               assertEquals(expected, result);
+        } catch (FileNotFoundException ex) {
+               IOUtils.write(result, new 
FileOutputStream(xmlFileUrl.getPath()+".expected"));
+               fail("Expected file created.");
+        }
     }
 
     private String escape(String s) {
@@ -180,16 +187,25 @@ public class MessageParserTest extends T
                     charset = "ISO8859-1";
                 }
 
-                String s1 = IOUtils.toString(expectedUrl.openStream(), 
charset);
                 String s2 = IOUtils.toString(((TextBody) b).getReader());
-                assertEquals(f.getName(), s1, s2);
+                try {
+                       String s1 = IOUtils.toString(expectedUrl.openStream(), 
charset);
+                       assertEquals(f.getName(), s1, s2);
+                } catch (FileNotFoundException ex) {
+                       IOUtils.write(s2, new 
FileOutputStream(expectedUrl.getPath()+".expected"));
+                       fail("Expected file created.");
+                }
             } else {
-                assertEqualsBinary(f.getName(), expectedUrl.openStream(),
+               try {
+                       assertEqualsBinary(f.getName(), 
expectedUrl.openStream(),
                         ((BinaryBody) b).getInputStream());
+               } catch (FileNotFoundException ex) {
+                       IOUtils.copy(((BinaryBody) b).getInputStream(), new 
FileOutputStream(expectedUrl.getPath()+".expected"));
+                       fail("Expected file created.");
+               }
             }
         }
         
-        
         if (e instanceof MessageImpl) {
             sb.append("</message>\r\n");
         } else {


Reply via email to