CSV-252: Migration to JUnit Jupiter (#49)
* CSV-252 Stop using junit.framework.TestCase junit.framework.TestCase is a class from JUnit 3, and while it is not officially deprecated, it's discouraged to use it. This patch removes the single use of junit.framework.TestCase#assertNull, and replaces it with the standard, recommended, org.junit.Assert#assertNull. * CSV-252 Standardize org.junit.Assert imports Code in the project uses org.junit.Assert's methods in two ways: 1. By statically importing them 2. By importing the class and using its methods Option 1 seems to be the de-facto standard, with just a handful of cases using Option 2. This patch standardizes these cases to also use static imports thus making the code look more uniform, and easier to maintain. * CSV-252 Upgrade Mockito to 3.1.0 Upgrade the Mockito dependency to the latest available version, 3.1.0, in order to facilitate an upgrade to JUnit Jupiter. * CSV-252 JUnit Jupiter upgrade This patch upgrades the project's testing framework from JUnit 4.12 to the modern JUnit Jupiter 5.5.4. Since JUnit 5 Jupiter is not backwards compatible to JUnit 4.x (or even JUnit Vintage), this patch is a bit large, even though a lot of the changes are merely cosmetic (such as changing the argument order, see details below). In order to make the reviewer's task as easy as possible, this PR does not presume to use JUnit Jupiter's best practices and all its new functionality, but only to migrate the existing tests with as little change as possible. Following patches may want to improve the tests by using some of JUnit Jupiter's new features. This patch includes the following changes: 1. Maven dependency changes: a. junit:junit was replaced with org.junit.jupiter:junit-jupiter. b. org.hamcrest:hamcrest was introduced as an explicit dependency, since the project uses Hamcrest, and JUnit Jupiter does not bundle Hamcrest, unlike JUnit 4.x. 2. Annotations: a. org.junit.jupiter.api.Test was used as a drop in replacement for org.juit.Test without arguments. See 3.ii. for handling of @Test annotations with an "expected" argument. b. org.junit.jupiter.api.BeforeEach was used as an drop in replacement for org.junit.Before. c. org.junit.jupiter.api.BeforeAll was used as an drop in replacement for org.junit.BeforeClass. d. org.junit.jupiter.api.Disabled was used as a drop in replacement for org.junit.Ignore. 3. Assertions: a. org.junit.jupiter.api.Assertions' methods were used as drop in replacements for org.junit.Assert's methods with the same name in the simple case of an assertion without a message. In the case of an assertion with a message, org.junit.jupiter.api.Assertions' methods were used, but the argument order was changed - Assert's methods take the message as the first argument, while Assertions' methods take the message as the last argument. b. org.junit.jupiter.api.Assertions#assertThrows was used to assert that a specific exception was throws instead of an org.junit.Test annotation with an expected argument. This technique has a couple of side bonuses. First, it makes the tests slightly stricter, as now they can assert the exception was thrown from a specific line and prevent false positives where the test's "set-up" code accidentally threw that exception. Second, it clarifies that some of the test code is unreachable (as a previous line already throws an exception), and can safely be removed in order to clean up the test. The throws clauses of these methods were cleaned up from exceptions that can no longer be thrown in order to avoid compilation warnings. c. org.hamcrest.MatcherAssert#assertThat was used as a drop in replacement for org.junit.Assert#assertThat. 4. Specific Changes: a. CSVFileParserTest was rewritten with JUnit Jupiter's org.junit.jupiter.api.ParameterizedTest. Unlike JUnit 4's org.junit.runners.Parameterized, it cannot be used to inject arguments to a test's construct, and so the test can't be stateful. Instead, it was rewritten so every test receives the file as a parameter, and opens a reader on it itself. As a side bonus, this design makes it easier to close the reader and avoid leaving open file descriptors like the original test did.
This commit is contained in:
parent
6aa1756750
commit
e2f0a4d8a8
16
pom.xml
16
pom.xml
|
@ -33,15 +33,21 @@ CSV files of various types.
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>4.12</version>
|
<version>5.5.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>1.10.19</version>
|
<version>3.1.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -28,8 +30,8 @@ public class AssertionsTest {
|
||||||
Assertions.notNull(new Object(), "object");
|
Assertions.notNull(new Object(), "object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNotNullNull() throws Exception {
|
public void testNotNullNull() {
|
||||||
Assertions.notNull(null, "object");
|
assertThrows(IllegalArgumentException.class, () -> Assertions.notNull(null, "object"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,152 +17,138 @@
|
||||||
|
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.stream.Stream;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse tests using test files
|
* Parse tests using test files
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class CSVFileParserTest {
|
public class CSVFileParserTest {
|
||||||
|
|
||||||
private static final File BASE = new File("src/test/resources/CSVFileParser");
|
private static final File BASE = new File("src/test/resources/CSVFileParser");
|
||||||
|
|
||||||
private final BufferedReader testData;
|
private String readTestData(BufferedReader reader) throws IOException {
|
||||||
|
|
||||||
private final String testName;
|
|
||||||
|
|
||||||
public CSVFileParserTest(final File file) throws FileNotFoundException {
|
|
||||||
this.testName = file.getName();
|
|
||||||
this.testData = new BufferedReader(new FileReader(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readTestData() throws IOException {
|
|
||||||
String line;
|
String line;
|
||||||
do {
|
do {
|
||||||
line = testData.readLine();
|
line = reader.readLine();
|
||||||
} while (line != null && line.startsWith("#"));
|
} while (line != null && line.startsWith("#"));
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
public static Stream<File> generateData() {
|
||||||
public static Collection<Object[]> generateData() {
|
|
||||||
final List<Object[]> list = new ArrayList<>();
|
|
||||||
|
|
||||||
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
|
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
|
||||||
final File[] files = BASE.listFiles(fileNameFilter);
|
final File[] files = BASE.listFiles(fileNameFilter);
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (final File f : files) {
|
return Arrays.stream(files);
|
||||||
list.add(new Object[] { f });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list;
|
return Stream.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testCSVFile() throws Exception {
|
@MethodSource("generateData")
|
||||||
String line = readTestData();
|
public void testCSVFile(File testFile) throws Exception {
|
||||||
assertNotNull("file must contain config line", line);
|
try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) {
|
||||||
final String[] split = line.split(" ");
|
String line = readTestData(testData);
|
||||||
assertTrue(testName + " require 1 param", split.length >= 1);
|
assertNotNull("file must contain config line", line);
|
||||||
// first line starts with csv data file name
|
final String[] split = line.split(" ");
|
||||||
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
|
assertTrue(split.length >= 1, testFile.getName() + " require 1 param");
|
||||||
boolean checkComments = false;
|
// first line starts with csv data file name
|
||||||
for (int i = 1; i < split.length; i++) {
|
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
|
||||||
final String option = split[i];
|
boolean checkComments = false;
|
||||||
final String[] option_parts = option.split("=", 2);
|
for (int i = 1; i < split.length; i++) {
|
||||||
if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) {
|
final String option = split[i];
|
||||||
format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1]));
|
final String[] option_parts = option.split("=", 2);
|
||||||
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
|
if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) {
|
||||||
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
|
format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1]));
|
||||||
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
|
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
|
||||||
format = format.withCommentMarker(option_parts[1].charAt(0));
|
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
|
||||||
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
|
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
|
||||||
checkComments = true;
|
format = format.withCommentMarker(option_parts[1].charAt(0));
|
||||||
} else {
|
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
|
||||||
fail(testName + " unexpected option: " + option);
|
checkComments = true;
|
||||||
}
|
} else {
|
||||||
}
|
fail(testFile.getName() + " unexpected option: " + option);
|
||||||
line = readTestData(); // get string version of format
|
}
|
||||||
assertEquals(testName + " Expected format ", line, format.toString());
|
}
|
||||||
|
line = readTestData(testData); // get string version of format
|
||||||
// Now parse the file and compare against the expected results
|
assertEquals(line, format.toString(), testFile.getName() + " Expected format ");
|
||||||
// We use a buffered reader internally so no need to create one here.
|
|
||||||
try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
|
// Now parse the file and compare against the expected results
|
||||||
for (final CSVRecord record : parser) {
|
// We use a buffered reader internally so no need to create one here.
|
||||||
String parsed = Arrays.toString(record.values());
|
try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
|
||||||
if (checkComments) {
|
for (final CSVRecord record : parser) {
|
||||||
final String comment = record.getComment().replace("\n", "\\n");
|
String parsed = Arrays.toString(record.values());
|
||||||
if (comment != null) {
|
if (checkComments) {
|
||||||
parsed += "#" + comment;
|
final String comment = record.getComment().replace("\n", "\\n");
|
||||||
}
|
if (comment != null) {
|
||||||
|
parsed += "#" + comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final int count = record.size();
|
||||||
|
assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
|
||||||
}
|
}
|
||||||
final int count = record.size();
|
|
||||||
assertEquals(testName, readTestData(), count + ":" + parsed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testCSVUrl() throws Exception {
|
@MethodSource("generateData")
|
||||||
String line = readTestData();
|
public void testCSVUrl(File testFile) throws Exception {
|
||||||
assertNotNull("file must contain config line", line);
|
try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) {
|
||||||
final String[] split = line.split(" ");
|
String line = readTestData(testData);
|
||||||
assertTrue(testName + " require 1 param", split.length >= 1);
|
assertNotNull("file must contain config line", line);
|
||||||
// first line starts with csv data file name
|
final String[] split = line.split(" ");
|
||||||
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
|
assertTrue(split.length >= 1, testFile.getName() + " require 1 param");
|
||||||
boolean checkComments = false;
|
// first line starts with csv data file name
|
||||||
for (int i = 1; i < split.length; i++) {
|
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
|
||||||
final String option = split[i];
|
boolean checkComments = false;
|
||||||
final String[] option_parts = option.split("=", 2);
|
for (int i = 1; i < split.length; i++) {
|
||||||
if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) {
|
final String option = split[i];
|
||||||
format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1]));
|
final String[] option_parts = option.split("=", 2);
|
||||||
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
|
if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) {
|
||||||
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
|
format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1]));
|
||||||
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
|
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
|
||||||
format = format.withCommentMarker(option_parts[1].charAt(0));
|
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
|
||||||
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
|
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
|
||||||
checkComments = true;
|
format = format.withCommentMarker(option_parts[1].charAt(0));
|
||||||
} else {
|
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
|
||||||
fail(testName + " unexpected option: " + option);
|
checkComments = true;
|
||||||
}
|
} else {
|
||||||
}
|
fail(testFile.getName() + " unexpected option: " + option);
|
||||||
line = readTestData(); // get string version of format
|
}
|
||||||
assertEquals(testName + " Expected format ", line, format.toString());
|
}
|
||||||
|
line = readTestData(testData); // get string version of format
|
||||||
// Now parse the file and compare against the expected results
|
assertEquals(line, format.toString(), testFile.getName() + " Expected format ");
|
||||||
final URL resource = ClassLoader.getSystemResource("CSVFileParser/" + split[0]);
|
|
||||||
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
|
// Now parse the file and compare against the expected results
|
||||||
for (final CSVRecord record : parser) {
|
final URL resource = ClassLoader.getSystemResource("CSVFileParser/" + split[0]);
|
||||||
String parsed = Arrays.toString(record.values());
|
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
|
||||||
if (checkComments) {
|
for (final CSVRecord record : parser) {
|
||||||
final String comment = record.getComment().replace("\n", "\\n");
|
String parsed = Arrays.toString(record.values());
|
||||||
if (comment != null) {
|
if (checkComments) {
|
||||||
parsed += "#" + comment;
|
final String comment = record.getComment().replace("\n", "\\n");
|
||||||
}
|
if (comment != null) {
|
||||||
|
parsed += "#" + comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final int count = record.size();
|
||||||
|
assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
|
||||||
}
|
}
|
||||||
final int count = record.size();
|
|
||||||
assertEquals(testName, readTestData(), count + ":" + parsed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
|
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CSVFormat.Predefined}.
|
* Tests {@link CSVFormat.Predefined}.
|
||||||
|
@ -26,8 +27,8 @@ import org.junit.Test;
|
||||||
public class CSVFormatPredefinedTest {
|
public class CSVFormatPredefinedTest {
|
||||||
|
|
||||||
private void test(final CSVFormat format, final String enumName) {
|
private void test(final CSVFormat format, final String enumName) {
|
||||||
Assert.assertEquals(format, CSVFormat.Predefined.valueOf(enumName).getFormat());
|
assertEquals(format, CSVFormat.Predefined.valueOf(enumName).getFormat());
|
||||||
Assert.assertEquals(format, CSVFormat.valueOf(enumName));
|
assertEquals(format, CSVFormat.valueOf(enumName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,18 +17,20 @@
|
||||||
|
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertNull;
|
|
||||||
import static org.apache.commons.csv.CSVFormat.RFC4180;
|
import static org.apache.commons.csv.CSVFormat.RFC4180;
|
||||||
import static org.apache.commons.csv.Constants.CR;
|
import static org.apache.commons.csv.Constants.CR;
|
||||||
import static org.apache.commons.csv.Constants.CRLF;
|
import static org.apache.commons.csv.Constants.CRLF;
|
||||||
import static org.apache.commons.csv.Constants.LF;
|
import static org.apache.commons.csv.Constants.LF;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -38,8 +40,7 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CSVFormat}.
|
* Tests {@link CSVFormat}.
|
||||||
|
@ -72,14 +73,14 @@ public class CSVFormatTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDelimiterSameAsCommentStartThrowsException() {
|
public void testDelimiterSameAsCommentStartThrowsException() {
|
||||||
CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!');
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDelimiterSameAsEscapeThrowsException() {
|
public void testDelimiterSameAsEscapeThrowsException() {
|
||||||
CSVFormat.DEFAULT.withDelimiter('!').withEscape('!');
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter('!').withEscape('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,9 +91,11 @@ public class CSVFormatTest {
|
||||||
assertArrayEquals(header, format.getHeader());
|
assertArrayEquals(header, format.getHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDuplicateHeaderElementsFalse() {
|
public void testDuplicateHeaderElementsFalse() {
|
||||||
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A", "A");
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A", "A"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDuplicateHeaderElementsTrue() {
|
public void testDuplicateHeaderElementsTrue() {
|
||||||
|
@ -520,15 +523,17 @@ public class CSVFormatTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testEscapeSameAsCommentStartThrowsException() {
|
public void testEscapeSameAsCommentStartThrowsException() {
|
||||||
CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!');
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
|
public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
|
||||||
// Cannot assume that callers won't use different Character objects
|
// Cannot assume that callers won't use different Character objects
|
||||||
CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentMarker(new Character('!'));
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentMarker(new Character('!')));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -659,25 +664,27 @@ public class CSVFormatTest {
|
||||||
assertFalse(formatStr.endsWith("null"));
|
assertFalse(formatStr.endsWith("null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testQuoteCharSameAsCommentStartThrowsException() {
|
public void testQuoteCharSameAsCommentStartThrowsException() {
|
||||||
CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!');
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
|
public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
|
||||||
// Cannot assume that callers won't use different Character objects
|
// Cannot assume that callers won't use different Character objects
|
||||||
CSVFormat.DEFAULT.withQuote(new Character('!')).withCommentMarker('!');
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> CSVFormat.DEFAULT.withQuote(new Character('!')).withCommentMarker('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testQuoteCharSameAsDelimiterThrowsException() {
|
public void testQuoteCharSameAsDelimiterThrowsException() {
|
||||||
CSVFormat.DEFAULT.withQuote('!').withDelimiter('!');
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote('!').withDelimiter('!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
|
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
|
||||||
CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -705,13 +712,13 @@ public class CSVFormatTest {
|
||||||
final CSVFormat format = (CSVFormat) in.readObject();
|
final CSVFormat format = (CSVFormat) in.readObject();
|
||||||
|
|
||||||
assertNotNull(format);
|
assertNotNull(format);
|
||||||
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
|
assertEquals(CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter(), "delimiter");
|
||||||
assertEquals("encapsulator", CSVFormat.DEFAULT.getQuoteCharacter(), format.getQuoteCharacter());
|
assertEquals(CSVFormat.DEFAULT.getQuoteCharacter(), format.getQuoteCharacter(), "encapsulator");
|
||||||
assertEquals("comment start", CSVFormat.DEFAULT.getCommentMarker(), format.getCommentMarker());
|
assertEquals(CSVFormat.DEFAULT.getCommentMarker(), format.getCommentMarker(), "comment start");
|
||||||
assertEquals("record separator", CSVFormat.DEFAULT.getRecordSeparator(), format.getRecordSeparator());
|
assertEquals(CSVFormat.DEFAULT.getRecordSeparator(), format.getRecordSeparator(), "record separator");
|
||||||
assertEquals("escape", CSVFormat.DEFAULT.getEscapeCharacter(), format.getEscapeCharacter());
|
assertEquals(CSVFormat.DEFAULT.getEscapeCharacter(), format.getEscapeCharacter(), "escape");
|
||||||
assertEquals("trim", CSVFormat.DEFAULT.getIgnoreSurroundingSpaces(), format.getIgnoreSurroundingSpaces());
|
assertEquals(CSVFormat.DEFAULT.getIgnoreSurroundingSpaces(), format.getIgnoreSurroundingSpaces(), "trim");
|
||||||
assertEquals("empty lines", CSVFormat.DEFAULT.getIgnoreEmptyLines(), format.getIgnoreEmptyLines());
|
assertEquals(CSVFormat.DEFAULT.getIgnoreEmptyLines(), format.getIgnoreEmptyLines(), "empty lines");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -891,9 +898,9 @@ public class CSVFormatTest {
|
||||||
assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentMarker());
|
assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentMarker());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testWithCommentStartCRThrowsException() {
|
public void testWithCommentStartCRThrowsException() {
|
||||||
CSVFormat.DEFAULT.withCommentMarker(CR);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withCommentMarker(CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -902,15 +909,15 @@ public class CSVFormatTest {
|
||||||
assertEquals('!', formatWithDelimiter.getDelimiter());
|
assertEquals('!', formatWithDelimiter.getDelimiter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testWithDelimiterLFThrowsException() {
|
public void testWithDelimiterLFThrowsException() {
|
||||||
CSVFormat.DEFAULT.withDelimiter(LF);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(LF));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithEmptyEnum() throws Exception {
|
public void testWithEmptyEnum() throws Exception {
|
||||||
final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(EmptyEnum.class);
|
final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(EmptyEnum.class);
|
||||||
Assert.assertTrue(formatWithHeader.getHeader().length == 0);
|
assertTrue(formatWithHeader.getHeader().length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -919,9 +926,9 @@ public class CSVFormatTest {
|
||||||
assertEquals(Character.valueOf('&'), formatWithEscape.getEscapeCharacter());
|
assertEquals(Character.valueOf('&'), formatWithEscape.getEscapeCharacter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testWithEscapeCRThrowsExceptions() {
|
public void testWithEscapeCRThrowsExceptions() {
|
||||||
CSVFormat.DEFAULT.withEscape(CR);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withEscape(CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1138,9 +1145,9 @@ public class CSVFormatTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testWithQuoteLFThrowsException() {
|
public void testWithQuoteLFThrowsException() {
|
||||||
CSVFormat.DEFAULT.withQuote(LF);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote(LF));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -20,13 +20,14 @@ package org.apache.commons.csv;
|
||||||
import static org.apache.commons.csv.Constants.CR;
|
import static org.apache.commons.csv.Constants.CR;
|
||||||
import static org.apache.commons.csv.Constants.CRLF;
|
import static org.apache.commons.csv.Constants.CRLF;
|
||||||
import static org.apache.commons.csv.Constants.LF;
|
import static org.apache.commons.csv.Constants.LF;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -50,9 +51,8 @@ import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.commons.io.input.BOMInputStream;
|
import org.apache.commons.io.input.BOMInputStream;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CSVParserTest
|
* CSVParserTest
|
||||||
|
@ -85,7 +85,7 @@ public class CSVParserTest {
|
||||||
|
|
||||||
private void parseFully(final CSVParser parser) {
|
private void parseFully(final CSVParser parser) {
|
||||||
for (final CSVRecord csvRecord : parser) {
|
for (final CSVRecord csvRecord : parser) {
|
||||||
Assert.assertNotNull(csvRecord);
|
assertNotNull(csvRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testBackslashEscapingOld() throws IOException {
|
public void testBackslashEscapingOld() throws IOException {
|
||||||
final String code = "one,two,three\n" + "on\\\"e,two\n" + "on\"e,two\n" + "one,\"tw\\\"o\"\n" +
|
final String code = "one,two,three\n" + "on\\\"e,two\n" + "on\"e,two\n" + "one,\"tw\\\"o\"\n" +
|
||||||
"one,\"t\\,wo\"\n" + "one,two,\"th,ree\"\n" + "\"a\\\\\"\n" + "a\\,b\n" + "\"a\\\\,b\"";
|
"one,\"t\\,wo\"\n" + "one,two,\"th,ree\"\n" + "\"a\\\\\"\n" + "a\\,b\n" + "\"a\\\\,b\"";
|
||||||
|
@ -177,13 +177,13 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("CSV-107")
|
@Disabled("CSV-107")
|
||||||
public void testBOM() throws IOException {
|
public void testBOM() throws IOException {
|
||||||
final URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
|
final URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
|
||||||
try (final CSVParser parser = CSVParser.parse(url, Charset.forName(UTF_8_NAME), CSVFormat.EXCEL.withHeader())) {
|
try (final CSVParser parser = CSVParser.parse(url, Charset.forName(UTF_8_NAME), CSVFormat.EXCEL.withHeader())) {
|
||||||
for (final CSVRecord record : parser) {
|
for (final CSVRecord record : parser) {
|
||||||
final String string = record.get("Date");
|
final String string = record.get("Date");
|
||||||
Assert.assertNotNull(string);
|
assertNotNull(string);
|
||||||
// System.out.println("date: " + record.get("Date"));
|
// System.out.println("date: " + record.get("Date"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ public class CSVParserTest {
|
||||||
final CSVParser parser = CSVParser.parse(inputStream, UTF_8, CSVFormat.EXCEL.withHeader())) {
|
final CSVParser parser = CSVParser.parse(inputStream, UTF_8, CSVFormat.EXCEL.withHeader())) {
|
||||||
for (final CSVRecord record : parser) {
|
for (final CSVRecord record : parser) {
|
||||||
final String string = record.get("Date");
|
final String string = record.get("Date");
|
||||||
Assert.assertNotNull(string);
|
assertNotNull(string);
|
||||||
// System.out.println("date: " + record.get("Date"));
|
// System.out.println("date: " + record.get("Date"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ public class CSVParserTest {
|
||||||
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader())) {
|
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader())) {
|
||||||
for (final CSVRecord record : parser) {
|
for (final CSVRecord record : parser) {
|
||||||
final String string = record.get("Date");
|
final String string = record.get("Date");
|
||||||
Assert.assertNotNull(string);
|
assertNotNull(string);
|
||||||
// System.out.println("date: " + record.get("Date"));
|
// System.out.println("date: " + record.get("Date"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ public class CSVParserTest {
|
||||||
final CSVParser parser = CSVParser.parse(reader, CSVFormat.EXCEL.withHeader())) {
|
final CSVParser parser = CSVParser.parse(reader, CSVFormat.EXCEL.withHeader())) {
|
||||||
for (final CSVRecord record : parser) {
|
for (final CSVRecord record : parser) {
|
||||||
final String string = record.get("Date");
|
final String string = record.get("Date");
|
||||||
Assert.assertNotNull(string);
|
assertNotNull(string);
|
||||||
// System.out.println("date: " + record.get("Date"));
|
// System.out.println("date: " + record.get("Date"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NoSuchElementException.class)
|
@Test
|
||||||
public void testClose() throws Exception {
|
public void testClose() throws Exception {
|
||||||
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
|
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
|
||||||
final Iterator<CSVRecord> records;
|
final Iterator<CSVRecord> records;
|
||||||
|
@ -252,7 +252,7 @@ public class CSVParserTest {
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
}
|
}
|
||||||
assertFalse(records.hasNext());
|
assertFalse(records.hasNext());
|
||||||
records.next();
|
assertThrows(NoSuchElementException.class, records::next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -292,10 +292,12 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testDuplicateHeadersNotAllowed() throws Exception {
|
public void testDuplicateHeadersNotAllowed() {
|
||||||
CSVParser.parse("a,b,a\n1,2,3\nx,y,z",
|
assertThrows(
|
||||||
CSVFormat.DEFAULT.withHeader(new String[] {}).withAllowDuplicateHeaderNames(false));
|
IllegalArgumentException.class,
|
||||||
|
() -> CSVParser.parse("a,b,a\n1,2,3\nx,y,z",
|
||||||
|
CSVFormat.DEFAULT.withHeader(new String[] {}).withAllowDuplicateHeaderNames(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -430,9 +432,9 @@ public class CSVParserTest {
|
||||||
final String code = "A,B,C,,\r\na,b,c,d,e\r\n";
|
final String code = "A,B,C,,\r\na,b,c,d,e\r\n";
|
||||||
try (final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader())) {
|
try (final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader())) {
|
||||||
for (final CSVRecord record : parser.getRecords()) {
|
for (final CSVRecord record : parser.getRecords()) {
|
||||||
Assert.assertEquals("a", record.get("A"));
|
assertEquals("a", record.get("A"));
|
||||||
Assert.assertEquals("b", record.get("B"));
|
assertEquals("b", record.get("B"));
|
||||||
Assert.assertEquals("c", record.get("C"));
|
assertEquals("c", record.get("C"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,9 +490,9 @@ public class CSVParserTest {
|
||||||
final Map<String, Integer> headerMap = parser.getHeaderMap();
|
final Map<String, Integer> headerMap = parser.getHeaderMap();
|
||||||
final Iterator<String> columnNames = headerMap.keySet().iterator();
|
final Iterator<String> columnNames = headerMap.keySet().iterator();
|
||||||
// Headers are iterated in column order.
|
// Headers are iterated in column order.
|
||||||
Assert.assertEquals("A", columnNames.next());
|
assertEquals("A", columnNames.next());
|
||||||
Assert.assertEquals("B", columnNames.next());
|
assertEquals("B", columnNames.next());
|
||||||
Assert.assertEquals("C", columnNames.next());
|
assertEquals("C", columnNames.next());
|
||||||
final Iterator<CSVRecord> records = parser.iterator();
|
final Iterator<CSVRecord> records = parser.iterator();
|
||||||
|
|
||||||
// Parse to make sure getHeaderMap did not have a side-effect.
|
// Parse to make sure getHeaderMap did not have a side-effect.
|
||||||
|
@ -512,11 +514,11 @@ public class CSVParserTest {
|
||||||
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
||||||
final Map<String, Integer> nameIndexMap = parser.getHeaderMap();
|
final Map<String, Integer> nameIndexMap = parser.getHeaderMap();
|
||||||
final List<String> headerNames = parser.getHeaderNames();
|
final List<String> headerNames = parser.getHeaderNames();
|
||||||
Assert.assertNotNull(headerNames);
|
assertNotNull(headerNames);
|
||||||
Assert.assertEquals(nameIndexMap.size(), headerNames.size());
|
assertEquals(nameIndexMap.size(), headerNames.size());
|
||||||
for (int i = 0; i < headerNames.size(); i++) {
|
for (int i = 0; i < headerNames.size(); i++) {
|
||||||
final String name = headerNames.get(i);
|
final String name = headerNames.get(i);
|
||||||
Assert.assertEquals(i, nameIndexMap.get(name).intValue());
|
assertEquals(i, nameIndexMap.get(name).intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,7 +528,7 @@ public class CSVParserTest {
|
||||||
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z",
|
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z",
|
||||||
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
CSVFormat.DEFAULT.withHeader("A", "B", "C"))) {
|
||||||
final List<String> headerNames = parser.getHeaderNames();
|
final List<String> headerNames = parser.getHeaderNames();
|
||||||
Assert.assertNotNull(headerNames);
|
assertNotNull(headerNames);
|
||||||
try {
|
try {
|
||||||
headerNames.add("This is a read-only list.");
|
headerNames.add("This is a read-only list.");
|
||||||
fail();
|
fail();
|
||||||
|
@ -716,10 +718,10 @@ public class CSVParserTest {
|
||||||
CSVFormat.DEFAULT.withHeader().withAllowMissingColumnNames().parse(in).iterator();
|
CSVFormat.DEFAULT.withHeader().withAllowMissingColumnNames().parse(in).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testHeadersMissingException() throws Exception {
|
public void testHeadersMissingException() {
|
||||||
final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
|
final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
|
||||||
CSVFormat.DEFAULT.withHeader().parse(in).iterator();
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withHeader().parse(in).iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -744,12 +746,9 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidFormat() throws Exception {
|
public void testInvalidFormat() {
|
||||||
final CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(CR));
|
||||||
try (final CSVParser parser = new CSVParser(null, invalidFormat)) {
|
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -885,7 +884,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testMongoDbCsv() throws Exception {
|
public void testMongoDbCsv() throws Exception {
|
||||||
try (final CSVParser parser = CSVParser.parse("\"a a\",b,c" + LF + "d,e,f", CSVFormat.MONGODB_CSV)) {
|
try (final CSVParser parser = CSVParser.parse("\"a a\",b,c" + LF + "d,e,f", CSVFormat.MONGODB_CSV)) {
|
||||||
final Iterator<CSVRecord> itr1 = parser.iterator();
|
final Iterator<CSVRecord> itr1 = parser.iterator();
|
||||||
|
@ -921,24 +920,20 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNewCSVParserNullReaderFormat() throws Exception {
|
public void testNewCSVParserNullReaderFormat() {
|
||||||
try (final CSVParser parser = new CSVParser(null, CSVFormat.DEFAULT)) {
|
assertThrows(IllegalArgumentException.class, () -> new CSVParser(null, CSVFormat.DEFAULT));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNewCSVParserReaderNullFormat() throws Exception {
|
public void testNewCSVParserReaderNullFormat() {
|
||||||
try (final CSVParser parser = new CSVParser(new StringReader(""), null)) {
|
assertThrows(IllegalArgumentException.class, () -> new CSVParser(new StringReader(""), null));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoHeaderMap() throws Exception {
|
public void testNoHeaderMap() throws Exception {
|
||||||
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT)) {
|
try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT)) {
|
||||||
Assert.assertNull(parser.getHeaderMap());
|
assertNull(parser.getHeaderMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,60 +970,56 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseFileNullFormat() throws Exception {
|
public void testParseFileNullFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse(new File("CSVFileParser/test.csv"), Charset.defaultCharset(), null)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse(new File("CSVFileParser/test.csv"), Charset.defaultCharset(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseNullFileFormat() throws Exception {
|
public void testParseNullFileFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseNullPathFormat() throws Exception {
|
public void testParseNullPathFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse((Path) null, Charset.defaultCharset(), CSVFormat.DEFAULT)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse((Path) null, Charset.defaultCharset(), CSVFormat.DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseNullStringFormat() throws Exception {
|
public void testParseNullStringFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse((String) null, CSVFormat.DEFAULT)) {
|
assertThrows(IllegalArgumentException.class, () -> CSVParser.parse((String) null, CSVFormat.DEFAULT));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseNullUrlCharsetFormat() throws Exception {
|
public void testParseNullUrlCharsetFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse((URL) null, Charset.defaultCharset(), CSVFormat.DEFAULT)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse((URL) null, Charset.defaultCharset(), CSVFormat.DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParserUrlNullCharsetFormat() throws Exception {
|
public void testParserUrlNullCharsetFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse(new URL("https://commons.apache.org"), null, CSVFormat.DEFAULT)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse(new URL("https://commons.apache.org"), null, CSVFormat.DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseStringNullFormat() throws Exception {
|
public void testParseStringNullFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse("csv data", (CSVFormat) null)) {
|
assertThrows(IllegalArgumentException.class, () -> CSVParser.parse("csv data", (CSVFormat) null));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testParseUrlCharsetNullFormat() throws Exception {
|
public void testParseUrlCharsetNullFormat() {
|
||||||
try (final CSVParser parser = CSVParser.parse(new URL("https://commons.apache.org"), Charset.defaultCharset(), null)) {
|
assertThrows(
|
||||||
Assert.fail("This test should have thrown an exception.");
|
IllegalArgumentException.class,
|
||||||
}
|
() -> CSVParser.parse(new URL("https://commons.apache.org"), Charset.defaultCharset(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1129,7 +1120,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testStartWithEmptyLinesThenHeaders() throws Exception {
|
public void testStartWithEmptyLinesThenHeaders() throws Exception {
|
||||||
final String[] codes = { "\r\n\r\n\r\nhello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n",
|
final String[] codes = { "\r\n\r\n\r\nhello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n",
|
||||||
"hello,\"\"\n\n\n" };
|
"hello,\"\"\n\n\n" };
|
||||||
|
@ -1156,7 +1147,7 @@ public class CSVParserTest {
|
||||||
assertEquals("1", record.get("X"));
|
assertEquals("1", record.get("X"));
|
||||||
assertEquals("2", record.get("Y"));
|
assertEquals("2", record.get("Y"));
|
||||||
assertEquals("3", record.get("Z"));
|
assertEquals("3", record.get("Z"));
|
||||||
Assert.assertEquals(3, record.size());
|
assertEquals(3, record.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1168,7 +1159,7 @@ public class CSVParserTest {
|
||||||
assertEquals("1", record.get("X"));
|
assertEquals("1", record.get("X"));
|
||||||
assertEquals("2", record.get("Y"));
|
assertEquals("2", record.get("Y"));
|
||||||
assertEquals("3", record.get("Z"));
|
assertEquals("3", record.get("Z"));
|
||||||
Assert.assertEquals(3, record.size());
|
assertEquals(3, record.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1185,7 +1176,7 @@ public class CSVParserTest {
|
||||||
final Iterator<CSVRecord> records = CSVFormat.RFC4180.parse(new StringReader(dqString)).iterator();
|
final Iterator<CSVRecord> records = CSVFormat.RFC4180.parse(new StringReader(dqString)).iterator();
|
||||||
final CSVRecord record = records.next();
|
final CSVRecord record = records.next();
|
||||||
assertFalse(records.hasNext());
|
assertFalse(records.hasNext());
|
||||||
Assert.assertEquals(3, record.size());
|
assertEquals(3, record.size());
|
||||||
assertEquals("aaa", record.get(0));
|
assertEquals("aaa", record.get(0));
|
||||||
assertEquals("b\"bb", record.get(1));
|
assertEquals("b\"bb", record.get(1));
|
||||||
assertEquals("ccc", record.get(2));
|
assertEquals("ccc", record.get(2));
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import static org.apache.commons.csv.Constants.CR;
|
import static org.apache.commons.csv.Constants.CR;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
@ -55,9 +56,8 @@ import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.h2.tools.SimpleResultSet;
|
import org.h2.tools.SimpleResultSet;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -578,12 +578,9 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidFormat() throws Exception {
|
public void testInvalidFormat() {
|
||||||
final CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR);
|
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(CR));
|
||||||
try (final CSVPrinter printer = new CSVPrinter(new StringWriter(), invalidFormat)) {
|
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -633,7 +630,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testJira135_part1() throws IOException {
|
public void testJira135_part1() throws IOException {
|
||||||
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
|
@ -649,7 +646,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testJira135_part2() throws IOException {
|
public void testJira135_part2() throws IOException {
|
||||||
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
|
@ -665,7 +662,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testJira135_part3() throws IOException {
|
public void testJira135_part3() throws IOException {
|
||||||
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
|
@ -681,7 +678,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testJira135All() throws IOException {
|
public void testJira135All() throws IOException {
|
||||||
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
|
@ -879,18 +876,14 @@ public class CSVPrinterTest {
|
||||||
assertEquals("\\N", CSVFormat.MYSQL.getNullString());
|
assertEquals("\\N", CSVFormat.MYSQL.getNullString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNewCsvPrinterAppendableNullFormat() throws Exception {
|
public void testNewCsvPrinterAppendableNullFormat() {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(new StringWriter(), null)) {
|
assertThrows(IllegalArgumentException.class, () -> new CSVPrinter(new StringWriter(), null));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testNewCsvPrinterNullAppendableFormat() throws Exception {
|
public void testNewCsvPrinterNullAppendableFormat() {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(null, CSVFormat.DEFAULT)) {
|
assertThrows(IllegalArgumentException.class, () -> new CSVPrinter(null, CSVFormat.DEFAULT));
|
||||||
Assert.fail("This test should have thrown an exception.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -942,7 +935,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testPostgreSqlCsvNullOutput() throws IOException {
|
public void testPostgreSqlCsvNullOutput() throws IOException {
|
||||||
Object[] s = new String[] { "NULL", null };
|
Object[] s = new String[] { "NULL", null };
|
||||||
CSVFormat format = CSVFormat.POSTGRESQL_CSV.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL);
|
CSVFormat format = CSVFormat.POSTGRESQL_CSV.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL);
|
||||||
|
@ -1045,7 +1038,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testPostgreSqlCsvTextOutput() throws IOException {
|
public void testPostgreSqlCsvTextOutput() throws IOException {
|
||||||
Object[] s = new String[] { "NULL", null };
|
Object[] s = new String[] { "NULL", null };
|
||||||
CSVFormat format = CSVFormat.POSTGRESQL_TEXT.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL);
|
CSVFormat format = CSVFormat.POSTGRESQL_TEXT.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL);
|
||||||
|
@ -1403,7 +1396,7 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testRandomMongoDbCsv() throws Exception {
|
public void testRandomMongoDbCsv() throws Exception {
|
||||||
doRandom(CSVFormat.MONGODB_CSV, ITERATIONS_FOR_RANDOM_TEST);
|
doRandom(CSVFormat.MONGODB_CSV, ITERATIONS_FOR_RANDOM_TEST);
|
||||||
}
|
}
|
||||||
|
@ -1414,19 +1407,19 @@ public class CSVPrinterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testRandomOracle() throws Exception {
|
public void testRandomOracle() throws Exception {
|
||||||
doRandom(CSVFormat.ORACLE, ITERATIONS_FOR_RANDOM_TEST);
|
doRandom(CSVFormat.ORACLE, ITERATIONS_FOR_RANDOM_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testRandomPostgreSqlCsv() throws Exception {
|
public void testRandomPostgreSqlCsv() throws Exception {
|
||||||
doRandom(CSVFormat.POSTGRESQL_CSV, ITERATIONS_FOR_RANDOM_TEST);
|
doRandom(CSVFormat.POSTGRESQL_CSV, ITERATIONS_FOR_RANDOM_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testRandomPostgreSqlText() throws Exception {
|
public void testRandomPostgreSqlText() throws Exception {
|
||||||
doRandom(CSVFormat.POSTGRESQL_TEXT, ITERATIONS_FOR_RANDOM_TEST);
|
doRandom(CSVFormat.POSTGRESQL_TEXT, ITERATIONS_FOR_RANDOM_TEST);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
@ -31,9 +32,8 @@ import java.util.TreeMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class CSVRecordTest {
|
public class CSVRecordTest {
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class CSVRecordTest {
|
||||||
private CSVRecord record, recordWithHeader;
|
private CSVRecord record, recordWithHeader;
|
||||||
private Map<String, Integer> headerMap;
|
private Map<String, Integer> headerMap;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
values = new String[] { "A", "B", "C" };
|
values = new String[] { "A", "B", "C" };
|
||||||
final String rowData = StringUtils.join(values, ',');
|
final String rowData = StringUtils.join(values, ',');
|
||||||
|
@ -73,35 +73,35 @@ public class CSVRecordTest {
|
||||||
assertEquals(values[2], recordWithHeader.get("third"));
|
assertEquals(values[2], recordWithHeader.get("third"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetStringInconsistentRecord() {
|
public void testGetStringInconsistentRecord() {
|
||||||
headerMap.put("fourth", Integer.valueOf(4));
|
headerMap.put("fourth", Integer.valueOf(4));
|
||||||
recordWithHeader.get("fourth");
|
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get("fourth"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test
|
||||||
public void testGetStringNoHeader() {
|
public void testGetStringNoHeader() {
|
||||||
record.get("first");
|
assertThrows(IllegalStateException.class, () -> record.get("first"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetUnmappedEnum() {
|
public void testGetUnmappedEnum() {
|
||||||
assertNull(recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
|
assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetUnmappedName() {
|
public void testGetUnmappedName() {
|
||||||
assertNull(recordWithHeader.get("fourth"));
|
assertThrows(IllegalArgumentException.class, () -> assertNull(recordWithHeader.get("fourth")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ArrayIndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testGetUnmappedNegativeInt() {
|
public void testGetUnmappedNegativeInt() {
|
||||||
assertNull(recordWithHeader.get(Integer.MIN_VALUE));
|
assertThrows(ArrayIndexOutOfBoundsException.class, () -> recordWithHeader.get(Integer.MIN_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ArrayIndexOutOfBoundsException.class)
|
@Test
|
||||||
public void testGetUnmappedPositiveInt() {
|
public void testGetUnmappedPositiveInt() {
|
||||||
assertNull(recordWithHeader.get(Integer.MAX_VALUE));
|
assertThrows(ArrayIndexOutOfBoundsException.class, () -> recordWithHeader.get(Integer.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -170,7 +170,7 @@ public class CSVRecordTest {
|
||||||
final ArrayList<String> list = new ArrayList<>(map.values());
|
final ArrayList<String> list = new ArrayList<>(map.values());
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
printer.printRecord(list);
|
printer.printRecord(list);
|
||||||
Assert.assertEquals("A,B,C,NewValue" + CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString());
|
assertEquals("A,B,C,NewValue" + CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +193,8 @@ public class CSVRecordTest {
|
||||||
try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','))) {
|
try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','))) {
|
||||||
final CSVRecord shortRec = parser.iterator().next();
|
final CSVRecord shortRec = parser.iterator().next();
|
||||||
final Map<String, String> map = shortRec.toMap();
|
final Map<String, String> map = shortRec.toMap();
|
||||||
assertNotNull("Map is not null.", map);
|
assertNotNull(map, "Map is not null.");
|
||||||
assertTrue("Map is empty.", map.isEmpty());
|
assertTrue(map.isEmpty(), "Map is empty.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ package org.apache.commons.csv;
|
||||||
|
|
||||||
import static org.apache.commons.csv.Constants.END_OF_STREAM;
|
import static org.apache.commons.csv.Constants.END_OF_STREAM;
|
||||||
import static org.apache.commons.csv.Constants.UNDEFINED;
|
import static org.apache.commons.csv.Constants.UNDEFINED;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,15 +28,16 @@ import static org.apache.commons.csv.Token.Type.EORECORD;
|
||||||
import static org.apache.commons.csv.Token.Type.TOKEN;
|
import static org.apache.commons.csv.Token.Type.TOKEN;
|
||||||
import static org.apache.commons.csv.TokenMatchers.hasContent;
|
import static org.apache.commons.csv.TokenMatchers.hasContent;
|
||||||
import static org.apache.commons.csv.TokenMatchers.matches;
|
import static org.apache.commons.csv.TokenMatchers.matches;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -45,7 +46,7 @@ public class LexerTest {
|
||||||
|
|
||||||
private CSVFormat formatWithEscaping;
|
private CSVFormat formatWithEscaping;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
formatWithEscaping = CSVFormat.DEFAULT.withEscape('\\');
|
formatWithEscaping = CSVFormat.DEFAULT.withEscape('\\');
|
||||||
}
|
}
|
||||||
|
@ -142,7 +143,7 @@ public class LexerTest {
|
||||||
"\n" + // 6c
|
"\n" + // 6c
|
||||||
"# Final comment\n"; // 7
|
"# Final comment\n"; // 7
|
||||||
final CSVFormat format = CSVFormat.DEFAULT.withCommentMarker('#').withIgnoreEmptyLines(false);
|
final CSVFormat format = CSVFormat.DEFAULT.withCommentMarker('#').withIgnoreEmptyLines(false);
|
||||||
assertFalse("Should not ignore empty lines", format.getIgnoreEmptyLines());
|
assertFalse(format.getIgnoreEmptyLines(), "Should not ignore empty lines");
|
||||||
|
|
||||||
try (final Lexer parser = createLexer(code, format)) {
|
try (final Lexer parser = createLexer(code, format)) {
|
||||||
assertThat(parser.nextToken(new Token()), matches(TOKEN, "1"));
|
assertThat(parser.nextToken(new Token()), matches(TOKEN, "1"));
|
||||||
|
@ -381,11 +382,11 @@ public class LexerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IOException.class)
|
@Test
|
||||||
public void testEscapingAtEOF() throws Exception {
|
public void testEscapingAtEOF() throws Exception {
|
||||||
final String code = "escaping at EOF is evil\\";
|
final String code = "escaping at EOF is evil\\";
|
||||||
try (final Lexer lexer = createLexer(code, formatWithEscaping)) {
|
try (final Lexer lexer = createLexer(code, formatWithEscaping)) {
|
||||||
lexer.nextToken(new Token());
|
assertThrows(IOException.class, () -> lexer.nextToken(new Token()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,17 @@ import static org.apache.commons.csv.TokenMatchers.hasContent;
|
||||||
import static org.apache.commons.csv.TokenMatchers.hasType;
|
import static org.apache.commons.csv.TokenMatchers.hasType;
|
||||||
import static org.apache.commons.csv.TokenMatchers.isReady;
|
import static org.apache.commons.csv.TokenMatchers.isReady;
|
||||||
import static org.apache.commons.csv.TokenMatchers.matches;
|
import static org.apache.commons.csv.TokenMatchers.matches;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TokenMatchersTest {
|
public class TokenMatchersTest {
|
||||||
|
|
||||||
private Token token;
|
private Token token;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
token = new Token();
|
token = new Token();
|
||||||
token.type = Token.Type.TOKEN;
|
token.type = Token.Type.TOKEN;
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
|
|
||||||
package org.apache.commons.csv;
|
package org.apache.commons.csv;
|
||||||
|
|
||||||
import java.util.List;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for test cases
|
* Utility methods for test cases
|
||||||
|
@ -38,9 +39,9 @@ final class Utils {
|
||||||
* @param actual the List of {@link CSVRecord} entries, each containing an array of values
|
* @param actual the List of {@link CSVRecord} entries, each containing an array of values
|
||||||
*/
|
*/
|
||||||
public static void compare(final String message, final String[][] expected, final List<CSVRecord> actual) {
|
public static void compare(final String message, final String[][] expected, final List<CSVRecord> actual) {
|
||||||
Assert.assertEquals(message+" - outer array size", expected.length, actual.size());
|
assertEquals(expected.length, actual.size(), message + " - outer array size");
|
||||||
for (int i = 0; i < expected.length; i++) {
|
for (int i = 0; i < expected.length; i++) {
|
||||||
Assert.assertArrayEquals(message + " (entry " + i + ")", expected[i], actual.get(i).values());
|
assertArrayEquals(expected[i], actual.get(i).values(), message + " (entry " + i + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.csv.issues;
|
package org.apache.commons.csv.issues;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVPrinter;
|
import org.apache.commons.csv.CSVPrinter;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class JiraCsv164Test {
|
public class JiraCsv164Test {
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class JiraCsv164Test {
|
||||||
printer.print("B");
|
printer.print("B");
|
||||||
}
|
}
|
||||||
final String s = out.toString();
|
final String s = out.toString();
|
||||||
assertTrue(s, s.contains(comment));
|
assertTrue(s.contains(comment), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,7 +51,7 @@ public class JiraCsv164Test {
|
||||||
printer.print("B");
|
printer.print("B");
|
||||||
}
|
}
|
||||||
final String s = out.toString();
|
final String s = out.toString();
|
||||||
assertTrue(s, s.contains(comment));
|
assertTrue(s.contains(comment), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.csv.issues;
|
package org.apache.commons.csv.issues;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -26,8 +28,7 @@ import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.apache.commons.csv.QuoteMode;
|
import org.apache.commons.csv.QuoteMode;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class JiraCsv167Test {
|
public class JiraCsv167Test {
|
||||||
|
|
||||||
|
@ -77,8 +78,8 @@ public class JiraCsv167Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comment lines are concatenated, in this example 4 lines become 2 comments.
|
// Comment lines are concatenated, in this example 4 lines become 2 comments.
|
||||||
Assert.assertEquals(totcomment, comments);
|
assertEquals(totcomment, comments);
|
||||||
Assert.assertEquals(totrecs, records); // records includes the header
|
assertEquals(totrecs, records); // records includes the header
|
||||||
}
|
}
|
||||||
|
|
||||||
private Reader getTestInput() {
|
private Reader getTestInput() {
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.csv.issues;
|
package org.apache.commons.csv.issues;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -24,8 +26,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class JiraCsv198Test {
|
public class JiraCsv198Test {
|
||||||
|
|
||||||
|
@ -34,12 +35,12 @@ public class JiraCsv198Test {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws UnsupportedEncodingException, IOException {
|
public void test() throws UnsupportedEncodingException, IOException {
|
||||||
final InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
|
final InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
|
||||||
Assert.assertNotNull(pointsOfReference);
|
assertNotNull(pointsOfReference);
|
||||||
try (@SuppressWarnings("resource")
|
try (@SuppressWarnings("resource")
|
||||||
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
|
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
|
||||||
for (final CSVRecord record : parser) {
|
for (final CSVRecord record : parser) {
|
||||||
final String locationType = record.get("location_type");
|
final String locationType = record.get("location_type");
|
||||||
Assert.assertNotNull(locationType);
|
assertNotNull(locationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.csv.issues;
|
package org.apache.commons.csv.issues;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVPrinter;
|
import org.apache.commons.csv.CSVPrinter;
|
||||||
import org.apache.commons.csv.QuoteMode;
|
import org.apache.commons.csv.QuoteMode;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JIRA: <a href="https://issues.apache.org/jira/browse/CSV-203">withNullString value is printed without quotes when QuoteMode.ALL is specified</a>
|
* JIRA: <a href="https://issues.apache.org/jira/browse/CSV-203">withNullString value is printed without quotes when QuoteMode.ALL is specified</a>
|
||||||
|
@ -38,7 +39,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString());
|
assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,7 +53,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
|
assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -65,7 +66,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
|
assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -79,7 +80,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
|
assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,7 +94,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
|
assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -107,7 +108,7 @@ public class JiraCsv203Test {
|
||||||
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
|
||||||
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString());
|
assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -122,6 +123,6 @@ public class JiraCsv203Test {
|
||||||
printer.printRecord(new Object[] { "", "Hello", "", "World" });
|
printer.printRecord(new Object[] { "", "Hello", "", "World" });
|
||||||
//printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
//printer.printRecord(new Object[] { null, "Hello", null, "World" });
|
||||||
}
|
}
|
||||||
Assert.assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString());
|
assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,8 +26,8 @@ import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.apache.commons.csv.QuoteMode;
|
import org.apache.commons.csv.QuoteMode;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests https://issues.apache.org/jira/browse/CSV-213
|
* Tests https://issues.apache.org/jira/browse/CSV-213
|
||||||
|
@ -37,7 +37,7 @@ import org.junit.Test;
|
||||||
* create a new Iterator you are only created a new view on the same position in the parser's stream. For the behavior
|
* create a new Iterator you are only created a new view on the same position in the parser's stream. For the behavior
|
||||||
* you want, you need to open a new CSVParser.
|
* you want, you need to open a new CSVParser.
|
||||||
*/
|
*/
|
||||||
@Ignore
|
@Disabled
|
||||||
public class JiraCsv213Test {
|
public class JiraCsv213Test {
|
||||||
|
|
||||||
private void createEndChannel(final File csvFile) {
|
private void createEndChannel(final File csvFile) {
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.commons.csv.issues;
|
package org.apache.commons.csv.issues;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -26,8 +28,7 @@ import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVPrinter;
|
import org.apache.commons.csv.CSVPrinter;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class JiraCvs249Test {
|
public class JiraCvs249Test {
|
||||||
|
|
||||||
|
@ -48,8 +49,8 @@ public class JiraCvs249Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
records.forEach(record -> {
|
records.forEach(record -> {
|
||||||
Assert.assertEquals("foo \\", record.get(0));
|
assertEquals("foo \\", record.get(0));
|
||||||
Assert.assertEquals("bar", record.get(1));
|
assertEquals("bar", record.get(1));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import java.util.zip.GZIPInputStream;
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests performance.
|
* Tests performance.
|
||||||
|
@ -47,7 +47,7 @@ public class PerformanceTest {
|
||||||
|
|
||||||
private static final File BIG_FILE = new File(System.getProperty("java.io.tmpdir"), "worldcitiespop.txt");
|
private static final File BIG_FILE = new File(System.getProperty("java.io.tmpdir"), "worldcitiespop.txt");
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws FileNotFoundException, IOException {
|
public static void setUpClass() throws FileNotFoundException, IOException {
|
||||||
if (BIG_FILE.exists()) {
|
if (BIG_FILE.exists()) {
|
||||||
System.out.println(String.format("Found test fixture %s: %,d bytes.", BIG_FILE, BIG_FILE.length()));
|
System.out.println(String.format("Found test fixture %s: %,d bytes.", BIG_FILE, BIG_FILE.length()));
|
||||||
|
|
Loading…
Reference in New Issue