You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2012/03/12 09:45:34 UTC

svn commit: r1299580 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Author: ebourg
Date: Mon Mar 12 08:45:34 2012
New Revision: 1299580

URL: http://svn.apache.org/viewvc?rev=1299580&view=rev
Log:
Serialization test for CSVFormat

Modified:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1299580&r1=1299579&r2=1299580&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Mar 12 08:45:34 2012
@@ -17,6 +17,11 @@
 
 package org.apache.commons.csv;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.TestCase;
 
 public class CSVFormatTest extends TestCase {
@@ -141,7 +146,28 @@ public class CSVFormatTest extends TestC
         } catch (IllegalArgumentException e) {
             // expected
         }
+    }
+
+    public void testSerialization() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
         
-        
+        ObjectOutputStream oos = new ObjectOutputStream(out);
+        oos.writeObject(CSVFormat.DEFAULT);
+        oos.flush();
+        oos.close();
+        
+        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+        CSVFormat format = (CSVFormat) in.readObject();
+        
+        assertNotNull(format);
+        assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
+        assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
+        assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
+        assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
+        assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
+        assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
+        assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
+        assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
+        assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
     }
 } 



Re: svn commit: r1299580 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Posted by sebb <se...@gmail.com>.
On 12 March 2012 16:54, Christian Grobmeier <gr...@gmail.com> wrote:
> On Mon, Mar 12, 2012 at 5:48 PM, sebb <se...@gmail.com> wrote:
>> On 12 March 2012 08:45,  <eb...@apache.org> wrote:
>>> Author: ebourg
>>> Date: Mon Mar 12 08:45:34 2012
>>> New Revision: 1299580
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1299580&view=rev
>>> Log:
>>> Serialization test for CSVFormat
>>
>> Note: this does not test serialisation between versions or JDKs as the
>> same JVM is used for writing and reading.
>
> Is it necessary to test/support this? serialization is a standard jdk
> feature which has worked like that for ages
> (serious question)

It may be a standard feature, but it is easy to get it wrong, or for
it to break when code is updated.

So yes, if the code is supposed to support full serialisation then it
must be properly tested.

This is done in Collections for example.

If serialisation is only supported for the current JVM, then the
write/read test is sufficient.

But if there is any chance that the serialised class can be passed
between different JVMs, then the existing test is insufficient.

>
>>> Modified:
>>>    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
>>>
>>> Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1299580&r1=1299579&r2=1299580&view=diff
>>> ==============================================================================
>>> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
>>> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Mar 12 08:45:34 2012
>>> @@ -17,6 +17,11 @@
>>>
>>>  package org.apache.commons.csv;
>>>
>>> +import java.io.ByteArrayInputStream;
>>> +import java.io.ByteArrayOutputStream;
>>> +import java.io.ObjectInputStream;
>>> +import java.io.ObjectOutputStream;
>>> +
>>>  import junit.framework.TestCase;
>>>
>>>  public class CSVFormatTest extends TestCase {
>>> @@ -141,7 +146,28 @@ public class CSVFormatTest extends TestC
>>>         } catch (IllegalArgumentException e) {
>>>             // expected
>>>         }
>>> +    }
>>> +
>>> +    public void testSerialization() throws Exception {
>>> +        ByteArrayOutputStream out = new ByteArrayOutputStream();
>>>
>>> -
>>> +        ObjectOutputStream oos = new ObjectOutputStream(out);
>>> +        oos.writeObject(CSVFormat.DEFAULT);
>>> +        oos.flush();
>>> +        oos.close();
>>> +
>>> +        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
>>> +        CSVFormat format = (CSVFormat) in.readObject();
>>> +
>>> +        assertNotNull(format);
>>> +        assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
>>> +        assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
>>> +        assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
>>> +        assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
>>> +        assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
>>> +        assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
>>> +        assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
>>> +        assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
>>> +        assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
>>>     }
>>>  }
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
>
> --
> http://www.grobmeier.de
> https://www.timeandbill.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1299580 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Posted by Christian Grobmeier <gr...@gmail.com>.
On Mon, Mar 12, 2012 at 5:48 PM, sebb <se...@gmail.com> wrote:
> On 12 March 2012 08:45,  <eb...@apache.org> wrote:
>> Author: ebourg
>> Date: Mon Mar 12 08:45:34 2012
>> New Revision: 1299580
>>
>> URL: http://svn.apache.org/viewvc?rev=1299580&view=rev
>> Log:
>> Serialization test for CSVFormat
>
> Note: this does not test serialisation between versions or JDKs as the
> same JVM is used for writing and reading.

Is it necessary to test/support this? serialization is a standard jdk
feature which has worked like that for ages
(serious question)


>> Modified:
>>    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
>>
>> Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1299580&r1=1299579&r2=1299580&view=diff
>> ==============================================================================
>> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
>> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Mar 12 08:45:34 2012
>> @@ -17,6 +17,11 @@
>>
>>  package org.apache.commons.csv;
>>
>> +import java.io.ByteArrayInputStream;
>> +import java.io.ByteArrayOutputStream;
>> +import java.io.ObjectInputStream;
>> +import java.io.ObjectOutputStream;
>> +
>>  import junit.framework.TestCase;
>>
>>  public class CSVFormatTest extends TestCase {
>> @@ -141,7 +146,28 @@ public class CSVFormatTest extends TestC
>>         } catch (IllegalArgumentException e) {
>>             // expected
>>         }
>> +    }
>> +
>> +    public void testSerialization() throws Exception {
>> +        ByteArrayOutputStream out = new ByteArrayOutputStream();
>>
>> -
>> +        ObjectOutputStream oos = new ObjectOutputStream(out);
>> +        oos.writeObject(CSVFormat.DEFAULT);
>> +        oos.flush();
>> +        oos.close();
>> +
>> +        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
>> +        CSVFormat format = (CSVFormat) in.readObject();
>> +
>> +        assertNotNull(format);
>> +        assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
>> +        assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
>> +        assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
>> +        assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
>> +        assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
>> +        assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
>> +        assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
>> +        assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
>> +        assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
>>     }
>>  }
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>



-- 
http://www.grobmeier.de
https://www.timeandbill.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1299580 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Posted by sebb <se...@gmail.com>.
On 12 March 2012 08:45,  <eb...@apache.org> wrote:
> Author: ebourg
> Date: Mon Mar 12 08:45:34 2012
> New Revision: 1299580
>
> URL: http://svn.apache.org/viewvc?rev=1299580&view=rev
> Log:
> Serialization test for CSVFormat

Note: this does not test serialisation between versions or JDKs as the
same JVM is used for writing and reading.

> Modified:
>    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
>
> Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1299580&r1=1299579&r2=1299580&view=diff
> ==============================================================================
> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Mon Mar 12 08:45:34 2012
> @@ -17,6 +17,11 @@
>
>  package org.apache.commons.csv;
>
> +import java.io.ByteArrayInputStream;
> +import java.io.ByteArrayOutputStream;
> +import java.io.ObjectInputStream;
> +import java.io.ObjectOutputStream;
> +
>  import junit.framework.TestCase;
>
>  public class CSVFormatTest extends TestCase {
> @@ -141,7 +146,28 @@ public class CSVFormatTest extends TestC
>         } catch (IllegalArgumentException e) {
>             // expected
>         }
> +    }
> +
> +    public void testSerialization() throws Exception {
> +        ByteArrayOutputStream out = new ByteArrayOutputStream();
>
> -
> +        ObjectOutputStream oos = new ObjectOutputStream(out);
> +        oos.writeObject(CSVFormat.DEFAULT);
> +        oos.flush();
> +        oos.close();
> +
> +        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
> +        CSVFormat format = (CSVFormat) in.readObject();
> +
> +        assertNotNull(format);
> +        assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
> +        assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
> +        assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
> +        assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
> +        assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
> +        assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
> +        assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
> +        assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
> +        assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
>     }
>  }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org