Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 21, 2014
1 parent cff1cee commit f4527f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testSimpleQuotesWithSpaces() throws Exception
System.err.println(" 3rd => ["+result.s3+"]");
*/

// start by trailing space trimming (easist one to work)
// start by trailing space trimming (easiest one to work)
assertEquals("abc", result.s1);
// follow by leading space trimming
assertEquals("def", result.s2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,44 @@
// [Issue#33]
public class TestWriter extends ModuleTestBase
{
private final CsvSchema SCHEMA = new CsvSchema.Builder()
.addColumn("timestamp", CsvSchema.ColumnType.STRING)
.addColumn("value", CsvSchema.ColumnType.NUMBER)
.addColumn("id", CsvSchema.ColumnType.STRING)
.build();
final ObjectWriter WRITER = new CsvMapper().writer().withSchema(SCHEMA);

@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(
final String csv = 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);
assertEquals("\"2014-03-10T23:32:47+00:00\",42,hello\n", csv);
}

@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(
final String csv = WRITER.writeValueAsString(
ImmutableMap.of("value", 42, "id", "hello"));

assertEquals(",42,hello\n", string);
assertEquals(",42,hello\n", csv);
}

@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(
final String csv = 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);
assertEquals("\"2014-03-10T23:32:47+00:00\",,hello\n", csv);
}

@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(
final String csv = 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);
assertEquals("\"2014-03-10T23:32:47+00:00\",42\n", csv);
}

}

0 comments on commit f4527f4

Please sign in to comment.