1
1
package com .fasterxml .jackson .dataformat .csv .deser ;
2
2
3
3
import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
4
- import com . fasterxml . jackson . core . JsonProcessingException ;
4
+
5
5
import com .fasterxml .jackson .databind .ObjectReader ;
6
6
import com .fasterxml .jackson .dataformat .csv .CsvMapper ;
7
7
import com .fasterxml .jackson .dataformat .csv .CsvParser ;
8
- import org . junit . Test ;
8
+ import com . fasterxml . jackson . dataformat . csv . ModuleTestBase ;
9
9
10
10
import java .io .IOException ;
11
11
12
- import static org .junit .Assert .*;
13
-
14
12
/**
15
- * Test for {@link CsvParser.Feature#EMPTY_STRING_AS_NULL}
13
+ * Tests for {@link CsvParser.Feature#EMPTY_STRING_AS_NULL}
14
+ * ({@code dataformats-text#7}).
16
15
*/
17
- public class EmptyStringAsNullTest {
18
-
19
-
16
+ public class EmptyStringAsNullTest
17
+ extends ModuleTestBase
18
+ {
20
19
@ JsonPropertyOrder ({"firstName" , "middleName" , "lastName" })
21
20
static class TestUser {
22
21
public String firstName , middleName , lastName ;
23
22
}
24
23
25
- @ Test
26
- public void givenFeatureDisabledByDefault_whenColumnIsEmptyString_thenParseAsEmptyString () throws IOException {
24
+ /*
25
+ /**********************************************************
26
+ /* Test methods
27
+ /**********************************************************
28
+ */
29
+
30
+ private final CsvMapper MAPPER = mapperForCsv ();
31
+
32
+ public void testDefaultParseAsEmptyString () throws IOException {
27
33
// setup test data
28
34
TestUser expectedTestUser = new TestUser ();
29
35
expectedTestUser .firstName = "Grace" ;
30
36
expectedTestUser .middleName = "" ;
31
37
expectedTestUser .lastName = "Hopper" ;
32
- CsvMapper csvMapper = CsvMapper .builder ().build ();
33
- ObjectReader objectReader = csvMapper .readerFor (TestUser .class ).with (csvMapper .schemaFor (TestUser .class ));
38
+ ObjectReader objectReader = MAPPER .readerFor (TestUser .class ).with (MAPPER .schemaFor (TestUser .class ));
34
39
String csv = "Grace,,Hopper" ;
35
40
36
41
// execute
@@ -43,14 +48,16 @@ public void givenFeatureDisabledByDefault_whenColumnIsEmptyString_thenParseAsEmp
43
48
assertEquals (expectedTestUser .lastName , actualTestUser .lastName );
44
49
}
45
50
46
- @ Test
47
- public void givenFeatureEnabled_whenColumnIsEmptyString_thenParseAsNull () throws IOException {
51
+ public void testSimpleParseEmptyStringAsNull () throws IOException {
48
52
// setup test data
49
53
TestUser expectedTestUser = new TestUser ();
50
54
expectedTestUser .firstName = "Grace" ;
51
55
expectedTestUser .lastName = "Hopper" ;
52
- CsvMapper csvMapper = CsvMapper .builder ().enable (CsvParser .Feature .EMPTY_STRING_AS_NULL ).build ();
53
- ObjectReader objectReader = csvMapper .readerFor (TestUser .class ).with (csvMapper .schemaFor (TestUser .class ));
56
+
57
+ ObjectReader objectReader = MAPPER
58
+ .readerFor (TestUser .class )
59
+ .with (MAPPER .schemaFor (TestUser .class ))
60
+ .with (CsvParser .Feature .EMPTY_STRING_AS_NULL );
54
61
String csv = "Grace,,Hopper" ;
55
62
56
63
// execute
0 commit comments