|
17 | 17 |
|
18 | 18 | package org.apache.commons.csv; |
19 | 19 |
|
| 20 | +import java.io.ByteArrayInputStream; |
| 21 | +import java.io.ByteArrayOutputStream; |
| 22 | +import java.io.ObjectInputStream; |
| 23 | +import java.io.ObjectOutputStream; |
| 24 | + |
20 | 25 | import junit.framework.TestCase; |
21 | 26 |
|
22 | 27 | public class CSVFormatTest extends TestCase { |
@@ -141,7 +146,28 @@ public void testValidation() { |
141 | 146 | } catch (IllegalArgumentException e) { |
142 | 147 | // expected |
143 | 148 | } |
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()); |
146 | 172 | } |
147 | 173 | } |
0 commit comments