1919
2020import static org .apache .commons .csv .CSVFormat .RFC4180 ;
2121import static org .apache .commons .csv .Constants .CR ;
22+ import static org .apache .commons .csv .Constants .CRLF ;
2223import static org .apache .commons .csv .Constants .LF ;
2324import static org .junit .Assert .assertArrayEquals ;
2425import static org .junit .Assert .assertEquals ;
@@ -118,7 +119,7 @@ public void testEqualsEscape() {
118119 @ Test
119120 public void testEqualsHeader () {
120121 final CSVFormat right = CSVFormat .newFormat ('\'' )
121- .withRecordSeparator ('*' )
122+ .withRecordSeparator (CR )
122123 .withCommentStart ('#' )
123124 .withEscape ('+' )
124125 .withHeader ("One" , "Two" , "Three" )
@@ -183,23 +184,23 @@ public void testEqualsQuotePolicy() {
183184 @ Test
184185 public void testEqualsRecordSeparator () {
185186 final CSVFormat right = CSVFormat .newFormat ('\'' )
186- .withRecordSeparator ('*' )
187+ .withRecordSeparator (CR )
187188 .withCommentStart ('#' )
188189 .withEscape ('+' )
189190 .withIgnoreEmptyLines (true )
190191 .withIgnoreSurroundingSpaces (true )
191192 .withQuoteChar ('"' )
192193 .withQuotePolicy (Quote .ALL );
193194 final CSVFormat left = right
194- .withRecordSeparator ('!' );
195+ .withRecordSeparator (LF );
195196
196197 assertNotEquals (right , left );
197198 }
198199
199200 @ Test
200201 public void testEqualsNullString () {
201202 final CSVFormat right = CSVFormat .newFormat ('\'' )
202- .withRecordSeparator ('*' )
203+ .withRecordSeparator (CR )
203204 .withCommentStart ('#' )
204205 .withEscape ('+' )
205206 .withIgnoreEmptyLines (true )
@@ -216,7 +217,7 @@ public void testEqualsNullString() {
216217 @ Test
217218 public void testEqualsSkipHeaderRecord () {
218219 final CSVFormat right = CSVFormat .newFormat ('\'' )
219- .withRecordSeparator ('*' )
220+ .withRecordSeparator (CR )
220221 .withCommentStart ('#' )
221222 .withEscape ('+' )
222223 .withIgnoreEmptyLines (true )
@@ -409,8 +410,25 @@ public void testWithQuotePolicy() throws Exception {
409410 }
410411
411412 @ Test
412- public void testWithRecordSeparator () throws Exception {
413- final CSVFormat formatWithRecordSeparator = CSVFormat .DEFAULT .withRecordSeparator ('!' );
414- assertEquals ("!" , formatWithRecordSeparator .getRecordSeparator ());
413+ public void testWithRecordSeparatorCR () throws Exception {
414+ final CSVFormat formatWithRecordSeparator = CSVFormat .DEFAULT .withRecordSeparator (CR );
415+ assertEquals (String .valueOf (CR ), formatWithRecordSeparator .getRecordSeparator ());
416+ }
417+
418+ @ Test
419+ public void testWithRecordSeparatorLF () throws Exception {
420+ final CSVFormat formatWithRecordSeparator = CSVFormat .DEFAULT .withRecordSeparator (LF );
421+ assertEquals (String .valueOf (LF ), formatWithRecordSeparator .getRecordSeparator ());
422+ }
423+
424+ @ Test
425+ public void testWithRecordSeparatorCRLF () throws Exception {
426+ final CSVFormat formatWithRecordSeparator = CSVFormat .DEFAULT .withRecordSeparator (CRLF );
427+ assertEquals (CRLF , formatWithRecordSeparator .getRecordSeparator ());
428+ }
429+
430+ @ Test (expected = IllegalArgumentException .class )
431+ public void testWithRecordSeparatorIllegal () throws Exception {
432+ CSVFormat .DEFAULT .withRecordSeparator ('!' );
415433 }
416434}
0 commit comments