From eff9210a1352d1bbb75d858e6d4eaad185ca2d0e Mon Sep 17 00:00:00 2001 From: Paul Magrath Date: Tue, 11 Mar 2014 11:44:14 +0000 Subject: [PATCH] Add unit test from #33 to failing unit tests folder --- .gitignore | 1 + pom.xml | 8 +- .../dataformat/csv/failing/TestWriter.java | 77 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/fasterxml/jackson/dataformat/csv/failing/TestWriter.java diff --git a/.gitignore b/.gitignore index 84914ec..c3bde80 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ target *.iml *.ipr *.iws +.idea diff --git a/pom.xml b/pom.xml index d125c30..7bc9327 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ abstractions. - 2.3.0 + 2.4.0-SNAPSHOT 2.4.0-SNAPSHOT com/fasterxml/jackson/dataformat/csv @@ -77,6 +77,12 @@ abstractions. ${jackson.version.annotations} test + + com.google.guava + guava + 16.0.1 + test + diff --git a/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/TestWriter.java b/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/TestWriter.java new file mode 100644 index 0000000..52641b0 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/TestWriter.java @@ -0,0 +1,77 @@ +package com.fasterxml.jackson.dataformat.csv.failing; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvSchema; +import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import java.lang.String;import static org.junit.Assert.assertEquals; + +public class TestWriter { + + @Test + public void testWrite_NoNulls() throws JsonProcessingException { + final CsvSchema.Builder csvSchemaBuilder = new CsvSchema.Builder(); + csvSchemaBuilder.addColumn("timestamp", CsvSchema.ColumnType.STRING); + csvSchemaBuilder.addColumn("value", CsvSchema.ColumnType.NUMBER); + csvSchemaBuilder.addColumn("id", CsvSchema.ColumnType.STRING); + final CsvSchema schema = csvSchemaBuilder.build(); + final ObjectWriter writer = new CsvMapper().writer().withSchema(schema); + + final String string = writer.writeValueAsString( + ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00", + "value", 42, "id", "hello")); + + assertEquals("\"2014-03-10T23:32:47+00:00\",42,hello\n", string); + } + + @Test + public void testWrite_NullFirstColumn() throws JsonProcessingException { + final CsvSchema.Builder csvSchemaBuilder = new CsvSchema.Builder(); + csvSchemaBuilder.addColumn("timestamp", CsvSchema.ColumnType.STRING); + csvSchemaBuilder.addColumn("value", CsvSchema.ColumnType.NUMBER); + csvSchemaBuilder.addColumn("id", CsvSchema.ColumnType.STRING); + final CsvSchema schema = csvSchemaBuilder.build(); + final ObjectWriter writer = new CsvMapper().writer().withSchema(schema); + + final String string = writer.writeValueAsString( + ImmutableMap.of("value", 42, "id", "hello")); + + assertEquals(",42,hello\n", string); + } + + @Test + public void testWrite_NullSecondColumn() throws JsonProcessingException { + final CsvSchema.Builder csvSchemaBuilder = new CsvSchema.Builder(); + csvSchemaBuilder.addColumn("timestamp", CsvSchema.ColumnType.STRING); + csvSchemaBuilder.addColumn("value", CsvSchema.ColumnType.NUMBER); + csvSchemaBuilder.addColumn("id", CsvSchema.ColumnType.STRING); + final CsvSchema schema = csvSchemaBuilder.build(); + final ObjectWriter writer = new CsvMapper().writer().withSchema(schema); + + final String string = writer.writeValueAsString( + ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00", + "id", "hello")); + + assertEquals("\"2014-03-10T23:32:47+00:00\",,hello\n", string); + } + + @Test + public void testWrite_NullThirdColumn() throws JsonProcessingException { + final CsvSchema.Builder csvSchemaBuilder = new CsvSchema.Builder(); + csvSchemaBuilder.addColumn("timestamp", CsvSchema.ColumnType.STRING); + csvSchemaBuilder.addColumn("value", CsvSchema.ColumnType.NUMBER); + csvSchemaBuilder.addColumn("id", CsvSchema.ColumnType.STRING); + final CsvSchema schema = csvSchemaBuilder.build(); + final ObjectWriter writer = new CsvMapper().writer().withSchema(schema); + + final String string = writer.writeValueAsString( + ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00", + "value", 42)); + + assertEquals("\"2014-03-10T23:32:47+00:00\",42\n", string); + } + +}