Skip to content

Commit

Permalink
Minor test refactoring (move writer-side test under writer tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 6, 2025
1 parent 713401b commit bb65a01
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.csv.*;

public class NullReadTest extends ModuleTestBase
{
final CsvMapper MAPPER = mapperForCsv();

@JsonPropertyOrder({ "prop1", "prop2", "prop3" })
static class Pojo83 {
public String prop1;
public String prop2;
public int prop3;

protected Pojo83() { }
public Pojo83(String a, String b, int c) {
prop1 = a;
prop2 = b;
prop3 = c;
}
}

// [dataformats-text#330]: empty String as null
static class Row330 {
public Integer id;
Expand All @@ -35,24 +16,9 @@ static class Row330 {
/* Test methods
/**********************************************************************
*/

public void testNullIssue83() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvSchema schema = mapper.schemaFor(Pojo83.class);
final ObjectWriter writer = mapper.writer(schema);

List<Pojo83> list = Arrays.asList(
new Pojo83("foo", "bar", 123),
null,
new Pojo83("test", "abc", 42));

String expectedCsv = "foo,bar,123\ntest,abc,42\n";
String actualCsv = writer.writeValueAsString(list);

assertEquals(expectedCsv, actualCsv);
}

private final CsvMapper MAPPER = mapperForCsv();

// For [dataformat-csv#72]: recognize "null value" for reading too
public void testReadNullValue72() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testNullsOnObjectArrayWrites2Col() throws Exception

final String csv = out.toString().trim();

assertEquals("\"a\",\"b\"\n" +
assertEquals("a,b\n" +
",2\n" +
",\n" +
"1,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.csv.*;

Expand All @@ -15,6 +16,27 @@ public static class Nullable {
public String a, b, c, d;
}

// for [jackson-dataformat-csv#83]
@JsonPropertyOrder({ "prop1", "prop2", "prop3" })
static class Pojo83 {
public String prop1;
public String prop2;
public int prop3;

protected Pojo83() { }
public Pojo83(String a, String b, int c) {
prop1 = a;
prop2 = b;
prop3 = c;
}
}

/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

private final CsvMapper csv = mapperForCsv();

public void testObjectWithNullMembersToString() throws Exception {
Expand Down Expand Up @@ -81,6 +103,21 @@ public void testCustomNullValue() throws Exception
assertEquals("id,n/a\n", result);
}

// [dataformat-csv#83]
public void testNullIssue83() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvSchema schema = mapper.schemaFor(Pojo83.class);
final ObjectWriter writer = mapper.writer(schema);

List<Pojo83> list = Arrays.asList(
new Pojo83("foo", "bar", 123),
null,
new Pojo83("test", "abc", 42));
String actualCsv = writer.writeValueAsString(list);
assertEquals("foo,bar,123\ntest,abc,42\n", actualCsv);
}

public void testNullFieldsOfListsContainedByMainLevelListIssue106() throws Exception
{
CsvMapper mapper = mapperForCsv();
Expand Down

0 comments on commit bb65a01

Please sign in to comment.