44import com .fasterxml .jackson .core .type .TypeReference ;
55import com .fasterxml .jackson .databind .JavaType ;
66import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import org .junit .jupiter .api .Test ;
78
89import java .util .ArrayList ;
910import java .util .List ;
1011
11- public class JsonNullableBasicTest extends ModuleTestBase {
12+ import static org .junit .jupiter .api .Assertions .*;
13+
14+ class JsonNullableBasicTest extends ModuleTestBase {
1215
1316 public static final class JsonNullableData {
1417 public JsonNullable <String > myString ;
@@ -58,37 +61,42 @@ public static class ContainedImpl implements Contained { }
5861
5962 private final ObjectMapper MAPPER = mapperWithModule ();
6063
61- public void testJsonNullableTypeResolution () throws Exception {
64+ @ Test
65+ void testJsonNullableTypeResolution () {
6266 // With 2.6, we need to recognize it as ReferenceType
6367 JavaType t = MAPPER .constructType (JsonNullable .class );
6468 assertNotNull (t );
6569 assertEquals (JsonNullable .class , t .getRawClass ());
6670 assertTrue (t .isReferenceType ());
6771 }
6872
69- public void testDeserAbsent () throws Exception {
73+ @ Test
74+ void testDeserAbsent () throws Exception {
7075 JsonNullable <?> value = MAPPER .readValue ("null" ,
7176 new TypeReference <JsonNullable <String >>() {
7277 });
7378 assertNull (value .get ());
7479 }
7580
76- public void testDeserSimpleString () throws Exception {
81+ @ Test
82+ void testDeserSimpleString () throws Exception {
7783 JsonNullable <?> value = MAPPER .readValue ("\" simpleString\" " ,
7884 new TypeReference <JsonNullable <String >>() {
7985 });
8086 assertTrue (value .isPresent ());
8187 assertEquals ("simpleString" , value .get ());
8288 }
8389
84- public void testDeserInsideObject () throws Exception {
90+ @ Test
91+ void testDeserInsideObject () throws Exception {
8592 JsonNullableData data = MAPPER .readValue ("{\" myString\" :\" simpleString\" }" ,
8693 JsonNullableData .class );
8794 assertTrue (data .myString .isPresent ());
8895 assertEquals ("simpleString" , data .myString .get ());
8996 }
9097
91- public void testDeserComplexObject () throws Exception {
98+ @ Test
99+ void testDeserComplexObject () throws Exception {
92100 TypeReference <JsonNullable <JsonNullableData >> type = new TypeReference <JsonNullable <JsonNullableData >>() {
93101 };
94102 JsonNullable <JsonNullableData > data = MAPPER .readValue (
@@ -98,7 +106,8 @@ public void testDeserComplexObject() throws Exception {
98106 assertEquals ("simpleString" , data .get ().myString .get ());
99107 }
100108
101- public void testDeserGeneric () throws Exception {
109+ @ Test
110+ void testDeserGeneric () throws Exception {
102111 TypeReference <JsonNullable <JsonNullableGenericData <String >>> type = new TypeReference <JsonNullable <JsonNullableGenericData <String >>>() {
103112 };
104113 JsonNullable <JsonNullableGenericData <String >> data = MAPPER .readValue (
@@ -108,62 +117,71 @@ public void testDeserGeneric() throws Exception {
108117 assertEquals ("simpleString" , data .get ().myData .get ());
109118 }
110119
111- public void testSerAbsent () throws Exception {
120+ @ Test
121+ void testSerAbsent () throws Exception {
112122 String value = MAPPER .writeValueAsString (JsonNullable .undefined ());
113123 assertEquals ("null" , value );
114124 }
115125
116- public void testSerSimpleString () throws Exception {
126+ @ Test
127+ void testSerSimpleString () throws Exception {
117128 String value = MAPPER .writeValueAsString (JsonNullable .of ("simpleString" ));
118129 assertEquals ("\" simpleString\" " , value );
119130 }
120131
121- public void testSerInsideObject () throws Exception {
132+ @ Test
133+ void testSerInsideObject () throws Exception {
122134 JsonNullableData data = new JsonNullableData ();
123135 data .myString = JsonNullable .of ("simpleString" );
124136 String value = MAPPER .writeValueAsString (data );
125137 assertEquals ("{\" myString\" :\" simpleString\" }" , value );
126138 }
127139
128- public void testSerComplexObject () throws Exception {
140+ @ Test
141+ void testSerComplexObject () throws Exception {
129142 JsonNullableData data = new JsonNullableData ();
130143 data .myString = JsonNullable .of ("simpleString" );
131144 String value = MAPPER .writeValueAsString (JsonNullable .of (data ));
132145 assertEquals ("{\" myString\" :\" simpleString\" }" , value );
133146 }
134147
135- public void testSerGeneric () throws Exception {
148+ @ Test
149+ void testSerGeneric () throws Exception {
136150 JsonNullableGenericData <String > data = new JsonNullableGenericData <String >();
137151 data .myData = JsonNullable .of ("simpleString" );
138152 String value = MAPPER .writeValueAsString (JsonNullable .of (data ));
139153 assertEquals ("{\" myData\" :\" simpleString\" }" , value );
140154 }
141155
142- public void testSerOptDefault () throws Exception {
156+ @ Test
157+ void testSerOptDefault () throws Exception {
143158 JsonNullableData data = new JsonNullableData ();
144159 data .myString = JsonNullable .undefined ();
145160 String value = mapperWithModule ().setSerializationInclusion (
146161 JsonInclude .Include .ALWAYS ).writeValueAsString (data );
147162 assertEquals ("{}" , value );
148163 }
149164
150- public void testSerOptNull () throws Exception {
165+ @ Test
166+ void testSerOptNull () throws Exception {
151167 JsonNullableData data = new JsonNullableData ();
152168 data .myString = null ;
153169 String value = mapperWithModule ().setSerializationInclusion (
154170 JsonInclude .Include .NON_NULL ).writeValueAsString (data );
155171 assertEquals ("{}" , value );
156172 }
157173
158- public void testSerOptNullNulled () throws Exception {
174+ @ Test
175+ void testSerOptNullNulled () throws Exception {
159176 JsonNullableData data = new JsonNullableData ();
160177 data .myString = JsonNullable .of (null );
161178 String value = mapperWithModule ().setSerializationInclusion (
162179 JsonInclude .Include .NON_NULL ).writeValueAsString (data );
163180 assertEquals ("{\" myString\" :null}" , value );
164181 }
165182
166- public void testSerOptAbsent () throws Exception {
183+ @ Test
184+ void testSerOptAbsent () throws Exception {
167185 final JsonNullableData data = new JsonNullableData ();
168186 data .myString = JsonNullable .undefined ();
169187
@@ -183,23 +201,26 @@ public void testSerOptAbsent() throws Exception {
183201 assertEquals ("{}" , mapper .writeValueAsString (data ));
184202 }
185203
186- public void testSerOptAbsentNull () throws Exception {
204+ @ Test
205+ void testSerOptAbsentNull () throws Exception {
187206 JsonNullableData data = new JsonNullableData ();
188207 data .myString = JsonNullable .of (null );
189208 String value = mapperWithModule ().setSerializationInclusion (
190209 JsonInclude .Include .NON_ABSENT ).writeValueAsString (data );
191210 assertEquals ("{\" myString\" :null}" , value );
192211 }
193212
194- public void testSerOptNonEmpty () throws Exception {
213+ @ Test
214+ void testSerOptNonEmpty () throws Exception {
195215 JsonNullableData data = new JsonNullableData ();
196216 data .myString = null ;
197217 String value = mapperWithModule ().setSerializationInclusion (
198218 JsonInclude .Include .NON_EMPTY ).writeValueAsString (data );
199219 assertEquals ("{}" , value );
200220 }
201221
202- public void testWithTypingEnabled () throws Exception {
222+ @ Test
223+ void testWithTypingEnabled () throws Exception {
203224 final ObjectMapper objectMapper = mapperWithModule ();
204225 // ENABLE TYPING
205226 objectMapper
@@ -214,7 +235,8 @@ public void testWithTypingEnabled() throws Exception {
214235 assertEquals (myData .myString , deserializedMyData .myString );
215236 }
216237
217- public void testObjectId () throws Exception {
238+ @ Test
239+ void testObjectId () throws Exception {
218240 final Unit input = new Unit ();
219241 input .link (input );
220242 String json = MAPPER .writeValueAsString (input );
@@ -226,7 +248,8 @@ public void testObjectId() throws Exception {
226248 assertSame (result , base );
227249 }
228250
229- public void testJsonNullableCollection () throws Exception {
251+ @ Test
252+ void testJsonNullableCollection () throws Exception {
230253
231254 TypeReference <List <JsonNullable <String >>> typeReference = new TypeReference <List <JsonNullable <String >>>() {
232255 };
@@ -242,17 +265,18 @@ public void testJsonNullableCollection() throws Exception {
242265 List <JsonNullable <String >> result = MAPPER .readValue (str , typeReference );
243266 assertEquals (list .size (), result .size ());
244267 for (int i = 0 ; i < list .size (); ++i ) {
245- assertEquals ("Entry #" + i , list .get (i ), result .get (i ));
268+ assertEquals (list .get (i ), result .get (i ), "Entry #" + i );
246269 }
247270 }
248271
249- public void testDeserNull () throws Exception {
272+ @ Test
273+ void testDeserNull () throws Exception {
250274 JsonNullable <?> value = MAPPER .readValue ("\" \" " , new TypeReference <JsonNullable <Integer >>() {});
251275 assertFalse (value .isPresent ());
252276 }
253277
254- public void testPolymorphic () throws Exception
255- {
278+ @ Test
279+ void testPolymorphic () throws Exception {
256280 final Container dto = new Container ();
257281 dto .contained = JsonNullable .of ((Contained ) new ContainedImpl ());
258282
0 commit comments