From b65859bdb3123e80cc210d966d0c8a8559433265 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 31 Dec 2024 17:53:30 -0800 Subject: [PATCH] Fix unit tests --- .../csv/failing/UnicodeCSVRead497Test.java | 2 +- .../javaprop/NumberDeserWithPropsTest.java | 1 - .../dataformat/toml/ComplianceValidTest.java | 20 +++++++++---------- .../dataformat/toml/LongTokenTest.java | 4 ++-- yaml/src/test/java/perf/YAMLDeserPerf.java | 1 - .../ParseBooleanLikeWordsAsStringsTest.java | 12 +++++------ .../yaml/fuzz/FuzzYAMLReadTest.java | 2 +- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/failing/UnicodeCSVRead497Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/failing/UnicodeCSVRead497Test.java index 3708e5793..444ddaf7f 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/failing/UnicodeCSVRead497Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/failing/UnicodeCSVRead497Test.java @@ -25,6 +25,6 @@ public void testUnicodeAtEnd() throws Exception assertNotNull(o); assertTrue(o.isArray()); assertEquals(1, o.size()); - assertEquals(o.get(0).textValue(), doc); + assertEquals(o.get(0).stringValue(), doc); } } diff --git a/properties/src/test/java/tools/jackson/dataformat/javaprop/NumberDeserWithPropsTest.java b/properties/src/test/java/tools/jackson/dataformat/javaprop/NumberDeserWithPropsTest.java index 0ff8015d5..122e910cd 100644 --- a/properties/src/test/java/tools/jackson/dataformat/javaprop/NumberDeserWithPropsTest.java +++ b/properties/src/test/java/tools/jackson/dataformat/javaprop/NumberDeserWithPropsTest.java @@ -9,7 +9,6 @@ import tools.jackson.core.StreamReadConstraints; import tools.jackson.core.exc.StreamConstraintsException; -import tools.jackson.databind.DatabindException; import tools.jackson.databind.ObjectMapper; // Tests copied from databind "JDKNumberDeserTest" (only a small subset) diff --git a/toml/src/test/java/tools/jackson/dataformat/toml/ComplianceValidTest.java b/toml/src/test/java/tools/jackson/dataformat/toml/ComplianceValidTest.java index 37c1acb2f..de275a8a7 100644 --- a/toml/src/test/java/tools/jackson/dataformat/toml/ComplianceValidTest.java +++ b/toml/src/test/java/tools/jackson/dataformat/toml/ComplianceValidTest.java @@ -77,14 +77,14 @@ private static JsonNode mapFromComplianceNode(ObjectNode expected) { final JsonNodeCreator nodeF = expected; if (expected.has("type") && expected.has("value")) { JsonNode value = expected.get("value"); - switch (expected.get("type").textValue()) { + switch (expected.get("type").stringValue()) { case "string": // for some reason, the compliance tests escape these values. this makes some tests fail right now - return nodeF.textNode(value.textValue()); + return nodeF.textNode(value.stringValue()); case "integer": - return nodeF.numberNode(NumberInput.parseBigInteger(value.textValue(), false)); + return nodeF.numberNode(NumberInput.parseBigInteger(value.stringValue(), false)); case "float": - switch (value.textValue()) { + switch (value.stringValue()) { case "inf": return nodeF.numberNode(Double.POSITIVE_INFINITY); case "-inf": @@ -92,21 +92,21 @@ private static JsonNode mapFromComplianceNode(ObjectNode expected) { case "nan": return nodeF.numberNode(Double.NaN); default: - return nodeF.numberNode(NumberInput.parseBigDecimal(value.textValue(), false)); + return nodeF.numberNode(NumberInput.parseBigDecimal(value.stringValue(), false)); } case "boolean": - return nodeF.booleanNode(Boolean.parseBoolean(value.textValue())); + return nodeF.booleanNode(Boolean.parseBoolean(value.stringValue())); case "offset datetime": - return nodeF.pojoNode(OffsetDateTime.parse(value.textValue())); + return nodeF.pojoNode(OffsetDateTime.parse(value.stringValue())); case "local datetime": case "datetime-local": - return nodeF.pojoNode(LocalDateTime.parse(value.textValue())); + return nodeF.pojoNode(LocalDateTime.parse(value.stringValue())); case "local date": case "date": - return nodeF.pojoNode(LocalDate.parse(value.textValue())); + return nodeF.pojoNode(LocalDate.parse(value.stringValue())); case "local time": case "time": - return nodeF.pojoNode(LocalTime.parse(value.textValue())); + return nodeF.pojoNode(LocalTime.parse(value.stringValue())); case "array": ArrayNode array = nodeF.arrayNode(); for (JsonNode member : value) { diff --git a/toml/src/test/java/tools/jackson/dataformat/toml/LongTokenTest.java b/toml/src/test/java/tools/jackson/dataformat/toml/LongTokenTest.java index e98bf8aba..2d3db03f8 100644 --- a/toml/src/test/java/tools/jackson/dataformat/toml/LongTokenTest.java +++ b/toml/src/test/java/tools/jackson/dataformat/toml/LongTokenTest.java @@ -109,7 +109,7 @@ public void string() throws IOException { } toml.append("'"); ObjectNode node = (ObjectNode) NO_LIMITS_MAPPER.readTree(toml.toString()); - Assert.assertEquals(SCALE, node.get("foo").textValue().length()); + Assert.assertEquals(SCALE, node.get("foo").stringValue().length()); } @Test @@ -124,6 +124,6 @@ public void stringEscapes() throws IOException { ObjectNode node = TomlParser.parse(FACTORY, testIOContext(), TomlWriteFeature.INTERNAL_PROHIBIT_INTERNAL_BUFFER_ALLOCATE, new StringReader(toml.toString())); - Assert.assertEquals(SCALE, node.get("foo").textValue().length()); + Assert.assertEquals(SCALE, node.get("foo").stringValue().length()); } } diff --git a/yaml/src/test/java/perf/YAMLDeserPerf.java b/yaml/src/test/java/perf/YAMLDeserPerf.java index 3fc98723d..34960c410 100644 --- a/yaml/src/test/java/perf/YAMLDeserPerf.java +++ b/yaml/src/test/java/perf/YAMLDeserPerf.java @@ -3,7 +3,6 @@ import tools.jackson.core.*; import tools.jackson.databind.JavaType; import tools.jackson.databind.ObjectMapper; -import tools.jackson.databind.type.TypeFactory; import tools.jackson.dataformat.yaml.YAMLMapper; /** diff --git a/yaml/src/test/java/tools/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java b/yaml/src/test/java/tools/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java index bbed2ae00..5aa5be48b 100644 --- a/yaml/src/test/java/tools/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java +++ b/yaml/src/test/java/tools/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java @@ -28,16 +28,16 @@ public void testParseBooleanLikeWordsAsStringDefault() throws Exception JsonNode root = mapper.readTree(YAML); assertEquals(root.get("one").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("one").textValue(), "Yes"); + assertEquals(root.get("one").stringValue(), "Yes"); assertEquals(root.get("two").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("two").textValue(), "No"); + assertEquals(root.get("two").stringValue(), "No"); assertEquals(root.get("three").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("three").textValue(), "Off"); + assertEquals(root.get("three").stringValue(), "Off"); assertEquals(root.get("four").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("four").textValue(), "On"); + assertEquals(root.get("four").stringValue(), "On"); assertEquals(root.get("five").getNodeType(), JsonNodeType.BOOLEAN); assertTrue(root.get("five").booleanValue()); @@ -46,9 +46,9 @@ public void testParseBooleanLikeWordsAsStringDefault() throws Exception assertFalse(root.get("six").booleanValue()); assertEquals(root.get("seven").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("seven").textValue(), "Y"); + assertEquals(root.get("seven").stringValue(), "Y"); assertEquals(root.get("eight").getNodeType(), JsonNodeType.STRING); - assertEquals(root.get("eight").textValue(), "N"); + assertEquals(root.get("eight").stringValue(), "N"); } } diff --git a/yaml/src/test/java/tools/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java b/yaml/src/test/java/tools/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java index 76353ad78..e0b2bc1e0 100644 --- a/yaml/src/test/java/tools/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java +++ b/yaml/src/test/java/tools/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java @@ -41,7 +41,7 @@ public void testNumberDecoding50052() throws Exception // tag basically ignored, returned as empty String otken JsonNode n = YAML_MAPPER.readTree("!!int"); assertEquals(JsonToken.VALUE_STRING, n.asToken()); - assertEquals("", n.textValue()); + assertEquals("", n.stringValue()); } // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50339