-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/SkipEmptyLines174Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.fasterxml.jackson.dataformat.csv.failing; | ||
|
||
import java.io.*; | ||
import java.util.Random; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.dataformat.csv.*; | ||
|
||
public class SkipEmptyLines174Test extends ModuleTestBase | ||
{ | ||
private final static CsvMapper MAPPER = new CsvMapper(); | ||
|
||
@JsonPropertyOrder({ "timestamp", "random" }) | ||
static class Row { | ||
private int timestamp; | ||
private String random; | ||
|
||
public int getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(int timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public String getRandom() { | ||
return random; | ||
} | ||
|
||
public void setRandom(String random) { | ||
this.random = random; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Row{timestamp=" + timestamp + ", random='" + random + "'}"; | ||
} | ||
} | ||
|
||
public void testEmptyLines174() throws Exception | ||
{ | ||
String doc = generateCsvFile(); | ||
ObjectReader objectReader = MAPPER | ||
.enable(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readerFor(Row.class) | ||
.with(MAPPER.schemaFor(Row.class)); | ||
int lineCount = 0; | ||
MappingIterator<Row> iterator = objectReader.readValues(doc); | ||
Row data = null; | ||
while (iterator.hasNext()) { | ||
++lineCount; | ||
try { | ||
data = iterator.next(); | ||
} catch (Exception e) { | ||
// System.out.println(lineCount + " : " + data); | ||
fail("Failed on row #"+lineCount+", previous row: "+data); | ||
} | ||
} | ||
iterator.close(); | ||
} | ||
|
||
private String generateCsvFile() throws Exception { | ||
final StringWriter sw = new StringWriter(50000); | ||
int lineCount = 0; | ||
final Random rnd = new Random(); | ||
|
||
while (lineCount < 4000) { | ||
sw.append("\"" + System.currentTimeMillis()/1000 + "\",\"" + randomString(rnd) + "\"\n"); | ||
++lineCount; | ||
} | ||
return sw.toString(); | ||
} | ||
|
||
private String randomString(Random rnd) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < 10; ++i) { | ||
sb.append((char) ('A' + (rnd.nextInt() & 0xF))); | ||
} | ||
return sb.toString(); | ||
} | ||
} |