@@ -731,33 +731,6 @@ public void testPrint() throws IOException {
731731 }
732732 }
733733
734- @ Test
735- public void testPrintToFileWithDefaultCharset () throws IOException {
736- File file = File .createTempFile (getClass ().getName (), ".csv" );
737- try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , Charset .defaultCharset ())) {
738- printer .printRecord ("a" , "b\\ c" );
739- }
740- assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , Charset .defaultCharset ()));
741- }
742-
743- @ Test
744- public void testPrintToPathWithDefaultCharset () throws IOException {
745- File file = File .createTempFile (getClass ().getName (), ".csv" );
746- try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file .toPath (), Charset .defaultCharset ())) {
747- printer .printRecord ("a" , "b\\ c" );
748- }
749- assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , Charset .defaultCharset ()));
750- }
751-
752- @ Test
753- public void testPrintToFileWithCharsetUtf16Be () throws IOException {
754- File file = File .createTempFile (getClass ().getName (), ".csv" );
755- try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , StandardCharsets .UTF_16BE )) {
756- printer .printRecord ("a" , "b\\ c" );
757- }
758- assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , StandardCharsets .UTF_16BE ));
759- }
760-
761734 @ Test
762735 public void testPrintCustomNullValues () throws IOException {
763736 final StringWriter sw = new StringWriter ();
@@ -839,6 +812,33 @@ public void testPrintNullValues() throws IOException {
839812 }
840813 }
841814
815+ @ Test
816+ public void testPrintToFileWithCharsetUtf16Be () throws IOException {
817+ File file = File .createTempFile (getClass ().getName (), ".csv" );
818+ try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , StandardCharsets .UTF_16BE )) {
819+ printer .printRecord ("a" , "b\\ c" );
820+ }
821+ assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , StandardCharsets .UTF_16BE ));
822+ }
823+
824+ @ Test
825+ public void testPrintToFileWithDefaultCharset () throws IOException {
826+ File file = File .createTempFile (getClass ().getName (), ".csv" );
827+ try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , Charset .defaultCharset ())) {
828+ printer .printRecord ("a" , "b\\ c" );
829+ }
830+ assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , Charset .defaultCharset ()));
831+ }
832+
833+ @ Test
834+ public void testPrintToPathWithDefaultCharset () throws IOException {
835+ File file = File .createTempFile (getClass ().getName (), ".csv" );
836+ try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file .toPath (), Charset .defaultCharset ())) {
837+ printer .printRecord ("a" , "b\\ c" );
838+ }
839+ assertEquals ("a,b\\ c" + recordSeparator , FileUtils .readFileToString (file , Charset .defaultCharset ()));
840+ }
841+
842842 @ Test
843843 public void testQuoteAll () throws IOException {
844844 final StringWriter sw = new StringWriter ();
@@ -926,39 +926,39 @@ public void testSkipHeaderRecordTrue() throws IOException {
926926 }
927927
928928 @ Test
929- public void testTrimOnOneColumn () throws IOException {
929+ public void testTrailingDelimiterOnTwoColumns () throws IOException {
930930 final StringWriter sw = new StringWriter ();
931- try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim ())) {
932- printer .print ( " A " );
933- assertEquals ("A" , sw .toString ());
931+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrailingDelimiter ())) {
932+ printer .printRecord ( "A" , "B " );
933+ assertEquals ("A,B, \r \n " , sw .toString ());
934934 }
935935 }
936936
937937 @ Test
938- public void testTrimOnTwoColumns () throws IOException {
938+ public void testTrimOffOneColumn () throws IOException {
939939 final StringWriter sw = new StringWriter ();
940- try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim ())) {
940+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim (false ))) {
941941 printer .print (" A " );
942- printer .print (" B " );
943- assertEquals ("A,B" , sw .toString ());
942+ assertEquals ("\" A \" " , sw .toString ());
944943 }
945944 }
946945
947946 @ Test
948- public void testTrailingDelimiterOnTwoColumns () throws IOException {
947+ public void testTrimOnOneColumn () throws IOException {
949948 final StringWriter sw = new StringWriter ();
950- try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrailingDelimiter ())) {
951- printer .printRecord ( "A" , "B " );
952- assertEquals ("A,B, \r \n " , sw .toString ());
949+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim ())) {
950+ printer .print ( " A " );
951+ assertEquals ("A" , sw .toString ());
953952 }
954953 }
955954
956955 @ Test
957- public void testTrimOffOneColumn () throws IOException {
956+ public void testTrimOnTwoColumns () throws IOException {
958957 final StringWriter sw = new StringWriter ();
959- try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim (false ))) {
958+ try (final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT .withTrim ())) {
960959 printer .print (" A " );
961- assertEquals ("\" A \" " , sw .toString ());
960+ printer .print (" B " );
961+ assertEquals ("A,B" , sw .toString ());
962962 }
963963 }
964964
0 commit comments