3131import java .net .URL ;
3232import java .nio .charset .Charset ;
3333import java .util .ArrayList ;
34+ import java .util .Arrays ;
3435import java .util .Collection ;
3536import java .util .List ;
3637
@@ -50,12 +51,12 @@ public class CSVFileParserTest {
5051 private static final File BASE = new File ("src/test/resources/CSVFileParser" );
5152
5253 private final BufferedReader testData ;
54+
5355 private final String testName ;
5456
55- public CSVFileParserTest (final File file ) throws FileNotFoundException
56- {
57- this .testName = file .getName ();
58- this .testData = new BufferedReader (new FileReader (file ));
57+ public CSVFileParserTest (final File file ) throws FileNotFoundException {
58+ this .testName = file .getName ();
59+ this .testData = new BufferedReader (new FileReader (file ));
5960 }
6061
6162 private String readTestData () throws IOException {
@@ -67,18 +68,21 @@ private String readTestData() throws IOException {
6768 }
6869
6970 @ Parameters
70- public static Collection <Object []> generateData ()
71- {
71+ public static Collection <Object []> generateData () {
7272 final List <Object []> list = new ArrayList <Object []>();
7373
7474 final FilenameFilter filenameFilter = new FilenameFilter () {
75+
76+ @ Override
7577 public boolean accept (final File dir , final String name ) {
7678 return name .startsWith ("test" ) && name .endsWith (".txt" );
7779 }
7880 };
7981 final File [] files = BASE .listFiles (filenameFilter );
80- for (final File f : files ){
81- list .add (new Object []{f });
82+ for (final File f : files ) {
83+ list .add (new Object [] {
84+ f
85+ });
8286 }
8387 return list ;
8488 }
@@ -88,14 +92,14 @@ public void testCSVFile() throws Exception {
8892 String line = readTestData ();
8993 assertNotNull ("file must contain config line" , line );
9094 final String [] split = line .split (" " );
91- assertTrue (testName + " require 1 param" , split .length >= 1 );
92- // first line starts with csv data file name
95+ assertTrue (testName + " require 1 param" , split .length >= 1 );
96+ // first line starts with csv data file name
9397 CSVFormat format = CSVFormat .newFormat (',' ).withQuote ('"' );
9498 boolean checkComments = false ;
95- for (int i = 1 ; i < split .length ; i ++) {
99+ for (int i = 1 ; i < split .length ; i ++) {
96100 final String option = split [i ];
97- final String [] option_parts = option .split ("=" ,2 );
98- if ("IgnoreEmpty" .equalsIgnoreCase (option_parts [0 ])){
101+ final String [] option_parts = option .split ("=" , 2 );
102+ if ("IgnoreEmpty" .equalsIgnoreCase (option_parts [0 ])) {
99103 format = format .withIgnoreEmptyLines (Boolean .parseBoolean (option_parts [1 ]));
100104 } else if ("IgnoreSpaces" .equalsIgnoreCase (option_parts [0 ])) {
101105 format = format .withIgnoreSurroundingSpaces (Boolean .parseBoolean (option_parts [1 ]));
@@ -104,25 +108,25 @@ public void testCSVFile() throws Exception {
104108 } else if ("CheckComments" .equalsIgnoreCase (option_parts [0 ])) {
105109 checkComments = true ;
106110 } else {
107- fail (testName + " unexpected option: " + option );
111+ fail (testName + " unexpected option: " + option );
108112 }
109113 }
110114 line = readTestData (); // get string version of format
111- assertEquals (testName + " Expected format " , line , format .toString ());
115+ assertEquals (testName + " Expected format " , line , format .toString ());
112116
113117 // Now parse the file and compare against the expected results
114118 // We use a buffered reader internally so no need to create one here.
115119 final CSVParser parser = CSVParser .parse (new File (BASE , split [0 ]), Charset .defaultCharset (), format );
116- for (final CSVRecord record : parser ) {
117- String parsed = record .toString ();
120+ for (final CSVRecord record : parser ) {
121+ String parsed = Arrays .toString (record . values () );
118122 if (checkComments ) {
119123 final String comment = record .getComment ().replace ("\n " , "\\ n" );
120124 if (comment != null ) {
121125 parsed += "#" + comment ;
122126 }
123127 }
124128 final int count = record .size ();
125- assertEquals (testName , readTestData (), count + ":" + parsed );
129+ assertEquals (testName , readTestData (), count + ":" + parsed );
126130 }
127131 parser .close ();
128132 }
@@ -158,7 +162,7 @@ public void testCSVUrl() throws Exception {
158162 final URL resource = ClassLoader .getSystemResource ("CSVFileParser/" + split [0 ]);
159163 final CSVParser parser = CSVParser .parse (resource , Charset .forName ("UTF-8" ), format );
160164 for (final CSVRecord record : parser ) {
161- String parsed = record .toString ();
165+ String parsed = Arrays .toString (record . values () );
162166 if (checkComments ) {
163167 final String comment = record .getComment ().replace ("\n " , "\\ n" );
164168 if (comment != null ) {
0 commit comments