5
5
6
6
import org .junit .jupiter .api .function .Executable ;
7
7
import org .junit .jupiter .api .Test ;
8
+ import org .junit .jupiter .params .ParameterizedTest ;
9
+ import org .junit .jupiter .params .provider .CsvSource ;
10
+ import org .junit .jupiter .params .provider .EnumSource ;
8
11
9
12
import tools .jackson .databind .ObjectMapper ;
10
13
import tools .jackson .databind .ObjectReader ;
@@ -29,39 +32,51 @@ static class Wrapper {
29
32
public Wrapper () { }
30
33
}
31
34
32
- @ Test
33
- public void testDeserializationAsString01_oneBased () throws Exception
35
+ @ ParameterizedTest
36
+ @ EnumSource (Month .class )
37
+ public void testDeserializationAsString01_oneBased (Month expectedMonth ) throws Exception
34
38
{
35
- assertEquals (Month .JANUARY , readerForOneBased ().readValue ("\" 1\" " ));
39
+ int monthNum = expectedMonth .getValue ();
40
+ assertEquals (expectedMonth , readerForOneBased ().readValue ("\" " + monthNum + '"' ));
36
41
}
37
42
38
- @ Test
39
- public void testDeserializationAsString01_zeroBased () throws Exception
43
+ @ ParameterizedTest
44
+ @ EnumSource (Month .class )
45
+ public void testDeserializationAsString01_zeroBased (Month expectedMonth ) throws Exception
40
46
{
41
- assertEquals (Month .FEBRUARY , readerForZeroBased ().readValue ("\" 1\" " ));
47
+ int monthNum = expectedMonth .ordinal ();
48
+ assertEquals (expectedMonth , readerForZeroBased ().readValue ("\" " + monthNum + '"' ));
42
49
}
43
50
44
51
45
- @ Test
46
- public void testDeserializationAsString02_oneBased () throws Exception
52
+ @ ParameterizedTest
53
+ @ EnumSource (Month .class )
54
+ public void testDeserializationAsString02_oneBased (Month month ) throws Exception
47
55
{
48
- assertEquals (Month . JANUARY , readerForOneBased ().readValue ("\" JANUARY \" " ));
56
+ assertEquals (month , readerForOneBased ().readValue ("\" " + month . name () + '"' ));
49
57
}
50
58
51
- @ Test
52
- public void testDeserializationAsString02_zeroBased () throws Exception
59
+ @ ParameterizedTest
60
+ @ EnumSource (Month .class )
61
+ public void testDeserializationAsString02_zeroBased (Month month ) throws Exception
53
62
{
54
- assertEquals (Month .JANUARY , readerForZeroBased ().readValue ("\" JANUARY\" " ));
55
- }
56
-
57
- @ Test
58
- public void testBadDeserializationAsString01_oneBased () {
63
+ assertEquals (month , readerForOneBased ().readValue ("\" " + month .name () + '"' ));
64
+ }
65
+
66
+ @ ParameterizedTest
67
+ @ CsvSource ({
68
+ "notamonth , 'Cannot deserialize value of type `java.time.Month` from String \" notamonth\" : not one of the values accepted for Enum class:'" ,
69
+ "JANUAR , 'Cannot deserialize value of type `java.time.Month` from String \" JANUAR\" : not one of the values accepted for Enum class:'" ,
70
+ "march , 'Cannot deserialize value of type `java.time.Month` from String \" march\" : not one of the values accepted for Enum class:'" ,
71
+ "0 , 'Month number 0 not allowed for 1-based Month.'" ,
72
+ "13 , 'Month number 13 not allowed for 1-based Month.'" ,
73
+ })
74
+ public void testBadDeserializationAsString01_oneBased (String monthSpec , String expectedMessage ) {
75
+ String value = "\" " + monthSpec + '"' ;
59
76
assertError (
60
- () -> readerForOneBased ().readValue (" \" notamonth \" " ),
77
+ () -> readerForOneBased ().readValue (value ),
61
78
InvalidFormatException .class ,
62
- // Order of enumerated values not stable, so don't check:
63
- "Cannot deserialize value of type `java.time.Month` from String \" notamonth\" :"
64
- +" not one of the values accepted for Enum class: ["
79
+ expectedMessage
65
80
);
66
81
}
67
82
0 commit comments