On 12 March 2012 16:54, Christian Grobmeier <[email protected]> wrote:
> On Mon, Mar 12, 2012 at 5:48 PM, sebb <[email protected]> wrote:
>> On 12 March 2012 08:45,  <[email protected]> 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: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
>
>
> --
> http://www.grobmeier.de
> https://www.timeandbill.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to