From 554af4bc5c1014644dfca83ce6577f7882a9dc04 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Thu, 5 May 2016 12:25:57 +0000 Subject: [PATCH] Access test data using the classloader instead of defining a file handle git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1742426 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/csv/bugs/JiraCsv167Test.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java b/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java index 19b3d86b..46c5739f 100644 --- a/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java +++ b/src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java @@ -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); + } }