Skip to content

Commit 12b600c

Browse files
committed
Serialization test for CSVFormat
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1299580 13f79535-47bb-0310-9956-ffa450edef68
1 parent 94b9f8d commit 12b600c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
package org.apache.commons.csv;
1919

20+
import java.io.ByteArrayInputStream;
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.ObjectInputStream;
23+
import java.io.ObjectOutputStream;
24+
2025
import junit.framework.TestCase;
2126

2227
public class CSVFormatTest extends TestCase {
@@ -141,7 +146,28 @@ public void testValidation() {
141146
} catch (IllegalArgumentException e) {
142147
// expected
143148
}
144-
145-
149+
}
150+
151+
public void testSerialization() throws Exception {
152+
ByteArrayOutputStream out = new ByteArrayOutputStream();
153+
154+
ObjectOutputStream oos = new ObjectOutputStream(out);
155+
oos.writeObject(CSVFormat.DEFAULT);
156+
oos.flush();
157+
oos.close();
158+
159+
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
160+
CSVFormat format = (CSVFormat) in.readObject();
161+
162+
assertNotNull(format);
163+
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
164+
assertEquals("encapsulator", CSVFormat.DEFAULT.getEncapsulator(), format.getEncapsulator());
165+
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
166+
assertEquals("line separator", CSVFormat.DEFAULT.getLineSeparator(), format.getLineSeparator());
167+
assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
168+
assertEquals("unicode escape", CSVFormat.DEFAULT.isUnicodeEscapesInterpreted(), format.isUnicodeEscapesInterpreted());
169+
assertEquals("trim left", CSVFormat.DEFAULT.isLeadingSpacesIgnored(), format.isLeadingSpacesIgnored());
170+
assertEquals("trim right", CSVFormat.DEFAULT.isTrailingSpacesIgnored(), format.isTrailingSpacesIgnored());
171+
assertEquals("empty lines", CSVFormat.DEFAULT.isEmptyLinesIgnored(), format.isEmptyLinesIgnored());
146172
}
147173
}

0 commit comments

Comments
 (0)