Skip to content

Commit 8c80ceb

Browse files
committed
Merge branch '2.13'
2 parents 7aab5d0 + cbae0c7 commit 8c80ceb

File tree

5 files changed

+116
-109
lines changed

5 files changed

+116
-109
lines changed

csv/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ abstractions.
4141
<artifactId>jackson-annotations</artifactId>
4242
</dependency>
4343

44-
<!-- and for testing -->
45-
<dependency>
46-
<groupId>com.google.guava</groupId>
47-
<artifactId>guava</artifactId>
48-
<version>27.1-jre</version>
49-
<scope>test</scope>
50-
</dependency>
5144
</dependencies>
5245

5346
<build>

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ModuleTestBase.java

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.nio.charset.StandardCharsets;
44
import java.util.Arrays;
5+
import java.util.LinkedHashMap;
56
import java.util.List;
67
import java.util.Locale;
78
import java.util.Map;
@@ -229,6 +230,15 @@ protected String aposToQuotes(String json) {
229230
return json.replace("'", "\"");
230231
}
231232

233+
protected static Map<String, Object> mapOf(Object...strings)
234+
{
235+
final Map<String, Object> map = new LinkedHashMap<>();
236+
for (int i = 0, end = strings.length; i < end; i += 2) {
237+
map.put(strings[i].toString(), strings[i+1]);
238+
}
239+
return map;
240+
}
241+
232242
protected void assertToken(JsonToken expToken, JsonToken actToken) {
233243
if (actToken != expToken) {
234244
fail("Expected token "+expToken+", current token "+actToken);

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/BasicCSVParserTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import com.fasterxml.jackson.databind.*;
1414
import com.fasterxml.jackson.dataformat.csv.*;
15-
import com.google.common.collect.Lists;
1615

1716
import static org.junit.Assert.assertArrayEquals;
1817

@@ -40,13 +39,15 @@ public static class Point {
4039

4140
final CsvMapper MAPPER = mapperForCsv();
4241

43-
public void testSimpleExplicit() throws Exception {
42+
public void testSimpleExplicit() throws Exception
43+
{
4444
ObjectReader r = MAPPER.reader(SIMPLE_SCHEMA);
4545
_testSimpleExplicit(r, false);
4646
_testSimpleExplicit(r, true);
4747
}
4848

49-
private void _testSimpleExplicit(ObjectReader r, boolean useBytes) throws Exception {
49+
private void _testSimpleExplicit(ObjectReader r, boolean useBytes) throws Exception
50+
{
5051
r = r.forType(FiveMinuteUser.class);
5152
FiveMinuteUser user;
5253
final String INPUT = "Bob,Robertson,MALE,AQIDBAU=,false\n";
@@ -421,7 +422,7 @@ public void testStrictColumnReturnsExpectedData()
421422
String CSV = "x,y,z\n1,2,3\n4,5,6\n7,8,9";
422423

423424
final MappingIterator<Point> iter = MAPPER.readerFor(Point.class).with(schema).readValues(CSV);
424-
final ArrayList<Point> values = Lists.newArrayList(iter);
425+
final List<Point> values = iter.readAll(new ArrayList<Point>());
425426
assertEquals(3, values.size());
426427
assertEquals(1, values.get(0).x);
427428
assertEquals(2, values.get(0).y.intValue());

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java

+12-22
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,50 @@
44

55
import com.fasterxml.jackson.dataformat.csv.*;
66

7-
import com.google.common.collect.ImmutableMap;
8-
9-
import org.junit.Test;
10-
11-
import java.lang.String;
12-
13-
// [Issue#33]
7+
// [dataformats-text#33]
148
public class TestWriterWithMissingValues extends ModuleTestBase
159
{
1610
private final CsvSchema SCHEMA = new CsvSchema.Builder()
1711
.addColumn("timestamp", CsvSchema.ColumnType.STRING)
1812
.addColumn("value", CsvSchema.ColumnType.NUMBER)
1913
.addColumn("id", CsvSchema.ColumnType.STRING)
2014
.build();
21-
final ObjectWriter WRITER = new CsvMapper().writer().with(SCHEMA);
22-
23-
@Test
15+
private final CsvMapper MAPPER = mapperForCsv();
16+
final ObjectWriter WRITER = MAPPER.writer().with(SCHEMA);
17+
2418
public void testWrite_NoNulls() {
2519
final String csv = WRITER.writeValueAsString(
26-
ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
20+
mapOf("timestamp", "2014-03-10T23:32:47+00:00",
2721
"value", 42, "id", "hello"));
2822

2923
assertEquals("\"2014-03-10T23:32:47+00:00\",42,hello\n", csv);
3024
}
3125

32-
@Test
3326
public void testWrite_NullFirstColumn() {
3427
final String csv = WRITER.writeValueAsString(
35-
ImmutableMap.of("value", 42, "id", "hello"));
28+
mapOf("value", 42, "id", "hello"));
3629
assertEquals(",42,hello\n", csv);
3730
}
3831

39-
@Test
4032
public void testWrite_NullSecondColumn() {
4133
final String csv = WRITER.writeValueAsString(
42-
ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
34+
mapOf("timestamp", "2014-03-10T23:32:47+00:00",
4335
"id", "hello"));
4436

4537
assertEquals("\"2014-03-10T23:32:47+00:00\",,hello\n", csv);
4638
}
4739

48-
@Test
4940
public void testWrite_NullThirdColumn()
5041
{
51-
CsvMapper mapper = new CsvMapper();
52-
assertFalse(mapper.tokenStreamFactory().isEnabled(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS));
53-
String csv = mapper.writer(SCHEMA).writeValueAsString(
54-
ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
42+
assertFalse(MAPPER.tokenStreamFactory().isEnabled(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS));
43+
String csv = MAPPER.writer(SCHEMA).writeValueAsString(
44+
mapOf("timestamp", "2014-03-10T23:32:47+00:00",
5545
"value", 42));
5646

5747
assertEquals("\"2014-03-10T23:32:47+00:00\",42,\n", csv);
58-
ObjectWriter w = mapper.writer().with(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS);
48+
ObjectWriter w = MAPPER.writer().with(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS);
5949
csv = w.with(SCHEMA).writeValueAsString(
60-
ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
50+
mapOf("timestamp", "2014-03-10T23:32:47+00:00",
6151
"value", 42));
6252
assertEquals("\"2014-03-10T23:32:47+00:00\",42\n", csv);
6353
}

0 commit comments

Comments
 (0)