55import static com .saasquatch .jsonschemainferrer .TestJunkDrawer .toStringSet ;
66import static java .nio .charset .StandardCharsets .UTF_8 ;
77import static org .junit .jupiter .api .Assertions .assertEquals ;
8+ import static org .junit .jupiter .api .Assertions .assertFalse ;
89import static org .junit .jupiter .api .Assertions .assertNotNull ;
910import static org .junit .jupiter .api .Assertions .assertNull ;
1011import static org .junit .jupiter .api .Assertions .assertSame ;
@@ -85,68 +86,68 @@ public void testFormatInferrers() {
8586 assertThrows (NullPointerException .class ,
8687 () -> FormatInferrers .chained (FormatInferrers .dateTime (), null ));
8788 assertSame (FormatInferrers .dateTime (), FormatInferrers .chained (FormatInferrers .dateTime ()));
88- assertNull (JsonSchemaInferrer .newBuilder ()
89+ assertFalse (JsonSchemaInferrer .newBuilder ()
8990 .addFormatInferrers (FormatInferrers .dateTime ())
9091 .setSpecVersion (SpecVersion .DRAFT_07 )
9192 .build ()
9293 .inferForSample (jnf .stringNode ("aaaaaaaaa" ))
93- .path ("format" ).textValue ());
94+ .path ("format" ).isString ());
9495 assertEquals ("date-time" , JsonSchemaInferrer .newBuilder ()
9596 .addFormatInferrers (FormatInferrers .dateTime ())
9697 .build ()
9798 .inferForSample (jnf .stringNode (Instant .now ().toString ()))
98- .path ("format" ).textValue ());
99- assertNull (JsonSchemaInferrer .newBuilder ()
99+ .path ("format" ).stringValue ());
100+ assertFalse (JsonSchemaInferrer .newBuilder ()
100101 .addFormatInferrers (FormatInferrers .dateTime ())
101102 .setSpecVersion (SpecVersion .DRAFT_06 )
102103 .build ()
103104 .inferForSample (jnf .stringNode ("1900-01-01" ))
104- .path ("format" ).textValue ());
105+ .path ("format" ).isString ());
105106 assertEquals ("date" , JsonSchemaInferrer .newBuilder ()
106107 .addFormatInferrers (FormatInferrers .dateTime ())
107108 .setSpecVersion (SpecVersion .DRAFT_07 )
108109 .build ()
109110 .inferForSample (jnf .stringNode ("1900-01-01" ))
110- .path ("format" ).textValue ());
111- assertNull (JsonSchemaInferrer .newBuilder ()
111+ .path ("format" ).stringValue ());
112+ assertFalse (JsonSchemaInferrer .newBuilder ()
112113 .addFormatInferrers (FormatInferrers .dateTime ())
113114 .setSpecVersion (SpecVersion .DRAFT_06 )
114115 .build ()
115116 .inferForSample (jnf .stringNode ("20:20:39" ))
116- .path ("format" ).textValue ());
117+ .path ("format" ).isString ());
117118 assertEquals ("time" , JsonSchemaInferrer .newBuilder ()
118119 .addFormatInferrers (FormatInferrers .dateTime ())
119120 .setSpecVersion (SpecVersion .DRAFT_07 ).build ()
120121 .inferForSample (jnf .stringNode ("20:20:39+01:23" ))
121- .path ("format" ).textValue ());
122+ .path ("format" ).stringValue ());
122123 assertEquals ("time" , JsonSchemaInferrer .newBuilder ()
123124 .addFormatInferrers (FormatInferrers .dateTime ())
124125 .setSpecVersion (SpecVersion .DRAFT_07 ).build ()
125126 .inferForSample (jnf .stringNode ("20:20:39+00:00" ))
126- .path ("format" ).textValue ());
127+ .path ("format" ).stringValue ());
127128 {
128129 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
129130 .addFormatInferrers (FormatInferrers .chained (
130131 FormatInferrers .dateTime (), testStrLenFormatInferrer ))
131132 .build ();
132133 assertEquals ("date-time" , inferrer .inferForSample (jnf .stringNode (Instant .now ().toString ()))
133- .path ("format" ).textValue ());
134- assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).textValue ());
134+ .path ("format" ).stringValue ());
135+ assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).stringValue ());
135136 }
136137 {
137138 final JsonSchemaInferrer inferrer =
138139 JsonSchemaInferrer .newBuilder ().addFormatInferrers (FormatInferrers .ip ()).build ();
139140 assertEquals ("ipv4" ,
140- inferrer .inferForSample (jnf .stringNode ("12.34.56.78" )).path ("format" ).textValue ());
141+ inferrer .inferForSample (jnf .stringNode ("12.34.56.78" )).path ("format" ).stringValue ());
141142 assertEquals ("ipv6" ,
142143 inferrer .inferForSample (jnf .stringNode ("2001:0db8:85a3:0000:0000:8a2e:0370:7334" ))
143- .path ("format" ).textValue ());
144+ .path ("format" ).stringValue ());
144145 assertEquals ("ipv6" ,
145- inferrer .inferForSample (jnf .stringNode ("a::F" )).path ("format" ).textValue ());
146+ inferrer .inferForSample (jnf .stringNode ("a::F" )).path ("format" ).stringValue ());
146147 assertEquals ("ipv6" ,
147- inferrer .inferForSample (jnf .stringNode ("5::" )).path ("format" ).textValue ());
148+ inferrer .inferForSample (jnf .stringNode ("5::" )).path ("format" ).stringValue ());
148149 assertEquals ("ipv6" ,
149- inferrer .inferForSample (jnf .stringNode ("::" )).path ("format" ).textValue ());
150+ inferrer .inferForSample (jnf .stringNode ("::" )).path ("format" ).stringValue ());
150151 }
151152 {
152153 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
@@ -163,8 +164,8 @@ public void testFormatInferrers() {
163164 testStrLenFormatInferrer , FormatInferrers .dateTime ()))
164165 .build ();
165166 assertEquals (String .valueOf (dateTimeString .length ()),
166- inferrer .inferForSample (jnf .stringNode (dateTimeString )).path ("format" ).textValue ());
167- assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).textValue ());
167+ inferrer .inferForSample (jnf .stringNode (dateTimeString )).path ("format" ).stringValue ());
168+ assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).stringValue ());
168169 }
169170 }
170171
@@ -221,23 +222,23 @@ public void testIntegerTypePreference() {
221222 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
222223 .setIntegerTypePreference (IntegerTypePreference .IF_ALL )
223224 .build ();
224- assertEquals ("number" , inferrer .inferForSamples (intAndFloats ).path ("type" ).textValue ());
225- assertEquals ("integer" , inferrer .inferForSamples (intsOnly ).path ("type" ).textValue ());
225+ assertEquals ("number" , inferrer .inferForSamples (intAndFloats ).path ("type" ).stringValue ());
226+ assertEquals ("integer" , inferrer .inferForSamples (intsOnly ).path ("type" ).stringValue ());
226227 }
227228 {
228229 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
229230 .setIntegerTypePreference (IntegerTypePreference .IF_ANY )
230231 .build ();
231232 assertEquals (ImmutableSet .of ("integer" , "number" ),
232233 toStringSet (inferrer .inferForSamples (intAndFloats ).path ("type" )));
233- assertEquals ("integer" , inferrer .inferForSamples (intsOnly ).path ("type" ).textValue ());
234+ assertEquals ("integer" , inferrer .inferForSamples (intsOnly ).path ("type" ).stringValue ());
234235 }
235236 {
236237 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
237238 .setIntegerTypePreference (IntegerTypePreference .NEVER )
238239 .build ();
239- assertEquals ("number" , inferrer .inferForSamples (intAndFloats ).path ("type" ).textValue ());
240- assertEquals ("number" , inferrer .inferForSamples (intsOnly ).path ("type" ).textValue ());
240+ assertEquals ("number" , inferrer .inferForSamples (intAndFloats ).path ("type" ).stringValue ());
241+ assertEquals ("number" , inferrer .inferForSamples (intsOnly ).path ("type" ).stringValue ());
241242 }
242243 }
243244
@@ -253,7 +254,7 @@ public void testIntegerConfigCombo() {
253254 .setIntegerTypePreference (IntegerTypePreference .IF_ANY )
254255 .build ();
255256 assertEquals ("integer" ,
256- inferrer .inferForSample (jnf .numberNode (1.0 )).path ("type" ).textValue ());
257+ inferrer .inferForSample (jnf .numberNode (1.0 )).path ("type" ).stringValue ());
257258 }
258259 }
259260
@@ -309,7 +310,7 @@ public void testTitleAndDescriptionGenerator() {
309310 .setTitleDescriptionGenerator (TitleDescriptionGenerators .useFieldNamesAsTitles ())
310311 .build ();
311312 assertEquals ("fieldName" , inferrer .inferForSample (sample ).path ("properties" ).path ("fieldName" )
312- .get ("title" ).textValue ());
313+ .get ("title" ).stringValue ());
313314 }
314315 {
315316 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
@@ -343,7 +344,7 @@ public String generateTitle(@Nonnull TitleDescriptionGeneratorInput input) {
343344 })
344345 .build ();
345346 assertEquals ("FIELDNAME" , inferrer .inferForSample (sample ).path ("properties" ).path ("fieldName" )
346- .get ("title" ).textValue ());
347+ .get ("title" ).stringValue ());
347348 }
348349 {
349350 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
@@ -363,7 +364,7 @@ public String generateDescription(@Nonnull TitleDescriptionGeneratorInput input)
363364
364365 }).build ();
365366 assertEquals ("FIELDNAME" , inferrer .inferForSample (sample ).path ("properties" ).path ("fieldName" )
366- .get ("description" ).textValue ());
367+ .get ("description" ).stringValue ());
367368 }
368369 }
369370
@@ -390,13 +391,13 @@ public void testDefault() {
390391 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
391392 .setDefaultPolicy (DefaultPolicies .useFirstSamples ())
392393 .build ();
393- assertEquals ("a" , inferrer .inferForSamples (samples ).path ("default" ).textValue ());
394+ assertEquals ("a" , inferrer .inferForSamples (samples ).path ("default" ).stringValue ());
394395 }
395396 {
396397 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
397398 .setDefaultPolicy (DefaultPolicies .useLastSamples ())
398399 .build ();
399- assertEquals ("c" , inferrer .inferForSamples (samples ).path ("default" ).textValue ());
400+ assertEquals ("c" , inferrer .inferForSamples (samples ).path ("default" ).stringValue ());
400401 }
401402 }
402403
@@ -604,13 +605,14 @@ public void testEnum() {
604605 EnumExtractors .validEnum (DayOfWeek .class )))
605606 .build ();
606607 final ObjectNode schema =
607- inferrer .inferForSamples (Arrays .asList (jnf .stringNode ("TUESDAY" ), jnf .stringNode ("MARCH" )));
608+ inferrer .inferForSamples (
609+ Arrays .asList (jnf .stringNode ("TUESDAY" ), jnf .stringNode ("MARCH" )));
608610 final JsonNode anyOf = schema .get ("anyOf" );
609611 assertTrue (anyOf .isArray ());
610612 assertTrue (
611- stream (anyOf ).anyMatch (_anyOf -> _anyOf .path ("enum" ).get (0 ).textValue ().equals ("MARCH" )));
613+ stream (anyOf ).anyMatch (_anyOf -> _anyOf .path ("enum" ).get (0 ).stringValue ().equals ("MARCH" )));
612614 assertTrue (stream (anyOf )
613- .anyMatch (_anyOf -> _anyOf .path ("enum" ).get (0 ).textValue ().equals ("TUESDAY" )));
615+ .anyMatch (_anyOf -> _anyOf .path ("enum" ).get (0 ).stringValue ().equals ("TUESDAY" )));
614616 }
615617 {
616618 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
@@ -713,7 +715,7 @@ public void testStringLengthAndFormat() {
713715 final ObjectNode schema = inferrer .inferForSamples (samples );
714716 assertEquals (dateTimeString .length (), schema .path ("minLength" ).intValue ());
715717 assertEquals (dateTimeString .length (), schema .path ("maxLength" ).intValue ());
716- assertEquals ("date-time" , schema .path ("format" ).textValue ());
718+ assertEquals ("date-time" , schema .path ("format" ).stringValue ());
717719 }
718720
719721 @ Test
@@ -753,7 +755,7 @@ public void testFakeGenericFeature() {
753755 .addGenericSchemaFeatures (GenericSchemaFeatures .noOp ())
754756 .build ();
755757 final ObjectNode schema = inferrer .inferForSample (null );
756- assertEquals ("bar" , schema .path ("foo" ).textValue ());
758+ assertEquals ("bar" , schema .path ("foo" ).stringValue ());
757759 }
758760
759761}
0 commit comments