From 579691a287e0dc9b303b9f9f266a9f0a614dcc4d Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 10:35:02 +0900 Subject: [PATCH] [ JSTEP-10 ] Migrate `yaml` module tests to JUnit 5 (#528) --- .../yaml/ExceptionConversionTest.java | 5 +++ .../dataformat/yaml/FormatDetectionTest.java | 11 +++--- .../dataformat/yaml/ModuleTestBase.java | 9 +++-- .../yaml/MultipleDocumentsReadTest.java | 10 ++++- .../yaml/MultipleDocumentsWriteTest.java | 9 ++++- .../jackson/dataformat/yaml/TestVersions.java | 6 +++ .../DeeplyNestedYAMLReadWriteTest.java | 12 ++++-- .../dataformat/yaml/deser/BinaryReadTest.java | 14 ++++--- .../yaml/deser/DatabindAdvancedTest.java | 5 +++ .../yaml/deser/DatabindReadTest.java | 17 +++++--- .../yaml/deser/NameQuoting306Test.java | 5 +++ .../deser/NullFromEmptyString130Test.java | 9 +++-- .../yaml/deser/NumberAltIntRead71Test.java | 11 ++++++ .../yaml/deser/NumberDeserWithYAMLTest.java | 39 ++++++++++++------- .../ParseBooleanLikeWordsAsStringsTest.java | 10 +++-- .../yaml/deser/ParserAutoCloseTest.java | 20 ++++++---- .../yaml/deser/ParserDupHandlingTest.java | 15 +++++-- ...StreamingYAMLAnchorReplayingParseTest.java | 13 +++++-- .../yaml/deser/StreamingYAMLParseTest.java | 33 +++++++++++----- .../dataformat/yaml/deser/UTF8ReaderTest.java | 12 +++--- .../yaml/failing/ObjectIdWithTree2Test.java | 10 +++-- .../PolymorphicWithObjectId25Test.java | 11 +++--- .../yaml/failing/SimpleGeneration215Test.java | 10 +++-- .../yaml/failing/SimpleGeneration366Test.java | 14 ++++--- .../yaml/failing/UnicodeYAMLRead497Test.java | 7 +++- .../yaml/filter/StreamingDecoratorsTest.java | 13 +++++-- .../yaml/fuzz/FuzzYAMLRead63274Test.java | 5 ++- .../yaml/fuzz/FuzzYAMLRead65855Test.java | 6 ++- .../yaml/fuzz/FuzzYAMLReadTest.java | 13 +++++++ .../yaml/fuzz/FuzzYAML_65918_Test.java | 8 +++- .../yaml/misc/ObjectAndTypeId231Test.java | 9 ++++- .../yaml/misc/ObjectAndTypeId232Test.java | 13 ++++--- .../dataformat/yaml/misc/ObjectId123Test.java | 11 +++++- .../dataformat/yaml/misc/ObjectId63Test.java | 7 +++- .../dataformat/yaml/misc/ObjectIdTest.java | 14 +++++-- .../yaml/misc/PolymorphicDeductionTest.java | 5 ++- .../yaml/misc/ReservedNamesTest.java | 8 +++- .../yaml/misc/ReservedValuesTest.java | 8 +++- .../dataformat/yaml/ser/BinaryWriteTest.java | 13 +++++-- .../yaml/ser/CustomNodeStyleTest.java | 11 +++--- .../yaml/ser/CustomStringQuoting229Test.java | 14 ++++--- .../yaml/ser/DatabindWriteTest.java | 18 +++++---- .../yaml/ser/GeneratorAutoCloseTest.java | 23 ++++++----- .../yaml/ser/GeneratorFeature175Test.java | 10 +++-- .../yaml/ser/GeneratorFeature34Test.java | 10 +++-- .../yaml/ser/GeneratorFeatureTest.java | 17 ++++---- .../yaml/ser/GeneratorWithMinimizeTest.java | 21 ++++++++-- .../yaml/ser/GeneratorWithSplitLinesTest.java | 6 +++ .../yaml/ser/SimpleGenerationTest.java | 17 +++++--- .../dataformat/yaml/ser/UTF8WriterTest.java | 12 +++--- .../yaml/ser/dos/CyclicYAMLDataSerTest.java | 12 ++++-- .../yaml/testutil/PrefixInputDecorator.java | 7 +--- .../yaml/testutil/PrefixOutputDecorator.java | 5 +-- .../failure/JacksonTestFailureExpected.java | 8 ++-- ...JacksonTestFailureExpectedInterceptor.java | 6 +-- .../yaml/type/PolymorphicIdTest.java | 6 ++- .../dataformat/yaml/type/TypeIdTest.java | 14 +++++-- yaml/src/test/java/perf/YAMLDeserPerf.java | 7 +++- yaml/src/test/java/perf/YAMLSerPerf.java | 6 ++- 59 files changed, 465 insertions(+), 215 deletions(-) diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java index 200f77e71..8b9105e83 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java @@ -1,5 +1,9 @@ package com.fasterxml.jackson.dataformat.yaml; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + /** * Tests to try to ensure that SnakeYAML exceptions are not leaked, * both because they are problematic on OSGi runtimes (depending on @@ -8,6 +12,7 @@ */ public class ExceptionConversionTest extends ModuleTestBase { + @Test public void testSimpleParsingLeakage() throws Exception { YAMLMapper mapper = newObjectMapper(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/FormatDetectionTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/FormatDetectionTest.java index 5ba041ca3..51640d7cc 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/FormatDetectionTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/FormatDetectionTest.java @@ -1,11 +1,10 @@ package com.fasterxml.jackson.dataformat.yaml; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.format.DataFormatDetector; -import com.fasterxml.jackson.core.format.DataFormatMatcher; -import com.fasterxml.jackson.core.format.MatchStrength; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.format.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class FormatDetectionTest extends ModuleTestBase { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ModuleTestBase.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ModuleTestBase.java index 1de364935..e9e83c82b 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ModuleTestBase.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ModuleTestBase.java @@ -1,14 +1,15 @@ package com.fasterxml.jackson.dataformat.yaml; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Arrays; import com.fasterxml.jackson.core.*; -public abstract class ModuleTestBase extends junit.framework.TestCase +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public abstract class ModuleTestBase { /** * Slightly modified sample class from Jackson tutorial ("JacksonInFiveMinutes") diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsReadTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsReadTest.java index 9521d7015..637f57401 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsReadTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsReadTest.java @@ -2,17 +2,22 @@ import java.util.Map; -import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.MappingIterator; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class MultipleDocumentsReadTest extends ModuleTestBase { private final YAMLMapper MAPPER = newObjectMapper(); private final YAMLFactory YAML_F = MAPPER.getFactory(); + @Test public void testMultipleDocumentsViaParser() throws Exception { final String YAML = "num: 42\n" @@ -39,6 +44,7 @@ public void testMultipleDocumentsViaParser() throws Exception p.close(); } + @Test public void testMultipleDocumentsViaIterator() throws Exception { final String YAML = "num: 42\n" diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsWriteTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsWriteTest.java index f3cb25631..a51e91a7a 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsWriteTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/MultipleDocumentsWriteTest.java @@ -4,7 +4,12 @@ import java.util.Arrays; import java.util.Collections; -import com.fasterxml.jackson.databind.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SequenceWriter; + +import static org.junit.jupiter.api.Assertions.assertEquals; // for [dataformats-text#163] public class MultipleDocumentsWriteTest extends ModuleTestBase @@ -15,6 +20,7 @@ static class POJO163 { public POJO163(int v) { value = v; } } + @Test public void testWriteMultipleDocsBeans() throws Exception { ObjectMapper mapper = newObjectMapper(); @@ -29,6 +35,7 @@ public void testWriteMultipleDocsBeans() throws Exception assertEquals("---\nvalue: 42\n---\nvalue: 28", yaml); } + @Test public void testWriteMultipleDocsLists() throws Exception { ObjectMapper mapper = newObjectMapper(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TestVersions.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TestVersions.java index 82d3d3a35..71de96758 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TestVersions.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/TestVersions.java @@ -2,11 +2,16 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; +import static org.junit.jupiter.api.Assertions.*; + public class TestVersions extends ModuleTestBase { @SuppressWarnings("resource") + @Test public void testMapperVersions() throws IOException { YAMLFactory f = new YAMLFactory(); @@ -18,6 +23,7 @@ public void testMapperVersions() throws IOException assertVersion(jgen); } + @Test public void testDefaults() throws Exception { YAMLFactory f = new YAMLFactory(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/constraints/DeeplyNestedYAMLReadWriteTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/constraints/DeeplyNestedYAMLReadWriteTest.java index c92ccecb3..fbb4977e3 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/constraints/DeeplyNestedYAMLReadWriteTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/constraints/DeeplyNestedYAMLReadWriteTest.java @@ -1,12 +1,16 @@ package com.fasterxml.jackson.dataformat.yaml.constraints; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Unit test(s) for verifying handling of maximum nesting depth @@ -25,6 +29,7 @@ public class DeeplyNestedYAMLReadWriteTest .build() ); + @Test public void testDeepNestingRead() throws Exception { final String DOC = YAML_MAPPER.writeValueAsString(createDeepNestedDoc(11)); @@ -44,6 +49,7 @@ private void _testDeepNestingRead(JsonParser p) throws Exception } } + @Test public void testDeepNestingWrite() throws Exception { final JsonNode docRoot = createDeepNestedDoc(13); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java index d91212042..06fe22e6c 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java @@ -5,18 +5,21 @@ import java.util.Arrays; import java.util.Random; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class BinaryReadTest extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testBinaryViaTree() throws Exception { final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X1\n" @@ -43,10 +46,11 @@ public void testBinaryViaTree() throws Exception assertEquals(65, gif.length); final byte[] actualFileHeader = Arrays.copyOfRange(gif, 0, 6); final byte[] expectedFileHeader = new byte[]{'G', 'I', 'F', '8', '9', 'a'}; - Assert.assertArrayEquals(expectedFileHeader, actualFileHeader); + assertArrayEquals(expectedFileHeader, actualFileHeader); } // [dataformats-text#90] + @Test public void testReadLongBinary() throws Exception { final byte[] data = new byte[1000]; new Random(1234).nextBytes(data); @@ -65,7 +69,7 @@ public void testReadLongBinary() throws Exception { assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("data", parser.currentName()); assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, parser.nextToken()); - Assert.assertArrayEquals(data, parser.getBinaryValue()); + assertArrayEquals(data, parser.getBinaryValue()); assertEquals(JsonToken.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindAdvancedTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindAdvancedTest.java index 8043722e8..17bb7c006 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindAdvancedTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindAdvancedTest.java @@ -3,9 +3,13 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DatabindAdvancedTest extends ModuleTestBase { enum Size { SMALL, LARGE; } @@ -136,6 +140,7 @@ public Image(String uri, String title, int w, int h, Size s) /********************************************************** */ + @Test public void testReadComplexPojo() throws Exception { ObjectMapper mapper = newObjectMapper(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindReadTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindReadTest.java index b372cd1b7..bf6d968c2 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindReadTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/DatabindReadTest.java @@ -1,17 +1,17 @@ package com.fasterxml.jackson.dataformat.yaml.deser; import java.io.ByteArrayInputStream; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for checking functioning of the databinding * on top of YAML layer. @@ -74,6 +74,7 @@ public void setVersion(String version) { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testSimpleNested() throws Exception { final String YAML = @@ -100,6 +101,7 @@ public void testSimpleNested() throws Exception } + @Test public void testBasicUntyped() throws Exception { final String YAML = @@ -122,6 +124,7 @@ public void testBasicUntyped() throws Exception assertEquals(EXP, json); } + @Test public void testBasicPOJO() throws Exception { final String YAML = @@ -138,9 +141,10 @@ public void testBasicPOJO() throws Exception assertTrue(user.isVerified()); byte[] data = user.getUserImage(); assertNotNull(data); - Assert.assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, data); + assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, data); } + @Test public void testIssue1() throws Exception { final byte[] YAML = "firstName: Billy".getBytes("UTF-8"); @@ -150,6 +154,7 @@ public void testIssue1() throws Exception assertEquals("Billy", user.firstName); } + @Test public void testUUIDs() throws Exception { UUID uuid = new UUID(0, 0); @@ -159,6 +164,7 @@ public void testUUIDs() throws Exception assertEquals(uuid, result); } + @Test public void testEmptyBean() throws Exception { String yaml = MAPPER.writer() @@ -175,6 +181,7 @@ public void testEmptyBean() throws Exception } // [dataformats-text#205] + @Test public void testRenamingIssue205() throws Exception { final String YAML = diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NameQuoting306Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NameQuoting306Test.java index e26470b6e..f734b986d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NameQuoting306Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NameQuoting306Test.java @@ -3,15 +3,20 @@ import java.util.Collections; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + // for [dataformats-text#306] public class NameQuoting306Test extends ModuleTestBase { private final YAMLMapper MAPPER = newObjectMapper(); // for [dataformats-text#306] + @Test public void testComplexName() throws Exception { final String key = "SomeKey:\nOtherLine"; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NullFromEmptyString130Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NullFromEmptyString130Test.java index 9064216a3..34b75e5a5 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NullFromEmptyString130Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NullFromEmptyString130Test.java @@ -1,8 +1,10 @@ package com.fasterxml.jackson.dataformat.yaml.deser; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLParser; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.*; // [dataformats-text#130]: Easy enough to fix, if we choose to, // but due to timing cannot include in 2.12 (too close to release @@ -23,6 +25,7 @@ public void setValue(String str) { private final YAMLMapper MAPPER = newObjectMapper(); // [dataformats-text#130] + @Test public void testEmptyValueToNull130() throws Exception { // by default, empy Strings are coerced: diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberAltIntRead71Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberAltIntRead71Test.java index f212b0909..0c3ed5f78 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberAltIntRead71Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberAltIntRead71Test.java @@ -2,9 +2,13 @@ import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; + // [dataformats-text#71]: hex numbers // [dataformats-text#233]: also binary, octal (with/without underscores) public class NumberAltIntRead71Test extends ModuleTestBase @@ -24,6 +28,7 @@ static class BigHolder { private final ObjectMapper MAPPER = newObjectMapper(); // [dataformats-text#71] + @Test public void testDeserHexInt71() throws Exception { _verifyNumber(Integer.parseInt("48", 16), "0x48"); @@ -37,6 +42,7 @@ public void testDeserHexInt71() throws Exception _verifyNumber(new BigInteger("-11112222333344445555ACDC", 16), "-0x11112222333344445555acdc"); } + @Test public void testDeserHexUnderscores() throws Exception { _verifyNumber(Integer.parseInt("1F3", 16), "0x01_F3"); @@ -47,6 +53,7 @@ public void testDeserHexUnderscores() throws Exception _verifyNumber(-Long.parseLong("12345678c0", 16), "-0x12_3456_78c0"); } + @Test public void testDeserOctal() throws Exception { _verifyNumber(Integer.parseInt("24", 8), "024"); @@ -60,6 +67,7 @@ public void testDeserOctal() throws Exception _verifyNumber(new BigInteger("-123456771234567712345677", 8), "-0123456771234567712345677"); } + @Test public void testDeserOctalUnderscores() throws Exception { _verifyNumber(Integer.parseInt("24", 8), "0_24"); @@ -70,6 +78,7 @@ public void testDeserOctalUnderscores() throws Exception _verifyNumber(-Long.parseLong("1234567712345677", 8), "-01_234_567_712_345_677"); } + @Test public void testDeserBinary() throws Exception { _verifyNumber(Integer.parseInt("1010", 2), "0b1010"); @@ -77,6 +86,7 @@ public void testDeserBinary() throws Exception _verifyNumber(-Integer.parseInt("1010", 2), "-0b1010"); } + @Test public void testDeserBinaryUnderscores() throws Exception { _verifyNumber(Integer.parseInt("1010", 2), "0b10_10"); @@ -88,6 +98,7 @@ public void testDeserBinaryUnderscores() throws Exception // least not yet, due to likely backwards-compatibility issues // with IP numbers /* + @Test public void testDeserBase60() throws Exception { IntHolder result = MAPPER.readerFor(IntHolder.class) diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberDeserWithYAMLTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberDeserWithYAMLTest.java index db5fdc9f8..2137567ae 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberDeserWithYAMLTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/NumberDeserWithYAMLTest.java @@ -6,23 +6,15 @@ import java.util.List; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonUnwrapped; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.StreamReadConstraints; -import com.fasterxml.jackson.databind.DatabindException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.MismatchedInputException; +import com.fasterxml.jackson.dataformat.yaml.*; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import static org.junit.jupiter.api.Assertions.*; // Tests copied from databind "JDKNumberDeserTest": may need more clean up // work remove useless ones, make more YAML-y (YAML parsers can typically @@ -73,6 +65,7 @@ static class NestedBigDecimalHolder2784 { private final YAMLMapper MAPPER = newObjectMapper(); + @Test public void testNaN() throws Exception { Float result = MAPPER.readValue(" \"NaN\"", Float.class); @@ -85,6 +78,7 @@ public void testNaN() throws Exception assertEquals(Double.valueOf(Double.NaN), num); } + @Test public void testDoubleInf() throws Exception { Double result = MAPPER.readValue(" \""+Double.POSITIVE_INFINITY+"\"", Double.class); @@ -96,6 +90,7 @@ public void testDoubleInf() throws Exception // 01-Mar-2017, tatu: This is bit tricky... in some ways, mapping to "empty value" // would be best; but due to legacy reasons becomes `null` at this point + @Test public void testEmptyAsNumber() throws Exception { assertNull(MAPPER.readValue(quote(""), Byte.class)); @@ -110,6 +105,7 @@ public void testEmptyAsNumber() throws Exception assertNull(MAPPER.readValue(quote(""), BigDecimal.class)); } + @Test public void testTextualNullAsNumber() throws Exception { final String NULL_JSON = quote("null"); @@ -155,6 +151,7 @@ public void testTextualNullAsNumber() throws Exception } // [databind#852] + @Test public void testScientificNotationAsStringForNumber() throws Exception { Object ob = MAPPER.readValue("\"3E-8\"", Number.class); @@ -167,6 +164,7 @@ public void testScientificNotationAsStringForNumber() throws Exception assertEquals(Long.class, ob.getClass()); } + @Test public void testIntAsNumber() throws Exception { // Even if declared as 'generic' type, should return using most @@ -175,6 +173,7 @@ public void testIntAsNumber() throws Exception assertEquals(Integer.valueOf(123), result); } + @Test public void testLongAsNumber() throws Exception { // And beyond int range, should get long @@ -183,6 +182,7 @@ public void testLongAsNumber() throws Exception assertEquals(Long.valueOf(exp), result); } + @Test public void testBigIntAsNumber() throws Exception { // and after long, BigInteger @@ -192,6 +192,7 @@ public void testBigIntAsNumber() throws Exception assertEquals(biggie, result); } + @Test public void testIntTypeOverride() throws Exception { // Slight twist; as per [JACKSON-100], can also request binding @@ -216,12 +217,14 @@ public void testIntTypeOverride() throws Exception assertEquals(123, node.asInt()); } + @Test public void testDoubleAsNumber() throws Exception { Number result = MAPPER.readValue(new StringReader(" 1.0 "), Number.class); assertEquals(Double.valueOf(1.0), result); } + @Test public void testFpTypeOverrideSimple() throws Exception { ObjectReader r = MAPPER.reader(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -242,6 +245,7 @@ public void testFpTypeOverrideSimple() throws Exception assertEquals(dec.doubleValue(), node.asDouble()); } + @Test public void testFpTypeOverrideStructured() throws Exception { ObjectReader r = MAPPER.reader(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -264,6 +268,7 @@ public void testFpTypeOverrideStructured() throws Exception } // [databind#504] + @Test public void testForceIntsToLongs() throws Exception { ObjectReader r = MAPPER.reader(DeserializationFeature.USE_LONG_FOR_INTS); @@ -285,6 +290,7 @@ public void testForceIntsToLongs() throws Exception } // [databind#2644] + @Test public void testBigDecimalSubtypes() throws Exception { ObjectMapper mapper = mapperBuilder() @@ -301,6 +307,7 @@ public void testBigDecimalSubtypes() throws Exception } // [databind#2784] + @Test public void testBigDecimalUnwrapped() throws Exception { // mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -309,6 +316,7 @@ public void testBigDecimalUnwrapped() throws Exception assertEquals(new BigDecimal("5.00"), result.holder.value); } + @Test public void testVeryBigDecimalUnwrapped() throws Exception { final int len = 1200; @@ -322,11 +330,12 @@ public void testVeryBigDecimalUnwrapped() throws Exception MAPPER.readValue(DOC, NestedBigDecimalHolder2784.class); fail("expected DatabindException"); } catch (DatabindException jme) { - assertTrue("unexpected message: " + jme.getMessage(), - jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed")); + assertTrue(jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed"), + "unexpected message: " + jme.getMessage()); } } + @Test public void testVeryBigDecimalUnwrappedWithNumLenUnlimited() throws Exception { final int len = 1200; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java index edb4fb8e8..95355a96d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParseBooleanLikeWordsAsStringsTest.java @@ -1,11 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.JsonNodeType; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLParser; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.*; public class ParseBooleanLikeWordsAsStringsTest extends ModuleTestBase { @@ -19,6 +21,7 @@ public class ParseBooleanLikeWordsAsStringsTest extends ModuleTestBase "seven: Y\n" + "eight: N\n"; + @Test public void testParseBooleanLikeWordsAsString_disabledFF() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -51,6 +54,7 @@ public void testParseBooleanLikeWordsAsString_disabledFF() throws Exception assertEquals(root.get("eight").textValue(), "N"); } + @Test public void testParseBooleanLikeWordsAsString_enabledFF() throws Exception { YAMLFactory f = YAMLFactory.builder() diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserAutoCloseTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserAutoCloseTest.java index f48a02236..d093381c3 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserAutoCloseTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserAutoCloseTest.java @@ -1,51 +1,55 @@ package com.fasterxml.jackson.dataformat.yaml.deser; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringReader; +import java.io.*; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; + @SuppressWarnings("resource") public class ParserAutoCloseTest extends ModuleTestBase { private final ObjectMapper YAML_MAPPER = newObjectMapper(); + @Test public void testParseReaderWithAutoClose() throws IOException { CloseTrackerReader reader = new CloseTrackerReader("foo:bar"); YAML_MAPPER.readTree(reader); - Assert.assertEquals(true, reader.isClosed()); + assertEquals(true, reader.isClosed()); } + @Test public void testParseStreamWithAutoClose() throws IOException { CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar"); YAML_MAPPER.readTree(stream); - Assert.assertEquals(true, stream.isClosed()); + assertEquals(true, stream.isClosed()); } + @Test public void testParseReaderWithoutAutoClose() throws IOException { CloseTrackerReader reader = new CloseTrackerReader("foo:bar"); YAML_MAPPER.reader() .without(JsonParser.Feature.AUTO_CLOSE_SOURCE) .readTree(reader); - Assert.assertEquals(false, reader.isClosed()); + assertEquals(false, reader.isClosed()); } + @Test public void testParseStreamWithoutAutoClose() throws IOException { CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar"); YAML_MAPPER.reader() .without(JsonParser.Feature.AUTO_CLOSE_SOURCE) .readTree(stream); - Assert.assertEquals(false, stream.isClosed()); + assertEquals(false, stream.isClosed()); } public static class CloseTrackerReader extends StringReader { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserDupHandlingTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserDupHandlingTest.java index 48a260424..90d02bee1 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserDupHandlingTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserDupHandlingTest.java @@ -1,12 +1,18 @@ package com.fasterxml.jackson.dataformat.yaml.deser; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.StringReader; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.LoaderOptions; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import org.yaml.snakeyaml.LoaderOptions; + +import static org.junit.jupiter.api.Assertions.assertFalse; public class ParserDupHandlingTest extends ModuleTestBase { @@ -15,6 +21,7 @@ public class ParserDupHandlingTest extends ModuleTestBase +" first: Bob\n" +" first: Dup\n"; + @Test public void testDupChecksDisabled() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -25,6 +32,7 @@ public void testDupChecksDisabled() throws Exception _verifyDupsOk(mapper, YAML_WITH_DUPS, true); } + @Test public void testDupChecksEnabled() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -34,6 +42,7 @@ public void testDupChecksEnabled() throws Exception _verifyDupsFail(mapper, YAML_WITH_DUPS, true); } + @Test public void testDupChecksEnabledLoaderOptions() throws Exception { LoaderOptions loaderOptions = new LoaderOptions(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLAnchorReplayingParseTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLAnchorReplayingParseTest.java index 357813bed..a098c1e4b 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLAnchorReplayingParseTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLAnchorReplayingParseTest.java @@ -1,16 +1,19 @@ package com.fasterxml.jackson.dataformat.yaml.deser; -import com.fasterxml.jackson.core.JsonLocation; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.YAMLAnchorReplayingFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class StreamingYAMLAnchorReplayingParseTest extends ModuleTestBase { private final YAMLAnchorReplayingFactory YAML_F = new YAMLAnchorReplayingFactory(); + @Test public void testBasic() throws Exception { final String YAML = @@ -65,6 +68,7 @@ public void testBasic() throws Exception p.close(); } + @Test public void testScalarAnchor() throws Exception { final String YAML = @@ -124,6 +128,7 @@ public void testScalarAnchor() throws Exception p.close(); } + @Test public void testSequenceAnchor() throws Exception { final String YAML = @@ -203,6 +208,7 @@ public void testSequenceAnchor() throws Exception p.close(); } + @Test public void testObjectAnchor() throws Exception { final String YAML = @@ -281,6 +287,7 @@ public void testObjectAnchor() throws Exception p.close(); } + @Test public void testMergeAnchor() throws Exception { final String YAML = diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLParseTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLParseTest.java index 17c7a2d1c..331f20966 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLParseTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingYAMLParseTest.java @@ -3,16 +3,14 @@ import java.io.StringWriter; import java.math.BigInteger; -import com.fasterxml.jackson.core.JsonLocation; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; - -import com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLParser; +import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.LoaderOptions; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for checking functioning of the underlying * parser implementation. @@ -21,6 +19,7 @@ public class StreamingYAMLParseTest extends ModuleTestBase { private final YAMLFactory YAML_F = new YAMLFactory(); + @Test public void testBasic() throws Exception { final String YAML = @@ -83,6 +82,7 @@ public void testBasic() throws Exception // @since 2.17 @SuppressWarnings("deprecation") + @Test public void testDeprecatedMethods() throws Exception { final String YAML = @@ -91,8 +91,8 @@ public void testDeprecatedMethods() throws Exception ; try (JsonParser p = YAML_F.createParser(YAML)) { assertToken(JsonToken.START_OBJECT, p.nextToken()); - assertNull("string", p.getCurrentName()); - assertNull("string", p.currentName()); + assertNull(p.getCurrentName(), "string"); + assertNull(p.currentName(), "string"); assertNull(p.getCurrentValue()); assertToken(JsonToken.FIELD_NAME, p.nextToken()); @@ -126,6 +126,7 @@ public void testDeprecatedMethods() throws Exception } // Parsing large numbers around the transition from int->long and long->BigInteger + @Test public void testIntParsingWithLimits() throws Exception { String YAML; @@ -229,6 +230,7 @@ public void testIntParsingWithLimits() throws Exception } // Testing addition of underscores + @Test public void testIntParsingUnderscoresSm() throws Exception { // First, couple of simple small values @@ -366,6 +368,7 @@ public void testIntParsingUnderscoresSm() throws Exception } // for [dataformats-text#146] + @Test public void testYamlLongWithUnderscores() throws Exception { try (JsonParser p = YAML_F.createParser("v: 1_000_000")) { @@ -378,6 +381,7 @@ public void testYamlLongWithUnderscores() throws Exception } // accidental recognition as double, with multiple dots + @Test public void testDoubleParsing() throws Exception { // First, test out valid use case. @@ -422,6 +426,7 @@ public void testDoubleParsing() throws Exception // [Issue#7] // looks like colons in content can be problematic, if unquoted + @Test public void testColons() throws Exception { // First, test out valid use case. NOTE: spaces matter! @@ -447,6 +452,7 @@ public void testColons() throws Exception /** * How should YAML Anchors be exposed? */ + @Test public void testAnchorParsing() throws Exception { // silly doc, just to expose an id (anchor) and ref to it @@ -502,6 +508,7 @@ public void testAnchorParsing() throws Exception } // Scalars should not be parsed when not in the plain flow style. + @Test public void testQuotedStyles() throws Exception { String YAML = "strings: [\"true\", 'false']"; @@ -525,6 +532,7 @@ public void testQuotedStyles() throws Exception } // Scalars should be parsed when in the plain flow style. + @Test public void testUnquotedStyles() throws Exception { String YAML = "booleans: [true, false]"; @@ -543,6 +551,7 @@ public void testUnquotedStyles() throws Exception p.close(); } + @Test public void testObjectWithNumbers() throws Exception { String YAML = "---\n" @@ -600,6 +609,7 @@ public void testObjectWithNumbers() throws Exception p.close(); } + @Test public void testNulls() throws Exception { String YAML = "nulls: [!!null \"null\" ]"; @@ -617,6 +627,7 @@ public void testNulls() throws Exception p.close(); } + @Test public void testTildeNulls() throws Exception { String YAML = "nulls: [~ ]"; @@ -635,6 +646,7 @@ public void testTildeNulls() throws Exception } // for [dataformat-yaml#69] + @Test public void testTimeLikeValues() throws Exception { final String YAML = "value: 3:00\n"; @@ -650,6 +662,7 @@ public void testTimeLikeValues() throws Exception p.close(); } + @Test public void testYamlParseFailsWhenCodePointLimitVerySmall() throws Exception { final String YAML = "---\n" diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UTF8ReaderTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UTF8ReaderTest.java index e43a0659a..1edda360d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UTF8ReaderTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UTF8ReaderTest.java @@ -1,15 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.deser; -import org.junit.Test; +import java.io.*; +import java.nio.charset.StandardCharsets; -import com.fasterxml.jackson.dataformat.yaml.UTF8Reader; +import org.junit.jupiter.api.Test; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; +import com.fasterxml.jackson.dataformat.yaml.UTF8Reader; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class UTF8ReaderTest { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectIdWithTree2Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectIdWithTree2Test.java index e127d07e8..615b95dc3 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectIdWithTree2Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectIdWithTree2Test.java @@ -1,11 +1,14 @@ package com.fasterxml.jackson.dataformat.yaml.failing; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; /** * Although native Object Ids work in general, Tree Model currently * has issues with it (see [dataformats-text#2]) @@ -41,6 +44,7 @@ public Node(String name) { ; // [dataformats-text#2] + @Test public void testRoundtripViaTree() throws Exception { ObjectMapper mapper = newObjectMapper(); @@ -63,7 +67,7 @@ private void _verify(Node first) assertEquals("first", first.name); assertNotNull(first.next); assertEquals("second", first.next.name); - assertNotNull("Should not have null for 'first.next.next'", first.next.next); + assertNotNull(first.next.next, "Should not have null for 'first.next.next'"); assertSame(first, first.next.next); } } diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/PolymorphicWithObjectId25Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/PolymorphicWithObjectId25Test.java index 80de3e674..d30415cd1 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/PolymorphicWithObjectId25Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/PolymorphicWithObjectId25Test.java @@ -1,13 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.failing; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + // [dataformats-text#25] public class PolymorphicWithObjectId25Test extends ModuleTestBase { @@ -39,6 +39,7 @@ static class SubNodeWithStringId extends NodeWithStringId { } private final ObjectMapper MAPPER = newObjectMapper(); // [dataformats-text#25] + @Test public void testPolymorphicAndObjectId25() throws Exception { String yml = "---\n" diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Test.java index 114612b0f..f3c83a8ee 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Test.java @@ -2,16 +2,17 @@ import java.util.Collections; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; // NOTE: fails only on 2.x (2.12) -- fixed for 3.0 public class SimpleGeneration215Test extends ModuleTestBase { // [dataformats-text#215]: trying to disable WRITE_DOC_START_MARKER // via ObjectWriter does not work + @Test public void testStartMarkerViaWriter() throws Exception { final String output = YAMLMapper.builder().build() @@ -23,6 +24,7 @@ public void testStartMarkerViaWriter() throws Exception } // [dataformats-text#215]: variant that actually works + @Test public void testStartMarkerViaMapper() throws Exception { YAMLMapper mapper = new YAMLMapper(YAMLFactory.builder() diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration366Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration366Test.java index 96668e7c9..1d82c13e4 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration366Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration366Test.java @@ -1,16 +1,19 @@ package com.fasterxml.jackson.dataformat.yaml.failing; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; - import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + public class SimpleGeneration366Test extends ModuleTestBase { // [dataformats-text#366]: multiline literal block with trailing spaces does not work + @Test public void testLiteralBlockStyleMultilineWithTrailingSpace() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -30,6 +33,7 @@ public void testLiteralBlockStyleMultilineWithTrailingSpace() throws Exception } // [dataformats-text#366]: multiline literal block without trailing spaces actually works + @Test public void testLiteralBlockStyleMultiline() throws Exception { YAMLFactory f = new YAMLFactory(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/UnicodeYAMLRead497Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/UnicodeYAMLRead497Test.java index 58c5b28ad..02e303e9f 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/UnicodeYAMLRead497Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/UnicodeYAMLRead497Test.java @@ -2,10 +2,14 @@ import java.nio.charset.StandardCharsets; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; -import com.fasterxml.jackson.dataformat.yaml.*; +import static org.junit.jupiter.api.Assertions.assertEquals; // [dataformats-text#497]: 3-byte UTF-8 character at end of content public class UnicodeYAMLRead497Test extends ModuleTestBase @@ -13,6 +17,7 @@ public class UnicodeYAMLRead497Test extends ModuleTestBase private final YAMLMapper MAPPER = newObjectMapper(); // [dataformats-text#497] + @Test public void testUnicodeAtEnd() throws Exception { // Had to find edge condition, these would do: diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/filter/StreamingDecoratorsTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/filter/StreamingDecoratorsTest.java index cd5b087ee..f22ad207a 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/filter/StreamingDecoratorsTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/filter/StreamingDecoratorsTest.java @@ -1,17 +1,23 @@ package com.fasterxml.jackson.dataformat.yaml.filter; import java.io.*; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; -import com.fasterxml.jackson.databind.*; +import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.dataformat.yaml.*; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.testutil.PrefixInputDecorator; import com.fasterxml.jackson.dataformat.yaml.testutil.PrefixOutputDecorator; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class StreamingDecoratorsTest extends ModuleTestBase { @SuppressWarnings("unchecked") + @Test public void testInputDecorators() throws IOException { final byte[] DOC = utf8("secret: mum\n"); @@ -31,6 +37,7 @@ public void testInputDecorators() throws IOException assertEquals("mum", value.get("secret")); } + @Test public void testOutputDecorators() throws IOException { final String PREFIX = "///////"; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead63274Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead63274Test.java index d905b7666..29d70314f 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead63274Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead63274Test.java @@ -1,15 +1,18 @@ package com.fasterxml.jackson.dataformat.yaml.fuzz; -import com.fasterxml.jackson.core.JacksonException; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.JacksonException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.fail; public class FuzzYAMLRead63274Test extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63274 + @Test public void testMalformedNumber63274() throws Exception { // As bytes: diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead65855Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead65855Test.java index 50a76b093..abe624f3f 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead65855Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLRead65855Test.java @@ -1,16 +1,18 @@ package com.fasterxml.jackson.dataformat.yaml.fuzz; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.fail; public class FuzzYAMLRead65855Test extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65855 + @Test public void testMalformedNumber65855() throws Exception { String doc = "!!int\n-_"; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java index 8c9e792de..3408838cc 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAMLReadTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.dataformat.yaml.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JacksonException; @@ -9,6 +11,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * Collection of OSS-Fuzz found issues for YAML format module. */ @@ -17,6 +22,7 @@ public class FuzzYAMLReadTest extends ModuleTestBase private final ObjectMapper YAML_MAPPER = newObjectMapper(); // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50036 + @Test public void testUTF8Decoding50036() throws Exception { byte[] INPUT = new byte[] { 0x20, (byte) 0xCD }; @@ -30,6 +36,7 @@ public void testUTF8Decoding50036() throws Exception } // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50052 + @Test public void testNumberDecoding50052() throws Exception { // 17-Sep-2022, tatu: Could produce an exception but for now type @@ -40,6 +47,7 @@ public void testNumberDecoding50052() throws Exception } // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50339 + @Test public void testTagDecoding50339() throws Exception { final String DOC = "[!!,"; @@ -54,6 +62,7 @@ public void testTagDecoding50339() throws Exception } // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50407 + @Test public void testNumberDecoding50407() throws Exception { // int, octal @@ -79,6 +88,7 @@ private void _testNumberDecoding50407(String doc) { // [dataformats-text#400], originally from // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50431 + @Test public void testUnicodeDecoding50431() throws Exception { String input = "\n\"\\UE30EEE"; @@ -97,6 +107,7 @@ public void testUnicodeDecoding50431() throws Exception // // Problem being value overflow wrt 32-bit integer for malformed YAML // version indicators + @Test public void testVersionNumberParsing56902() throws Exception { String input = "%YAML 1.9224775801"; @@ -112,6 +123,7 @@ public void testVersionNumberParsing56902() throws Exception // [dataformats-text#435], originally from // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61823 + @Test public void testNumberDecoding61823() throws Exception { try { @@ -134,6 +146,7 @@ public ModelContainer445(@JsonProperty(value = "string") String string) { // [dataformats-text#445]: NPE // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64662 + @Test public void testNullPointerException445_64662() throws Exception { // Content itself odd, generated by Fuzz; but needs to trigger buffering to work diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAML_65918_Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAML_65918_Test.java index 3bea01e3d..905efb28b 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAML_65918_Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/fuzz/FuzzYAML_65918_Test.java @@ -1,17 +1,21 @@ package com.fasterxml.jackson.dataformat.yaml.fuzz; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class FuzzYAML_65918_Test extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65918 + @Test public void testMalformed65918() throws Exception { byte[] doc = readResource("/data/fuzz-65918.yaml"); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId231Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId231Test.java index 22344043b..51e314484 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId231Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId231Test.java @@ -2,10 +2,14 @@ import java.util.List; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.*; +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ObjectAndTypeId231Test extends ModuleTestBase { @@ -29,6 +33,7 @@ static class Derived extends Base { private final ObjectMapper MAPPER = newObjectMapper(); // [dataformats-text#231] + @Test public void testTypeAndObjectId231() throws Exception { String yaml = "list:\n" + diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId232Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId232Test.java index 592be9b31..eb016fdd9 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId232Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectAndTypeId232Test.java @@ -2,16 +2,16 @@ import java.util.List; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + public class ObjectAndTypeId232Test extends ModuleTestBase { // [dataformats-text#232] @@ -39,6 +39,7 @@ static class Derived232 extends Base232 { private final ObjectMapper MAPPER = newObjectMapper(); // [dataformats-text#232] + @Test public void testTypedYAML232() throws Exception { String yaml = "list:\n" + diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId123Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId123Test.java index eb037b785..cdf02aeb8 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId123Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId123Test.java @@ -1,14 +1,21 @@ package com.fasterxml.jackson.dataformat.yaml.misc; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.*; +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; //for [dataformats-text#123], problem with YAML, Object Ids public class ObjectId123Test extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testObjectIdUsingNative() throws Exception { final String YAML_CONTENT = diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId63Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId63Test.java index 28ce217c7..9f081f63d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId63Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectId63Test.java @@ -1,9 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.misc; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.*; +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; + +import static org.junit.jupiter.api.Assertions.assertEquals; // for [dataformats-text#63], problem with YAML, Object Ids public class ObjectId63Test extends ModuleTestBase @@ -32,6 +36,7 @@ public void setValue(final String newValue) { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testIssue63() throws Exception { final SimplePojo simplePojoWithId = new SimplePojo(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectIdTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectIdTest.java index e2ee346f2..886eba25d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectIdTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ObjectIdTest.java @@ -1,12 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.misc; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.util.TokenBuffer; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.*; public class ObjectIdTest extends ModuleTestBase { @@ -115,6 +116,7 @@ public ObjectIdGenerator.IdKey key(Object key) { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testNativeSerialization() throws Exception { Node first = new Node("first"); @@ -126,6 +128,7 @@ public void testNativeSerialization() throws Exception } // [dataformat-yaml#23] + @Test public void testNonNativeSerialization() throws Exception { YAMLMapper mapper = YAMLMapper.builder() @@ -139,6 +142,7 @@ public void testNonNativeSerialization() throws Exception assertYAML(SIMPLE_YAML_NON_NATIVE, yaml); } + @Test public void testBasicDeserialization() throws Exception { Node first = MAPPER.readValue(SIMPLE_YAML_NATIVE, Node.class); @@ -151,6 +155,7 @@ public void testBasicDeserialization() throws Exception // More complex example with string-prefixed id // [dataformat-yaml#45] + @Test public void testDeserializationIssue45() throws Exception { NodeWithStringId node = MAPPER.readValue(SIMPLE_YAML_NATIVE_B, NodeWithStringId.class); @@ -163,6 +168,7 @@ public void testDeserializationIssue45() throws Exception assertSame(node, node.next.next); } + @Test public void testRoundtripWithBuffer() throws Exception { TokenBuffer tbuf = MAPPER.readValue(SIMPLE_YAML_NATIVE, TokenBuffer.class); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/PolymorphicDeductionTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/PolymorphicDeductionTest.java index 167777bcc..49cecb50a 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/PolymorphicDeductionTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/PolymorphicDeductionTest.java @@ -2,12 +2,13 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import static com.fasterxml.jackson.annotation.JsonSubTypes.Type; import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.DEDUCTION; +import static org.junit.jupiter.api.Assertions.*; // Copied from [databind#43], deduction-based polymorphism public class PolymorphicDeductionTest extends ModuleTestBase diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedNamesTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedNamesTest.java index ee2726e90..84b7dda5b 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedNamesTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedNamesTest.java @@ -1,15 +1,21 @@ package com.fasterxml.jackson.dataformat.yaml.misc; -import java.util.*; +import java.util.Collections; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; + // [dataformats-text#68]: should quote reserved names public class ReservedNamesTest extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testQuotingOfBooleanKeys() throws Exception { for (String value : new String[] { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedValuesTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedValuesTest.java index ced7f832c..fd2635c1f 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedValuesTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/misc/ReservedValuesTest.java @@ -1,14 +1,20 @@ package com.fasterxml.jackson.dataformat.yaml.misc; -import java.util.*; +import java.util.Collections; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ReservedValuesTest extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testQuotingOfBooleanValues() throws Exception { for (String value : new String[] { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/BinaryWriteTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/BinaryWriteTest.java index 89e977f13..a07164ccf 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/BinaryWriteTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/BinaryWriteTest.java @@ -3,18 +3,22 @@ import java.io.StringWriter; import java.util.Arrays; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class BinaryWriteTest extends ModuleTestBase { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testBinaryViaTree() throws Exception { byte[] srcPayload = new byte[] { 1, 2, 3, 4, 5 }; @@ -28,9 +32,10 @@ public void testBinaryViaTree() throws Exception assertNotNull(data); assertEquals(JsonNodeType.BINARY, data.getNodeType()); final byte[] b = data.binaryValue(); - Assert.assertArrayEquals(srcPayload, b); + assertArrayEquals(srcPayload, b); } + @Test public void testWriteLongBinary() throws Exception { final int length = 200; final byte[] data = new byte[length]; @@ -46,7 +51,7 @@ public void testWriteLongBinary() throws Exception { } String yaml = w.toString(); - Assert.assertEquals("---\n" + + assertEquals("---\n" + "array: !!binary |-\n" + " AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" + " AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" + diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomNodeStyleTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomNodeStyleTest.java index 04c892d72..e9e13b318 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomNodeStyleTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomNodeStyleTest.java @@ -1,14 +1,14 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.DumperOptions; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.*; + import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CustomNodeStyleTest extends ModuleTestBase { @@ -16,6 +16,7 @@ public class CustomNodeStyleTest extends ModuleTestBase { private final ObjectMapper BLOCK_STYLE_MAPPER = createMapper(DumperOptions.FlowStyle.BLOCK); private final ObjectMapper FLOW_STYLE_MAPPER = createMapper(DumperOptions.FlowStyle.FLOW); + @Test public void testFlowStyles() throws Exception { // list assertEquals("key_default:\n- value", diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomStringQuoting229Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomStringQuoting229Test.java index 7f8504edf..7fac5696b 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomStringQuoting229Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/CustomStringQuoting229Test.java @@ -2,14 +2,14 @@ import java.util.Collections; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.*; import com.fasterxml.jackson.dataformat.yaml.util.StringQuotingChecker; +import static org.junit.jupiter.api.Assertions.assertEquals; + @SuppressWarnings("serial") public class CustomStringQuoting229Test extends ModuleTestBase { @@ -41,6 +41,7 @@ public boolean needToQuoteValue(String value) { .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) .build(); + @Test public void testNameQuotingDefault() throws Exception { // First, default quoting @@ -61,6 +62,7 @@ public void testNameQuotingDefault() throws Exception _asYaml(MINIMIZING_MAPPER, Collections.singletonMap("specialKey", "value"))); } + @Test public void testNameQuotingCustom() throws Exception { // Then with custom rules @@ -79,6 +81,7 @@ public void testNameQuotingCustom() throws Exception _asYaml(CUSTOM_MAPPER, Collections.singletonMap("specialKey", "value"))); } + @Test public void testValueQuotingDefault() throws Exception { // First, default quoting @@ -97,6 +100,7 @@ public void testValueQuotingDefault() throws Exception _asYaml(MINIMIZING_MAPPER, Collections.singletonMap("key", "specialValue"))); } + @Test public void testValueQuotingCustom() throws Exception { // Then with custom rules diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java index 6258c5e37..e8b21d07e 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java @@ -1,19 +1,17 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeSet; +import java.io.*; +import java.util.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class DatabindWriteTest extends ModuleTestBase { final ObjectMapper MAPPER = newObjectMapper(); @@ -29,6 +27,7 @@ public Point(int x, int y) { } } + @Test public void testBasicPOJO() throws Exception { FiveMinuteUser user = new FiveMinuteUser("Bob", "Dabolito", false, @@ -59,6 +58,7 @@ public void testBasicPOJO() throws Exception } // Related to [dataformats-text#68], escaping of "reserved" names + @Test public void testBasicDatabind2() throws Exception { String yaml = trimDocMarker(MAPPER.writeValueAsString(new Point(1, 2))); @@ -73,6 +73,7 @@ public void testBasicDatabind2() throws Exception assertEquals(2, p.y); } + @Test public void testWithFile() throws Exception { File f = File.createTempFile("test", ".yml"); @@ -94,6 +95,7 @@ public void testWithFile() throws Exception f.delete(); } + @Test public void testWithFile2() throws Exception { File f = File.createTempFile("test", ".yml"); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorAutoCloseTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorAutoCloseTest.java index 8a782f725..80facdfca 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorAutoCloseTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorAutoCloseTest.java @@ -1,52 +1,57 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import java.io.IOException; -import java.io.OutputStream; -import java.io.StringWriter; +import java.io.*; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; + @SuppressWarnings("resource") public class GeneratorAutoCloseTest extends ModuleTestBase { private Pojo pojo = new Pojo("bar"); + @Test public void testGenerateWriterWithoAutoCloseTarget() throws IOException { CloseTrackerWriter writer = new CloseTrackerWriter(); ObjectMapper yamlMapper = newObjectMapper(); yamlMapper.writeValue(writer, pojo); - Assert.assertEquals(true, writer.isClosed()); + assertEquals(true, writer.isClosed()); } + @Test public void testGenerateOutputStreamWithAutoCloseTarget() throws IOException { CloseTrackerOutputStream stream = new CloseTrackerOutputStream(); ObjectMapper yamlMapper = newObjectMapper(); yamlMapper.writeValue(stream, pojo); - Assert.assertEquals(true, stream.isClosed()); + assertEquals(true, stream.isClosed()); } + @Test public void testGenerateWriterWithoutAutoCloseTarget() throws IOException { CloseTrackerWriter writer = new CloseTrackerWriter(); ObjectMapper yamlMapper = newObjectMapper() .disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); yamlMapper.writeValue(writer, pojo); - Assert.assertEquals(false, writer.isClosed()); + assertEquals(false, writer.isClosed()); } + @Test public void testGenerateOutputStreamWithoutAutoCloseTarget() throws IOException { CloseTrackerOutputStream stream = new CloseTrackerOutputStream(); ObjectMapper yamlMapper = newObjectMapper() .disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); yamlMapper.writeValue(stream, pojo); - Assert.assertEquals(false, stream.isClosed()); + assertEquals(false, stream.isClosed()); } + @Test public void testGenerateOutputStreamWithoutAutoCloseTargetOnFactory() throws IOException { CloseTrackerOutputStream stream = new CloseTrackerOutputStream(); ObjectMapper yamlMapper = new ObjectMapper( @@ -54,7 +59,7 @@ public void testGenerateOutputStreamWithoutAutoCloseTargetOnFactory() throws IOE .disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET) ); yamlMapper.writeValue(stream, pojo); - Assert.assertEquals(false, stream.isClosed()); + assertEquals(false, stream.isClosed()); } diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature175Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature175Test.java index 303270b68..b7e069836 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature175Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature175Test.java @@ -1,11 +1,12 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; - import java.util.Map; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.*; public class GeneratorFeature175Test extends ModuleTestBase { /* /********************************************************** @@ -14,6 +15,7 @@ public class GeneratorFeature175Test extends ModuleTestBase { */ // [dataformats-text#175]: arrays indentation with indicator + @Test public void testArrayWithIndicatorIndentation() throws Exception { String yamlBefore = "---\n" + "tags:\n" + diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature34Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature34Test.java index 82988de33..36539a9ab 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature34Test.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeature34Test.java @@ -2,9 +2,12 @@ import java.util.Map; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class GeneratorFeature34Test extends ModuleTestBase { @@ -15,6 +18,7 @@ public class GeneratorFeature34Test extends ModuleTestBase */ // [dataformats-text#34]: busted indentation + @Test public void testArrayIndentation67() throws Exception { String yamlBefore = "---\n" + diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeatureTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeatureTest.java index bba48d418..038c10139 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeatureTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorFeatureTest.java @@ -1,16 +1,14 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; +import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.DumperOptions; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GeneratorFeatureTest extends ModuleTestBase { @@ -30,6 +28,7 @@ public Words(String... w) { private final ObjectMapper MAPPER = newObjectMapper(); + @Test public void testArrayIndentation() throws Exception { Words input = new Words("first", "second", "third"); @@ -65,6 +64,7 @@ public void testArrayIndentation() throws Exception } //@since 2.14 + @Test public void testLongKeys() throws Exception { final String LONG_KEY = "key_longer_than_128_characters_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; @@ -80,6 +80,7 @@ public void testLongKeys() throws Exception } // @since 2.12 + @Test public void testYAMLSpecVersionDefault() throws Exception { ObjectMapper defaultMapper = YAMLMapper.builder().build(); @@ -90,6 +91,7 @@ public void testYAMLSpecVersionDefault() throws Exception } // @since 2.12 + @Test public void testYAMLSpecVersion10() throws Exception { ObjectMapper mapper10 = YAMLMapper.builder( @@ -103,6 +105,7 @@ public void testYAMLSpecVersion10() throws Exception } // @since 2.12 + @Test public void testYAMLSpecVersion11() throws Exception { ObjectMapper mapper11 = YAMLMapper.builder( diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java index 2a2db6866..fa66e80f9 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java @@ -1,12 +1,14 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.*; +import static org.junit.jupiter.api.Assertions.*; + public class GeneratorWithMinimizeTest extends ModuleTestBase { private final ObjectMapper VANILLA_MAPPER = newObjectMapper(); @@ -15,6 +17,7 @@ public class GeneratorWithMinimizeTest extends ModuleTestBase .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) .build(); + @Test public void testDefaultSetting() { YAMLFactory f = new YAMLFactory(); assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES)); @@ -22,6 +25,7 @@ public void testDefaultSetting() { assertTrue(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES)); } + @Test public void testLiteralStringsSingleLine() throws Exception { Map content = new HashMap(); @@ -32,6 +36,7 @@ public void testLiteralStringsSingleLine() throws Exception "key: some value", yaml); } + @Test public void testMinimizeQuotesWithBooleanContent() throws Exception { Map content = new HashMap(); @@ -63,6 +68,7 @@ public void testMinimizeQuotesWithBooleanContent() throws Exception "key: true", yaml); } + @Test public void testMinimizeQuotesWithNulls() throws Exception { Map content = new HashMap(); @@ -91,6 +97,7 @@ public void testMinimizeQuotesWithNulls() throws Exception "key: nuLL", yaml); } + @Test public void testMinimizeQuotesWithStringsContainingSpecialChars() throws Exception { Map content; @@ -162,6 +169,7 @@ public void testMinimizeQuotesWithStringsContainingSpecialChars() throws Excepti } + @Test public void testLiteralStringsMultiLine() throws Exception { Map content = new HashMap(); @@ -172,6 +180,7 @@ public void testLiteralStringsMultiLine() throws Exception "key: |-\n first\n second\n third", yaml); } + @Test public void testQuoteNumberStoredAsString() throws Exception { // [dataformats-text#182] @@ -212,6 +221,7 @@ public void testQuoteNumberStoredAsString() throws Exception "key: \"+125\"", yaml); } + @Test public void testNonQuoteNumberStoredAsString() throws Exception { String yaml = MINIM_MAPPER.writeValueAsString(Collections.singletonMap("key", "20")).trim(); @@ -228,6 +238,7 @@ public void testNonQuoteNumberStoredAsString() throws Exception } // [dataformats-test#50] + @Test public void testEmptyStringWithMinimizeQuotes() throws Exception { String yaml = MINIM_MAPPER.writeValueAsString(Collections.singletonMap("key", "")).trim(); @@ -235,6 +246,7 @@ public void testEmptyStringWithMinimizeQuotes() throws Exception } // [dataformats-text#140] + @Test public void testNumberKey() throws Exception { // First, test with Strings that happen to look like Integer @@ -262,6 +274,7 @@ public void testNumberKey() throws Exception } // [dataformats-text#246] + @Test public void testMinimizeQuotesSpecialCharsMultiLine() throws Exception { Map content = new HashMap<>(); @@ -275,6 +288,7 @@ public void testMinimizeQuotesSpecialCharsMultiLine() throws Exception // [dataformats-text#274]: tilde is an alias for null values, must quote // if written as String. Was already quoted by default but also must be quoted // in minimized mode + @Test public void testQuotingOfTilde() throws Exception { Map content = new HashMap<>(); @@ -291,6 +305,7 @@ public void testQuotingOfTilde() throws Exception // [dataformats-text#492]: too aggressive dropping of quoting? // (wrt [dataformats-text#465] change in 2.17) + @Test public void testMinimalHashQuoting492() throws Exception { Map content = Collections.singletonMap("$ref", diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithSplitLinesTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithSplitLinesTest.java index 9de65de69..b7d43332d 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithSplitLinesTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithSplitLinesTest.java @@ -1,9 +1,15 @@ package com.fasterxml.jackson.dataformat.yaml.ser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.yaml.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class GeneratorWithSplitLinesTest extends ModuleTestBase { + @Test public void testSplitLines() throws Exception { final String TEXT = "1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890"; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/SimpleGenerationTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/SimpleGenerationTest.java index df31faee3..c6a2ba6d5 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/SimpleGenerationTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/SimpleGenerationTest.java @@ -1,19 +1,21 @@ package com.fasterxml.jackson.dataformat.yaml.ser; import java.io.*; -import java.util.*; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.dataformat.yaml.*; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import static org.junit.jupiter.api.Assertions.*; public class SimpleGenerationTest extends ModuleTestBase { private final YAMLFactory YAML_F = new YAMLFactory(); + @Test public void testStreamingArray() throws Exception { StringWriter w = new StringWriter(); @@ -31,6 +33,7 @@ public void testStreamingArray() throws Exception assertEquals("- 3\n- \"foobar\"", yaml); } + @Test public void testStreamingObject() throws Exception { StringWriter w = new StringWriter(); @@ -44,6 +47,7 @@ public void testStreamingObject() throws Exception gen.close(); } + @Test public void testStreamingNested() throws Exception { StringWriter w = new StringWriter(); @@ -76,6 +80,7 @@ public void testStreamingNested() throws Exception } @SuppressWarnings("resource") + @Test public void testStartMarker() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -100,6 +105,7 @@ public void testStartMarker() throws Exception assertEquals("name: \"Brad\"\nage: 39", yaml); } + @Test public void testLiteralBlockStyle() throws Exception { YAMLFactory f = new YAMLFactory(); @@ -125,6 +131,7 @@ public void testLiteralBlockStyle() throws Exception "text: \"Hello World\"", yaml); } + @Test public void testSimpleNullProperty() throws Exception { StringWriter w = new StringWriter(); diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/UTF8WriterTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/UTF8WriterTest.java index 9c1db5496..fe7d3b66a 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/UTF8WriterTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/UTF8WriterTest.java @@ -1,18 +1,16 @@ package com.fasterxml.jackson.dataformat.yaml.ser; -import org.junit.Test; - -import com.fasterxml.jackson.dataformat.yaml.UTF8Writer; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.yaml.UTF8Writer; + +import static org.junit.jupiter.api.Assertions.*; public class UTF8WriterTest { diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/dos/CyclicYAMLDataSerTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/dos/CyclicYAMLDataSerTest.java index 722f463c5..836997f1f 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/dos/CyclicYAMLDataSerTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/dos/CyclicYAMLDataSerTest.java @@ -3,14 +3,17 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.core.StreamWriteConstraints; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.StreamWriteConstraints; import com.fasterxml.jackson.databind.DatabindException; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * Simple unit tests to verify that we fail gracefully if you attempt to serialize * data that is cyclic (eg a list that contains itself). @@ -19,6 +22,7 @@ public class CyclicYAMLDataSerTest extends ModuleTestBase { private final ObjectMapper MAPPER = YAMLMapper.builder().build(); + @Test public void testListWithSelfReference() throws Exception { List list = new ArrayList<>(); list.add(list); @@ -28,8 +32,8 @@ public void testListWithSelfReference() throws Exception { } catch (DatabindException e) { String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); - assertTrue("DatabindException message is as expected?", - e.getMessage().startsWith(exceptionPrefix)); + assertTrue(e.getMessage().startsWith(exceptionPrefix), + "DatabindException message is as expected?"); } } } diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixInputDecorator.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixInputDecorator.java index 86775c93a..7eaf872d5 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixInputDecorator.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixInputDecorator.java @@ -1,11 +1,6 @@ package com.fasterxml.jackson.dataformat.yaml.testutil; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.SequenceInputStream; -import java.io.StringReader; +import java.io.*; import java.nio.charset.StandardCharsets; import com.fasterxml.jackson.core.io.IOContext; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixOutputDecorator.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixOutputDecorator.java index ff9521440..4dd7d1106 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixOutputDecorator.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/PrefixOutputDecorator.java @@ -1,9 +1,6 @@ package com.fasterxml.jackson.dataformat.yaml.testutil; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; +import java.io.*; import com.fasterxml.jackson.core.io.IOContext; import com.fasterxml.jackson.core.io.OutputDecorator; diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpected.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpected.java index 4b7f02fa4..3ce15ba72 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpected.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpected.java @@ -1,11 +1,8 @@ package com.fasterxml.jackson.dataformat.yaml.testutil.failure; -import org.junit.jupiter.api.extension.ExtendWith; +import java.lang.annotation.*; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; /** *

@@ -24,6 +21,7 @@ * * @Test * @JacksonTestFailureExpected + * @Test * public void testFeatureNotYetImplemented() { * // Test code that is expected to fail * } diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpectedInterceptor.java index 2f619da2d..52b6ef230 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpectedInterceptor.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -1,11 +1,9 @@ package com.fasterxml.jackson.dataformat.yaml.testutil.failure; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.InvocationInterceptor; -import org.junit.jupiter.api.extension.ReflectiveInvocationContext; - import java.lang.reflect.Method; +import org.junit.jupiter.api.extension.*; + /** * Custom {@link InvocationInterceptor} that intercepts test method invocation. * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/PolymorphicIdTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/PolymorphicIdTest.java index 5fddea306..db4eca6eb 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/PolymorphicIdTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/PolymorphicIdTest.java @@ -1,11 +1,13 @@ package com.fasterxml.jackson.dataformat.yaml.type; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class PolymorphicIdTest extends ModuleTestBase { static class Wrapper { @@ -41,7 +43,7 @@ public void testPolymorphicType() throws Exception top = MAPPER.readValue(YAML, Wrapper.class); assertNotNull(top); assertEquals(NestedImpl.class, top.nested.getClass()); - assertNull("whatever", ((NestedImpl) top.nested).value); + assertNull(((NestedImpl) top.nested).value, "whatever"); } @Test diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/TypeIdTest.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/TypeIdTest.java index 58cf48258..d4ab41e50 100644 --- a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/TypeIdTest.java +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/type/TypeIdTest.java @@ -1,12 +1,14 @@ package com.fasterxml.jackson.dataformat.yaml.type; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.util.TokenBuffer; -import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.fasterxml.jackson.dataformat.yaml.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TypeIdTest extends ModuleTestBase { @@ -34,6 +36,7 @@ public Impl() { } /********************************************************** */ + @Test public void testNativeSerialization() throws Exception { ObjectMapper mapper = newObjectMapper(); @@ -42,6 +45,7 @@ public void testNativeSerialization() throws Exception assertEquals("--- !\na: 13", yaml); } + @Test public void testNonNativeSerialization() throws Exception { YAMLMapper mapper = newObjectMapper(); @@ -56,6 +60,7 @@ public void testNonNativeSerialization() throws Exception assertEquals(Impl.class, back.getClass()); } + @Test public void testDeserialization() throws Exception { /* Looks like there are couple of alternative ways to indicate @@ -77,6 +82,7 @@ public void testDeserialization() throws Exception } } + @Test public void testRoundtripWithBuffer() throws Exception { ObjectMapper mapper = newObjectMapper(); diff --git a/yaml/src/test/java/perf/YAMLDeserPerf.java b/yaml/src/test/java/perf/YAMLDeserPerf.java index ab95cd76e..15ee6a650 100644 --- a/yaml/src/test/java/perf/YAMLDeserPerf.java +++ b/yaml/src/test/java/perf/YAMLDeserPerf.java @@ -1,9 +1,11 @@ package perf; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; /** * Micro-benchmark for comparing performance of bean deserialization @@ -47,6 +49,7 @@ private MediaItem buildItem() return item; } + @Test public void test() throws Exception { diff --git a/yaml/src/test/java/perf/YAMLSerPerf.java b/yaml/src/test/java/perf/YAMLSerPerf.java index 3254e3947..bae648c34 100644 --- a/yaml/src/test/java/perf/YAMLSerPerf.java +++ b/yaml/src/test/java/perf/YAMLSerPerf.java @@ -1,12 +1,15 @@ package perf; -import java.io.*; +import java.io.ByteArrayOutputStream; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + public final class YAMLSerPerf { /* @@ -47,6 +50,7 @@ private MediaItem buildItem() return item; } + @Test public void test() throws Exception {