Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 10, 2020
1 parent 8f06b66 commit b38eece
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 67 deletions.
@@ -1,6 +1,8 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvParser;
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;

Expand All @@ -15,6 +17,61 @@ public class SkipBlankLines15Test extends ModuleTestBase {
private static final String CSV_WITH_FIRST_BLANK_LINE = "\n1,\"xyz\"\ntrue,\n";
private static final String CSV_WITH_TRAILING_BLANK_LINES = "1,\"xyz\"\ntrue,\n \n\n";

@JsonPropertyOrder({ "age", "name", "cute" })
protected static class Entry {
public int age;
public String name;
public boolean cute;
}

// for [dataformats-text#15]: Allow skipping of empty lines
public void testSkipEmptyLinesFeature() throws Exception
{
final String CSV = "1,\"xyz\"\n\ntrue,\n";

CsvMapper mapper = mapperForCsv();

// First, verify default behavior:

String[][] rows = mapper
.readerFor(String[][].class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValue(CSV);
assertEquals(3, rows.length);
String[] row;

row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);

row = rows[1];
assertEquals(1, row.length);
assertEquals("", row[0]);

row = rows[2];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);

// when wrapped as an array, we'll get array of Lists:
rows = mapper.readerFor(String[][].class)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValue(CSV);

assertEquals(2, rows.length);
row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);

row = rows[1];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);
}

public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled() throws Exception {
String[][] rows = mapperForCsvAsArray().readValue(CSV_WITH_EMPTY_LINE);
// First, verify default behavior:
Expand Down

This file was deleted.

0 comments on commit b38eece

Please sign in to comment.