55
66import org .junit .jupiter .api .function .Executable ;
77import 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 ;
811
912import tools .jackson .databind .ObjectMapper ;
1013import tools .jackson .databind .ObjectReader ;
@@ -29,39 +32,51 @@ static class Wrapper {
2932 public Wrapper () { }
3033 }
3134
32- @ Test
33- public void testDeserializationAsString01_oneBased () throws Exception
35+ @ ParameterizedTest
36+ @ EnumSource (Month .class )
37+ public void testDeserializationAsString01_oneBased (Month expectedMonth ) throws Exception
3438 {
35- assertEquals (Month .JANUARY , readerForOneBased ().readValue ("\" 1\" " ));
39+ int monthNum = expectedMonth .getValue ();
40+ assertEquals (expectedMonth , readerForOneBased ().readValue ("\" " + monthNum + '"' ));
3641 }
3742
38- @ Test
39- public void testDeserializationAsString01_zeroBased () throws Exception
43+ @ ParameterizedTest
44+ @ EnumSource (Month .class )
45+ public void testDeserializationAsString01_zeroBased (Month expectedMonth ) throws Exception
4046 {
41- assertEquals (Month .FEBRUARY , readerForZeroBased ().readValue ("\" 1\" " ));
47+ int monthNum = expectedMonth .ordinal ();
48+ assertEquals (expectedMonth , readerForZeroBased ().readValue ("\" " + monthNum + '"' ));
4249 }
4350
4451
45- @ Test
46- public void testDeserializationAsString02_oneBased () throws Exception
52+ @ ParameterizedTest
53+ @ EnumSource (Month .class )
54+ public void testDeserializationAsString02_oneBased (Month month ) throws Exception
4755 {
48- assertEquals (Month . JANUARY , readerForOneBased ().readValue ("\" JANUARY \" " ));
56+ assertEquals (month , readerForOneBased ().readValue ("\" " + month . name () + '"' ));
4957 }
5058
51- @ Test
52- public void testDeserializationAsString02_zeroBased () throws Exception
59+ @ ParameterizedTest
60+ @ EnumSource (Month .class )
61+ public void testDeserializationAsString02_zeroBased (Month month ) throws Exception
5362 {
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 + '"' ;
5976 assertError (
60- () -> readerForOneBased ().readValue (" \" notamonth \" " ),
77+ () -> readerForOneBased ().readValue (value ),
6178 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
6580 );
6681 }
6782
0 commit comments