Skip to content

Commit

Permalink
Add unit test from FasterXML#33 to failing unit tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Magrath committed Mar 11, 2014
1 parent e3275c5 commit eff9210
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ target
*.iml
*.ipr
*.iws
.idea
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstractions.
</scm>

<properties>
<jackson.version.annotations>2.3.0</jackson.version.annotations>
<jackson.version.annotations>2.4.0-SNAPSHOT</jackson.version.annotations>
<jackson.version.core>2.4.0-SNAPSHOT</jackson.version.core>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/dataformat/csv</packageVersion.dir>
Expand Down Expand Up @@ -77,6 +77,12 @@ abstractions.
<version>${jackson.version.annotations}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit eff9210

Please sign in to comment.