Skip to content

Commit 054d856

Browse files
committed
Replace deprecated textValue
1 parent dcb04a9 commit 054d856

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

src/test/java/com/saasquatch/jsonschemainferrer/JsonSchemaInferrerOptionsTest.java

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static com.saasquatch.jsonschemainferrer.TestJunkDrawer.toStringSet;
66
import static java.nio.charset.StandardCharsets.UTF_8;
77
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertFalse;
89
import static org.junit.jupiter.api.Assertions.assertNotNull;
910
import static org.junit.jupiter.api.Assertions.assertNull;
1011
import 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
}

src/test/java/com/saasquatch/jsonschemainferrer/JsonSchemaInferrerTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testSimpleExample() {
4444
{
4545
final ObjectNode schema = JsonSchemaInferrer.newBuilder().build().inferForSample(simple);
4646
assertTrue(schema.hasNonNull("$schema"));
47-
assertTrue(schema.path("$schema").textValue().contains("-04"));
47+
assertTrue(schema.path("$schema").stringValue().contains("-04"));
4848
assertTrue(schema.hasNonNull("type"));
4949
}
5050
{
@@ -53,7 +53,7 @@ public void testSimpleExample() {
5353
.build()
5454
.inferForSample(simple);
5555
assertTrue(schema.hasNonNull("$schema"));
56-
assertTrue(schema.path("$schema").textValue().contains("-06"));
56+
assertTrue(schema.path("$schema").stringValue().contains("-06"));
5757
assertTrue(schema.hasNonNull("type"));
5858
}
5959
{
@@ -63,21 +63,21 @@ public void testSimpleExample() {
6363
.inferForSample(simple);
6464
assertTrue(schema.hasNonNull("properties"));
6565
assertTrue(schema.path("properties").isObject());
66-
assertEquals("integer", schema.path("properties").path("id").path("type").textValue());
67-
assertEquals("string", schema.path("properties").path("slug").path("type").textValue());
68-
assertEquals("boolean", schema.path("properties").path("admin").path("type").textValue());
69-
assertEquals("null", schema.path("properties").path("avatar").path("type").textValue());
70-
assertEquals("string", schema.path("properties").path("date").path("type").textValue());
71-
assertEquals("date-time", schema.path("properties").path("date").path("format").textValue());
72-
assertEquals("object", schema.path("properties").path("article").path("type").textValue());
66+
assertEquals("integer", schema.path("properties").path("id").path("type").stringValue());
67+
assertEquals("string", schema.path("properties").path("slug").path("type").stringValue());
68+
assertEquals("boolean", schema.path("properties").path("admin").path("type").stringValue());
69+
assertEquals("null", schema.path("properties").path("avatar").path("type").stringValue());
70+
assertEquals("string", schema.path("properties").path("date").path("type").stringValue());
71+
assertEquals("date-time", schema.path("properties").path("date").path("format").stringValue());
72+
assertEquals("object", schema.path("properties").path("article").path("type").stringValue());
7373
assertTrue(schema.path("properties").path("article").isObject());
7474
assertEquals("string", schema.path("properties").path("article").path("properties")
75-
.path("title").path("type").textValue());
75+
.path("title").path("type").stringValue());
7676
assertEquals("string", schema.path("properties").path("article").path("properties")
77-
.path("description").path("type").textValue());
77+
.path("description").path("type").stringValue());
7878
assertEquals("string", schema.path("properties").path("article").path("properties")
79-
.path("body").path("type").textValue());
80-
assertEquals("array", schema.path("properties").path("comments").path("type").textValue());
79+
.path("body").path("type").stringValue());
80+
assertEquals("array", schema.path("properties").path("comments").path("type").stringValue());
8181
assertTrue(schema.path("properties").path("comments").path("items").isObject());
8282
assertEquals(ImmutableSet.of("string", "null"), toStringSet(schema.path("properties")
8383
.path("comments").path("items").path("properties").path("body").path("type")));
@@ -92,11 +92,11 @@ public void testAdvancedExample() {
9292
assertTrue(schema.path("items").isObject());
9393
assertTrue(schema.path("items").path("properties").path("tags").isObject());
9494
assertEquals("integer",
95-
schema.path("items").path("properties").path("id").path("type").textValue());
95+
schema.path("items").path("properties").path("id").path("type").stringValue());
9696
assertEquals("number",
97-
schema.path("items").path("properties").path("price").path("type").textValue());
97+
schema.path("items").path("properties").path("price").path("type").stringValue());
9898
assertEquals("number", schema.path("items").path("properties").path("dimensions")
99-
.path("properties").path("length").path("type").textValue());
99+
.path("properties").path("length").path("type").stringValue());
100100
}
101101
}
102102

src/test/java/com/saasquatch/jsonschemainferrer/TestJunkDrawer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ private TestJunkDrawer() {}
2828
new com.fasterxml.jackson.databind.ObjectMapper();
2929

3030
public static Set<String> toStringSet(JsonNode arrayNode) {
31-
return Streams.stream(arrayNode)
32-
.map(JsonNode::textValue)
31+
return arrayNode.valueStream()
32+
.map(JsonNode::stringValue)
3333
.collect(ImmutableSet.toImmutableSet());
3434
}
3535

0 commit comments

Comments
 (0)