commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1299580 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
Date Mon, 12 Mar 2012 17:36:23 GMT
On 12 March 2012 16:54, Christian Grobmeier <grobmeier@gmail.com> wrote:
> On Mon, Mar 12, 2012 at 5:48 PM, sebb <sebbaz@gmail.com> wrote:
>> On 12 March 2012 08:45,  <ebourg@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


Mime
View raw message