commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1742426 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java
Date Thu, 05 May 2016 12:25:57 GMT
Author: britter
Date: Thu May  5 12:25:57 2016
New Revision: 1742426

URL: http://svn.apache.org/viewvc?rev=1742426&view=rev
Log:
Access test data using the classloader instead of defining a file handle

Modified:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java?rev=1742426&r1=1742425&r2=1742426&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java
(original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java
Thu May  5 12:25:57 2016
@@ -17,10 +17,10 @@
 package org.apache.commons.csv.bugs;
 
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
-import java.nio.charset.Charset;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
@@ -33,8 +33,7 @@ public class JiraCsv167Test {
 
     @Test
     public void parse() throws IOException {
-        final File csvData = new File("src/test/resources/csv-167/sample1.csv");
-        final BufferedReader br = new BufferedReader(new FileReader(csvData));
+        final BufferedReader br = new BufferedReader(getTestInput());
         String s = null;
         int totcomment = 0;
         int totrecs = 0;
@@ -67,11 +66,10 @@ public class JiraCsv167Test {
         format = format.withRecordSeparator('\n');
         format = format.withSkipHeaderRecord(false);
         //
-        final CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), format);
+        final CSVParser parser = format.parse(getTestInput());
         int comments = 0;
         int records = 0;
         for (final CSVRecord csvRecord : parser) {
-//            System.out.println(csvRecord.isComment() + "[" + csvRecord.toString() + "]");
             records++;
             if (csvRecord.hasComment()) {
                 comments++;
@@ -81,4 +79,9 @@ public class JiraCsv167Test {
         Assert.assertEquals(totcomment, comments);
         Assert.assertEquals(totrecs, records); // records includes the header
     }
+
+    private Reader getTestInput() {
+        final InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("csv-167/sample1.csv");
+        return new InputStreamReader(is);
+    }
 }



Mime
View raw message