From aa1c3ed0fa00fc75928c81c234e3102af9d22700 Mon Sep 17 00:00:00 2001 From: Hovhannes Date: Thu, 5 Mar 2015 11:50:46 +0100 Subject: [PATCH] Update CSVTestDataSource.java Added all possible parameters for CSVReader to be able to parse special chars like \n \t ... --- .../core/csv/CSVTestDataSource.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/net/thucydides/core/csv/CSVTestDataSource.java b/core/src/main/java/net/thucydides/core/csv/CSVTestDataSource.java index 35881ce7fa..8e30869519 100644 --- a/core/src/main/java/net/thucydides/core/csv/CSVTestDataSource.java +++ b/core/src/main/java/net/thucydides/core/csv/CSVTestDataSource.java @@ -22,12 +22,18 @@ public class CSVTestDataSource implements TestDataSource { private final List> testData; private final char separator; + private final char quotechar; + private final char escape; + private final int skipLines; private final List headers; private static final Logger LOGGER = LoggerFactory.getLogger(CSVTestDataSource.class); - public CSVTestDataSource(final String path, final char separatorValue) throws IOException { + public CSVTestDataSource(final String path, final char separatorValue, final char quotechar, final char escape, final int skipLines) throws IOException { this.separator = separatorValue; + this.quotechar = quotechar; + this.escape = escape; + this.skipLines = skipLines; List csvDataRows = getCSVDataFrom(getDataFileFor(path)); String[] titleRow = csvDataRows.get(0); @@ -43,7 +49,19 @@ public String convert(String str) { } public CSVTestDataSource(final String path) throws IOException { - this(path, CSVReader.DEFAULT_SEPARATOR); + this(path, CSVReader.DEFAULT_SEPARATOR, CSVReader.DEFAULT_QUOTE_CHARACTER, CSVReader.DEFAULT_ESCAPE_CHARACTER, CSVReader.DEFAULT_SKIP_LINES); + } + + public CSVTestDataSource(final String path, final char separatorValue) throws IOException { + this(path, separatorValue, CSVReader.DEFAULT_QUOTE_CHARACTER, CSVReader.DEFAULT_ESCAPE_CHARACTER, CSVReader.DEFAULT_SKIP_LINES); + } + + public CSVTestDataSource(final String path, final char separatorValue, final char quotechar) throws IOException { + this(path, separatorValue, quotechar, CSVReader.DEFAULT_ESCAPE_CHARACTER, CSVReader.DEFAULT_SKIP_LINES); + } + + public CSVTestDataSource(final String path, final char separatorValue, final char quotechar, final char escape) throws IOException { + this(path, separatorValue, quotechar, escape, CSVReader.DEFAULT_SKIP_LINES); } public static boolean validTestDataPath(final String path) { @@ -80,7 +98,7 @@ private static boolean validFileSystemPath(final String path) { protected List getCSVDataFrom(final Reader testDataReader) throws IOException { - CSVReader reader = new CSVReader(testDataReader, separator); + CSVReader reader = new CSVReader(testDataReader, separator, quotechar, escape, skipLines); List rows = Lists.newArrayList(); try { rows = reader.readAll();