From 4c245fa16f35f3e260618c606936e38501a975c9 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 11:16:57 +0900 Subject: [PATCH 1/5] Migrate cbor tests --- .../jackson/dataformat/cbor/CBORFactory.java | 2 +- .../dataformat/cbor/CBORGenerator.java | 6 ++-- .../jackson/dataformat/cbor/CBORParser.java | 8 ++--- .../cbor/CBORParserBootstrapper.java | 6 ++-- .../dataformat/cbor/databind/CBORMapper.java | 6 +--- .../cbor/BrokenLongBinary186Test.java | 12 +++++--- .../cbor/CBORFactoryPropertiesTest.java | 10 ++++++- .../jackson/dataformat/cbor/CBORTestBase.java | 17 +++++------ .../dataformat/cbor/FloatPrecisionTest.java | 5 ++-- .../dataformat/cbor/FormatDefaultsTest.java | 5 ++++ .../cbor/GeneratorDeepNestingTest.java | 9 +++++- .../cbor/GeneratorDupHandlingTest.java | 10 ++++++- .../dataformat/cbor/GeneratorInteropTest.java | 6 ++++ .../cbor/GeneratorInvalidCallsTest.java | 5 ++++ .../cbor/GeneratorLongStringTest.java | 8 ++++- .../cbor/GeneratorShortStringTest.java | 10 +++++++ .../dataformat/cbor/MapAndArrayTest.java | 16 ++++++++++ .../dataformat/cbor/NumberCoercing32Test.java | 8 ++++- .../cbor/ParserInputStreamTest.java | 15 +++++----- .../cbor/ParserWithJsonOrgSampleTest.java | 7 +++++ .../cbor/SharedRawGeneratorBufferTest.java | 12 ++++---- .../dataformat/cbor/StringrefTest.java | 22 ++++++++++---- .../cbor/filter/StreamingDecoratorsTest.java | 12 ++++++-- .../fuzz/CBORFuzz451_65617_IOOBETest.java | 7 +++-- .../cbor/fuzz/CBORFuzz458_65768_NPETest.java | 7 +++-- .../fuzz/CBORFuzz464_65722_IOOBETest.java | 7 +++-- .../fuzz/CBORFuzz_35979_StringValueTest.java | 7 +++-- .../Fuzz264_32381BigDecimalScaleTest.java | 8 +++-- .../fuzz/Fuzz267_32579BigDecimalTest.java | 6 ++++ .../fuzz/Fuzz272_32722_ChunkedTextTest.java | 6 +++- .../fuzz/Fuzz273_32912_ChunkedTextTest.java | 5 ++++ .../Fuzz288_35750_NonCanonicalNameTest.java | 3 ++ .../fuzz/Fuzz289_35822_TruncatedNameTest.java | 5 ++++ .../cbor/fuzz/Fuzz32173LongTextTest.java | 7 +++-- .../cbor/fuzz/Fuzz32250BigIntegerTest.java | 6 ++++ .../cbor/fuzz/Fuzz32912ChunkedTextTest.java | 7 +++-- .../cbor/gen/ArrayGenerationTest.java | 15 +++++++--- .../cbor/gen/GeneratorBinaryTest.java | 1 + .../cbor/gen/GeneratorSimpleTest.java | 29 ++++++++++++++----- .../gen/LenientUnicodeCBORGenerationTest.java | 9 +++++- .../cbor/gen/TestGeneratorClosing.java | 10 ++++++- .../DeeplyNestedCBORReadWriteTest.java | 15 ++++++---- .../constraints/LongDocumentCBORReadTest.java | 11 ++++--- .../cbor/gen/dos/CyclicCBORDataSerTest.java | 13 +++++++-- .../cbor/mapper/BiggerDataTest.java | 5 +++- .../cbor/mapper/BinaryReadTest.java | 10 ++++++- .../cbor/mapper/CBORMapperTest.java | 11 ++++--- .../cbor/mapper/MapperSimpleReadTest.java | 6 ++++ .../cbor/mapper/NumberArrayBeanTest.java | 8 +++++ .../cbor/mapper/NumberBeanTest.java | 20 ++++++++----- .../cbor/mapper/NumberMap269Test.java | 9 ++++-- .../dataformat/cbor/mapper/TreeNodesTest.java | 7 ++++- .../cbor/parse/Base64AsBinaryTest.java | 10 +++++-- .../cbor/parse/BasicParserTest.java | 17 ++++++++--- .../parse/BinaryToStringCoercionTest.java | 9 +++++- .../cbor/parse/CBORBigNumberParserTest.java | 13 ++++++--- .../cbor/parse/CBORNumberParseTest.java | 15 ++++++++++ .../parse/ParseIncompleteArray240Test.java | 12 ++++++-- .../parse/ParseInvalidUTF8String236Test.java | 12 +++++++- .../cbor/parse/ParserDupHandlingTest.java | 5 ++++ .../cbor/parse/ParserInteropTest.java | 16 +++++----- .../cbor/parse/ParserNextXxxTest.java | 11 ++++++- .../cbor/parse/SimpleValuesTest.java | 17 ++++++----- .../cbor/parse/SymbolTable312Test.java | 10 ++++++- .../cbor/parse/SymbolTableTest.java | 16 +++++----- .../cbor/parse/TagParsing185Test.java | 6 +++- .../cbor/parse/UndefinedValueTest.java | 14 +++++---- .../cbor/parse/UnicodeHandlingTest.java | 7 +++++ .../parse/dos/DeepNestingCBORParserTest.java | 9 +++++- .../dataformat/cbor/seq/ReadTreesTest.java | 7 ++++- .../cbor/seq/SequenceWriterTest.java | 10 +++---- .../cbor/testutil/PrefixInputDecorator.java | 8 ++--- .../cbor/testutil/PrefixOutputDecorator.java | 6 ++-- .../failure/JacksonTestFailureExpected.java | 1 + 74 files changed, 533 insertions(+), 175 deletions(-) diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORFactory.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORFactory.java index 386f7462f..3bdfc6e73 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORFactory.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORFactory.java @@ -6,8 +6,8 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.format.InputAccessor; import com.fasterxml.jackson.core.format.MatchStrength; -import com.fasterxml.jackson.core.io.IOContext; import com.fasterxml.jackson.core.io.ContentReference; +import com.fasterxml.jackson.core.io.IOContext; /** * Factory used for constructing {@link CBORParser} and {@link CBORGenerator} diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java index 2ceb648a0..e2052d1cc 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.HashMap; import com.fasterxml.jackson.core.*; diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java index 52f1d3514..0bbe8fcdf 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java @@ -5,9 +5,7 @@ import java.math.BigInteger; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Stack; +import java.util.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.base.ParserMinimalBase; @@ -15,9 +13,7 @@ import com.fasterxml.jackson.core.io.NumberInput; import com.fasterxml.jackson.core.json.DupDetector; import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer; -import com.fasterxml.jackson.core.util.ByteArrayBuilder; -import com.fasterxml.jackson.core.util.JacksonFeatureSet; -import com.fasterxml.jackson.core.util.TextBuffer; +import com.fasterxml.jackson.core.util.*; import static com.fasterxml.jackson.dataformat.cbor.CBORConstants.*; diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParserBootstrapper.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParserBootstrapper.java index 761cb6c28..19a4123a9 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParserBootstrapper.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParserBootstrapper.java @@ -1,8 +1,10 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.core.format.InputAccessor; import com.fasterxml.jackson.core.format.MatchStrength; import com.fasterxml.jackson.core.io.IOContext; diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/databind/CBORMapper.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/databind/CBORMapper.java index 785d9c774..c0b7734a9 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/databind/CBORMapper.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/databind/CBORMapper.java @@ -2,13 +2,9 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.Version; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.cfg.MapperBuilder; - -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.PackageVersion; +import com.fasterxml.jackson.dataformat.cbor.*; /** * Specialized {@link ObjectMapper} to use with CBOR format backend. diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java index 3013dc13c..b496f445e 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java @@ -2,13 +2,14 @@ import java.io.ByteArrayOutputStream; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.ObjectMapper; -// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class BrokenLongBinary186Test extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); @@ -20,12 +21,14 @@ public class BrokenLongBinary186Test extends CBORTestBase */ // [dataformats-binary#186] + @Test public void testCorruptVeryLongBinary() throws Exception { // Let's do about 2 GB to likely trigger failure _testCorruptLong(1_999_999_999, 95000); } // [dataformats-binary#186] + @Test public void testCorruptQuiteLongBinary() throws Exception { // Value below limit for chunked handling _testCorruptLong(CBORParser.LONGEST_NON_CHUNKED_BINARY >> 1, 37); @@ -51,6 +54,7 @@ private void _testCorruptLong(int allegedLength, int actualIncluded) throws Exce */ // [dataformats-binary#186] + @Test public void testQuiteLongStreaming() throws Exception { // Can try bit shorter here, like 500 megs diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java index d8babb77e..359c1a2a7 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java @@ -2,9 +2,11 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Miscellaneous tests for {@link CBORFactory}, and for some aspects @@ -16,6 +18,7 @@ public class CBORFactoryPropertiesTest extends CBORTestBase private final static CBORFactory CBOR_F = new CBORFactory(); + @Test public void testCBORFactorySerializable() throws Exception { CBORFactory f = new CBORFactory(); @@ -30,6 +33,7 @@ public void testCBORFactorySerializable() throws Exception assertArrayEquals(doc, docOut); } + @Test public void testCBORFactoryCopy() throws Exception { CBORFactory f2 = CBOR_F.copy(); @@ -39,6 +43,7 @@ public void testCBORFactoryCopy() throws Exception assertNotNull(doc); } + @Test public void testVersions() throws Exception { CBORFactory f = CBOR_F; @@ -55,6 +60,7 @@ public void testVersions() throws Exception p.close(); } + @Test public void testCapabilities() throws Exception { assertTrue(CBOR_F.canHandleBinaryNatively()); @@ -63,6 +69,7 @@ public void testCapabilities() throws Exception assertEquals(CBORGenerator.Feature.class, CBOR_F.getFormatWriteFeatureType()); } + @Test public void testInabilityToReadChars() throws Exception { final String EXP = "non-byte-based source"; @@ -86,6 +93,7 @@ public void testInabilityToReadChars() throws Exception } } + @Test public void testInabilityToWriteChars() throws Exception { try { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java index 4c983e51d..eec8a456c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java @@ -1,19 +1,16 @@ package com.fasterxml.jackson.dataformat.cbor; -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 java.util.Random; -import org.junit.Assert; - import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper; +import static org.junit.jupiter.api.Assertions.*; + public abstract class CBORTestBase - extends junit.framework.TestCase { /* /********************************************************** @@ -161,14 +158,14 @@ protected void verifyException(Throwable e, String... matches) } protected void _verifyBytes(byte[] actBytes, byte... expBytes) { - Assert.assertArrayEquals(expBytes, actBytes); + assertArrayEquals(expBytes, actBytes); } protected void _verifyBytes(byte[] actBytes, byte exp1, byte[] expRest) { byte[] expBytes = new byte[expRest.length+1]; System.arraycopy(expRest, 0, expBytes, 1, expRest.length); expBytes[0] = exp1; - Assert.assertArrayEquals(expBytes, actBytes); + assertArrayEquals(expBytes, actBytes); } protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte[] expRest) { @@ -176,7 +173,7 @@ protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte[] expRes System.arraycopy(expRest, 0, expBytes, 2, expRest.length); expBytes[0] = exp1; expBytes[1] = exp2; - Assert.assertArrayEquals(expBytes, actBytes); + assertArrayEquals(expBytes, actBytes); } protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, byte[] expRest) { @@ -185,7 +182,7 @@ protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, by expBytes[0] = exp1; expBytes[1] = exp2; expBytes[2] = exp3; - Assert.assertArrayEquals(expBytes, actBytes); + assertArrayEquals(expBytes, actBytes); } /** diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java index 9b301b7e2..49940d3c7 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java @@ -3,13 +3,14 @@ import java.io.ByteArrayOutputStream; import java.math.BigDecimal; -import static org.junit.Assert.assertArrayEquals; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; -// for [jackson-core#730] public class FloatPrecisionTest extends CBORTestBase { // for [jackson-core#730] + @Test public void testFloatRoundtrips() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FormatDefaultsTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FormatDefaultsTest.java index 5256968de..b94d5cf0c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FormatDefaultsTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FormatDefaultsTest.java @@ -1,13 +1,18 @@ package com.fasterxml.jackson.dataformat.cbor; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.StreamReadCapability; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class FormatDefaultsTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testParserDefaults() throws Exception { try (JsonParser p = MAPPER.createParser(new byte[4])) { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDeepNestingTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDeepNestingTest.java index 9306aee1c..29236d8a2 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDeepNestingTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDeepNestingTest.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.dataformat.cbor; import java.io.ByteArrayOutputStream; -import java.util.*; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class GeneratorDeepNestingTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); @@ -18,6 +23,7 @@ public class GeneratorDeepNestingTest extends CBORTestBase // for [dataformats-binary#62] @SuppressWarnings("unchecked") + @Test public void testDeeplyNestedMap() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -65,6 +71,7 @@ private void _verifyNestedMap(Map map, int level) { } } + @Test public void testDeeplyNestedArray() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDupHandlingTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDupHandlingTest.java index 3e429ea80..fff104015 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDupHandlingTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorDupHandlingTest.java @@ -1,17 +1,25 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; + public class GeneratorDupHandlingTest extends CBORTestBase { + @Test public void testSimpleDupsEagerlyBytes() throws Exception { _testSimpleDups(false, new JsonFactory()); } // Testing ability to enable checking after construction of // generator, not just via JsonFactory + @Test public void testSimpleDupsLazilyBytes() throws Exception { final JsonFactory f = new JsonFactory(); assertFalse(f.isEnabled(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION)); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInteropTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInteropTest.java index 89b7b9d5e..84d48400e 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInteropTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInteropTest.java @@ -2,6 +2,10 @@ import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + /** * Unit tests geared at testing issues that were raised due to * inter-operability with other CBOR codec implementations @@ -16,6 +20,7 @@ public class GeneratorInteropTest extends CBORTestBase }; // Test for [Issue#6], for optional writing of CBOR Type Description Tag + @Test public void testTypeDescriptionTag() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -28,6 +33,7 @@ public void testTypeDescriptionTag() throws Exception _verifyBytes(out.toByteArray(), TYPE_DESC_AND_TRUE); } + @Test public void testAutoTypeDescription() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInvalidCallsTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInvalidCallsTest.java index 3fe2f4692..51183e4df 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInvalidCallsTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorInvalidCallsTest.java @@ -2,10 +2,15 @@ import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonGenerationException; +import static org.junit.jupiter.api.Assertions.fail; + public class GeneratorInvalidCallsTest extends CBORTestBase { + @Test public void testInvalidFieldNameInRoot() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorLongStringTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorLongStringTest.java index 5ab936686..9b5cd81b8 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorLongStringTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorLongStringTest.java @@ -1,15 +1,21 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.io.SerializedString; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class GeneratorLongStringTest extends CBORTestBase { final static int DOC_LEN = 2000000; // 2 meg test doc + @Test public void testLongWithMultiBytes() throws Exception { CBORFactory f = cborFactory(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorShortStringTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorShortStringTest.java index 308d2b72a..18acc08ab 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorShortStringTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorShortStringTest.java @@ -2,11 +2,17 @@ import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class GeneratorShortStringTest extends CBORTestBase { + @Test public void testEmptyString() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (CBORGenerator gen = cborGenerator(out)) { @@ -25,6 +31,7 @@ public void testEmptyString() throws Exception { _verifyBytes(out.toByteArray(), CBORConstants.BYTE_EMPTY_STRING); } + @Test public void testShortTextAsString() throws Exception { for (int len = 1; len <= 23; ++len) { final String value = generateAsciiString(len); @@ -40,6 +47,7 @@ public void testShortTextAsString() throws Exception { } } + @Test public void testShortTextAsCharArray() throws Exception { for (int len = 1; len <= 23; ++len) { final String value = generateAsciiString(len); @@ -55,6 +63,7 @@ public void testShortTextAsCharArray() throws Exception { } } + @Test public void testMediumTextAsString() throws Exception { for (int len = 24; len <= 255; ++len) { final String value = generateAsciiString(len); @@ -71,6 +80,7 @@ public void testMediumTextAsString() throws Exception { } } + @Test public void testMediumTextAsCharArray() throws Exception { for (int len = 24; len <= 255; ++len) { final String value = generateAsciiString(len); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/MapAndArrayTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/MapAndArrayTest.java index 3a9c954d8..52cdd1d36 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/MapAndArrayTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/MapAndArrayTest.java @@ -3,12 +3,17 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + public class MapAndArrayTest extends CBORTestBase { /** * Test for verifying complex Array and Map generation with limited and unlimited size */ + @Test public void testCborBasicMap() throws IOException { /* {_"Fun": true, "Amt": -2} @@ -38,6 +43,7 @@ public void testCborBasicMap() throws IOException { assertTrue(hexData.equalsIgnoreCase("bf6346756ef563416d7421ff")); } + @Test public void testCborUnsizedMap() throws IOException { /* {_"Fun": true, 1504: -33, 1505: false, 13171233041: 22} @@ -81,6 +87,7 @@ public void testCborUnsizedMap() throws IOException { + @Test public void testCborSizedMap() throws IOException { /* {1504: -33, 1505: false, 1506: "Fun", "Amt": [2, 3], 1507: false} @@ -131,6 +138,7 @@ public void testCborSizedMap() throws IOException { assertTrue(hexData.equalsIgnoreCase("A51905e038201905e1f41905E26346756e63416d748202031905E3F4")); } + @Test public void testCborSizedMapWithParserTest() throws IOException { /* {_ 1504:-33, 1505:false, 1506:"Fun", 1507: [_"c", 3, false], 13171233041:false } @@ -192,6 +200,7 @@ public void testCborSizedMapWithParserTest() throws IOException { parser.close(); } + @Test public void testCborUnsizedMapWithArrayAsKey() throws IOException { /* {_ "a": 1, "b": [_ 2, 3]} @@ -216,6 +225,7 @@ public void testCborUnsizedMapWithArrayAsKey() throws IOException { assertTrue(hexData.equalsIgnoreCase("bf61610161629f0203ffff")); } + @Test public void testCborMultilevelMapWithMultilevelArrays() throws IOException { /* { "a": 1, "b": [_ 2, 3], 1501: ["Fun", 44, [_ 45, 46, [ 47, 48]], { "key": {_"complex": 50}, 51: "52"}, 53], 1502: {_54: "value", 55: {56:61, 57:62}}} @@ -277,6 +287,7 @@ public void testCborMultilevelMapWithMultilevelArrays() throws IOException { assertTrue(hexData.equalsIgnoreCase("a461610161629f0203ff1905dd856346756e182c9f182d182e82182f1830ffa2636b6579bf67636f6d706c65781832ff183362353218351905debf18366576616c75651837a21838183d1839183eff")); } + @Test public void testCborUnsizedMapWithAllInside() throws IOException { /* {_ 1504: { 2504:-33}, 1505:false, 1506:"Fun", 1507: [_"c", 3, false], 13171233041:false } @@ -312,6 +323,7 @@ public void testCborUnsizedMapWithAllInside() throws IOException { assertTrue(hexData.equalsIgnoreCase("BF1905e0A11909C838201905e1f41905E26346756e1905E39F616303F4FF1B0000000311111111F4FF")); } + @Test public void testCborArraysInArray() throws IOException { /* [_ 1, [2, 3], [_ 4, 5]] @@ -339,6 +351,7 @@ public void testCborArraysInArray() throws IOException { assertTrue(hexData.equalsIgnoreCase("9f018202039f0405ffff")); } + @Test public void testCborArraysInUnsizedArray() throws IOException { /* [_ 1, [2, 3], [_ 4, 5], [6, 7, [_ 8, 8, [1, 1]]], [9, 9], [_ 0, 1] ] @@ -385,6 +398,7 @@ public void testCborArraysInUnsizedArray() throws IOException { assertTrue(hexData.equalsIgnoreCase("9f018202039f0405ff8306079f080808820101ff8209099f0001ffff")); } + @Test public void testCborArraysInSizedArray() throws IOException { /* [1, [_2, 3, 4], [_ 4, [5, [_6, 6, 6]]], [7, 8, [_ 9, 10]]] @@ -428,6 +442,7 @@ public void testCborArraysInSizedArray() throws IOException { assertTrue(hexData.equalsIgnoreCase("84019f020304ff9f0482059f060606ffff8307089f090aff")); } + @Test public void testCborSizedArray() throws IOException { /* [ 33, [256, 255, ..., 0], 34 ] @@ -470,6 +485,7 @@ public void testCborSizedArray() throws IOException { assertTrue(hexData.equalsIgnoreCase("8318219901000102030405060708090A0B0C0D0E0F101112131415161718181819181A181B181C181D181E181F1820182118221823182418251826182718281829182A182B182C182D182E182F1830183118321833183418351836183718381839183A183B183C183D183E183F1840184118421843184418451846184718481849184A184B184C184D184E184F1850185118521853185418551856185718581859185A185B185C185D185E185F1860186118621863186418651866186718681869186A186B186C186D186E186F1870187118721873187418751876187718781879187A187B187C187D187E187F1880188118821883188418851886188718881889188A188B188C188D188E188F1890189118921893189418951896189718981899189A189B189C189D189E189F18A018A118A218A318A418A518A618A718A818A918AA18AB18AC18AD18AE18AF18B018B118B218B318B418B518B618B718B818B918BA18BB18BC18BD18BE18BF18C018C118C218C318C418C518C618C718C818C918CA18CB18CC18CD18CE18CF18D018D118D218D318D418D518D618D718D818D918DA18DB18DC18DD18DE18DF18E018E118E218E318E418E518E618E718E818E918EA18EB18EC18ED18EE18EF18F018F118F218F318F418F518F618F718F818F918FA18FB18FC18FD18FE18FF1901001822")); } + @Test public void testCborSizedArrayWithMap() throws IOException { /* ["a", {_ "b": "c", "d": "e", }] diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/NumberCoercing32Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/NumberCoercing32Test.java index a5832920e..34f337f8b 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/NumberCoercing32Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/NumberCoercing32Test.java @@ -1,9 +1,14 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.util.*; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class NumberCoercing32Test extends CBORTestBase { /* @@ -12,6 +17,7 @@ public class NumberCoercing32Test extends CBORTestBase /********************************************************** */ + @Test public void testPrimitiveTypeInvariance() throws Exception { ObjectMapper mapper = new ObjectMapper( diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserInputStreamTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserInputStreamTest.java index 4d258fcee..a82909e66 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserInputStreamTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserInputStreamTest.java @@ -1,22 +1,22 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.SequenceInputStream; +import java.io.*; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonLocation; -import com.fasterxml.jackson.core.JsonParser; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + public class ParserInputStreamTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); // for [dataformat-cbor#13] + @Test public void testInpuStream() throws Exception { byte[] buffer = generateHugeCBOR(MAPPER.getFactory()); @@ -36,6 +36,7 @@ public void testInpuStream() throws Exception { assertNotNull(jsonNode); } + @Test public void testInputStreamWithHugeValueThatOverlaps() throws Exception { final byte[] buffer = new byte[8002]; buffer[0] = 0x79; // string length 7996 + 3 init bytes diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java index a591bf67e..bbedbd71c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java @@ -2,9 +2,14 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * Tests that use the json.org sample document. */ @@ -38,6 +43,7 @@ public class ParserWithJsonOrgSampleTest extends CBORTestBase +"}" ; + @Test public void testJsonSampleDoc() throws IOException { byte[] data = cborDoc(SAMPLE_DOC_JSON_SPEC); @@ -47,6 +53,7 @@ public void testJsonSampleDoc() throws IOException verifyJsonSpecSampleDoc(cborParser(data), false, true); } + @Test public void testJsonSampleDocStringref() throws IOException { byte[] data = cborDoc( diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java index 41b4a58cf..2c2be4062 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java @@ -2,13 +2,14 @@ import java.io.ByteArrayOutputStream; -import com.fasterxml.jackson.annotation.*; +import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.annotation.JsonRawValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.*; - -// for [dataformats-binary#43] public class SharedRawGeneratorBufferTest extends CBORTestBase { public static class RawBean { @@ -25,6 +26,7 @@ public String getValue() { } } + @Test public void testSharedBuffersWithRaw() throws Exception { String data = "{\"x\":\"" + generate(5000) + "\"}"; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringrefTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringrefTest.java index 28db94187..498b74aae 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringrefTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringrefTest.java @@ -1,21 +1,22 @@ package com.fasterxml.jackson.dataformat.cbor; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.io.*; import java.math.BigInteger; import java.nio.charset.StandardCharsets; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.io.SerializedString; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Basic testing for string reference generation added in 2.15. */ public class StringrefTest extends CBORTestBase { + @Test public void testSimpleObject() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -97,6 +98,7 @@ public void testSimpleObject() throws Exception { assertToken(JsonToken.END_ARRAY, parser.nextToken()); } + @Test public void testSimpleObjectSerializedStrings() throws Exception { // SerializableString interface takes different code paths. ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -187,6 +189,7 @@ public void testSimpleObjectSerializedStrings() throws Exception { assertToken(JsonToken.END_ARRAY, parser.nextToken()); } + @Test public void testStringArray() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -232,6 +235,7 @@ public void testStringArray() throws Exception { verifyStringArray(encoded); } + @Test public void testStringArrayFromChars() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -277,6 +281,7 @@ public void testStringArrayFromChars() throws Exception { verifyStringArray(encoded); } + @Test public void testStringArraySerializedString() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -322,6 +327,7 @@ public void testStringArraySerializedString() throws Exception { verifyStringArray(encoded); } + @Test public void testStringArrayUTF8() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -367,6 +373,7 @@ public void testStringArrayUTF8() throws Exception { verifyStringArray(encoded); } + @Test public void testStringArrayNextTextValue() throws Exception { // nextTextValue() takes a separate code path. Use the expected encoded bytes since there's // no special overload we want to test for encoding. @@ -407,6 +414,7 @@ public void testStringArrayNextTextValue() throws Exception { verifyNextTextValueRef(ssssStr, parser); } + @Test public void testBinaryStringArray() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -487,6 +495,7 @@ public void testBinaryStringArray() throws Exception { verifyNextTokenBinaryRef(ssssStr, parser); } + @Test public void testBinaryStringArrayStream() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); @@ -567,6 +576,7 @@ public void testBinaryStringArrayStream() throws Exception { verifyNextTokenBinaryStream("ssss", parser); } + @Test public void testNestedNamespaces() throws Exception { byte[] nestedNamespaceBytes = new byte[]{ (byte) 0xD9, 0x01, 0x00, (byte) 0x85, 0x63, 0x61, 0x61, 0x61, (byte) 0xD8, 0x19, @@ -595,6 +605,7 @@ public void testNestedNamespaces() throws Exception { assertToken(JsonToken.END_ARRAY, parser.nextToken()); } + @Test public void testNestedTags() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = new CBORFactory() @@ -627,6 +638,7 @@ public void testNestedTags() throws Exception { assertToken(JsonToken.END_ARRAY, parser.nextToken()); } + @Test public void testNestedTagsRounddTrip() throws Exception { CBORParser parser = cborParser(_nestedTagBytes); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/filter/StreamingDecoratorsTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/filter/StreamingDecoratorsTest.java index 59337705a..3e3eaa522 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/filter/StreamingDecoratorsTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/filter/StreamingDecoratorsTest.java @@ -1,14 +1,21 @@ package com.fasterxml.jackson.dataformat.cbor.filter; -import java.io.*; +import java.io.ByteArrayOutputStream; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.dataformat.cbor.*; +import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.testutil.PrefixInputDecorator; import com.fasterxml.jackson.dataformat.cbor.testutil.PrefixOutputDecorator; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class StreamingDecoratorsTest extends CBORTestBase { + @Test public void testInputDecorators() throws Exception { final byte[] DOC = cborDoc("42 37"); @@ -24,6 +31,7 @@ public void testInputDecorators() throws Exception p.close(); } + @Test public void testOutputDecorators() throws Exception { final byte[] DOC = cborDoc(" 137"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz451_65617_IOOBETest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz451_65617_IOOBETest.java index e3871e72d..4481e9fff 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz451_65617_IOOBETest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz451_65617_IOOBETest.java @@ -1,17 +1,20 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class CBORFuzz451_65617_IOOBETest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidText() throws Exception { final byte[] input = readResource("/data/clusterfuzz-cbor-65617.cbor"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz458_65768_NPETest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz458_65768_NPETest.java index 814167f5b..65b0bf0af 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz458_65768_NPETest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz458_65768_NPETest.java @@ -1,17 +1,20 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class CBORFuzz458_65768_NPETest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidText() throws Exception { final byte[] input = readResource("/data/clusterfuzz-cbor-65768.cbor"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz464_65722_IOOBETest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz464_65722_IOOBETest.java index 1563eb91b..47b0866fc 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz464_65722_IOOBETest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz464_65722_IOOBETest.java @@ -1,17 +1,20 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class CBORFuzz464_65722_IOOBETest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidText() throws Exception { final byte[] input = { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz_35979_StringValueTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz_35979_StringValueTest.java index cd75ad9cf..6d78bc70e 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz_35979_StringValueTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/CBORFuzz_35979_StringValueTest.java @@ -1,13 +1,15 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class CBORFuzz_35979_StringValueTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); @@ -19,6 +21,7 @@ public class CBORFuzz_35979_StringValueTest extends CBORTestBase // which indicates multi-byte UTF-8 character; decoder does not verify // there are more bytes available. If at end of buffer, hits ArrayIndex; // otherwise would return corrupt character with data past content end + @Test public void testInvalidTextValueWithBrokenUTF8() throws Exception { final byte[] input = readResource("/data/clusterfuzz-cbor-35979.cbor"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java index 891843b11..28375bd77 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java @@ -2,18 +2,22 @@ import java.math.BigDecimal; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.JsonParser.NumberType; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; -// [dataformats-binary#264] +import static org.junit.jupiter.api.Assertions.*; + public class Fuzz264_32381BigDecimalScaleTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidBigDecimal() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz267_32579BigDecimalTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz267_32579BigDecimalTest.java index 85613411b..9587b6319 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz267_32579BigDecimalTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz267_32579BigDecimalTest.java @@ -2,15 +2,21 @@ import java.math.BigDecimal; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class Fuzz267_32579BigDecimalTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); // [dataformats-binary#267] + @Test public void testBigDecimalOverflow() throws Exception { // final byte[] input = readResource("/data/clusterfuzz-cbor-32579.cbor"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz272_32722_ChunkedTextTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz272_32722_ChunkedTextTest.java index 15d5700ff..d5a9ef9f6 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz272_32722_ChunkedTextTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz272_32722_ChunkedTextTest.java @@ -1,17 +1,21 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class Fuzz272_32722_ChunkedTextTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); // [dataformats-binary#272] + @Test public void testChunkedWithUTF8_4Bytes() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz273_32912_ChunkedTextTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz273_32912_ChunkedTextTest.java index ae339e182..8161e735c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz273_32912_ChunkedTextTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz273_32912_ChunkedTextTest.java @@ -1,17 +1,22 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class Fuzz273_32912_ChunkedTextTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); // [dataformats-binary#273] // (see https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32912) + @Test public void testChunkedWithUTF8_4Bytes_v2() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz288_35750_NonCanonicalNameTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz288_35750_NonCanonicalNameTest.java index 212a1be90..cb0839d42 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz288_35750_NonCanonicalNameTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz288_35750_NonCanonicalNameTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; @@ -11,6 +13,7 @@ public class Fuzz288_35750_NonCanonicalNameTest extends CBORTestBase // [dataformats-binary#288]: non-canonical representation for length of 0 // causing ArrayOutOfBoundsException + @Test public void testInvalidLongName() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz289_35822_TruncatedNameTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz289_35822_TruncatedNameTest.java index 0326be5ac..001225674 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz289_35822_TruncatedNameTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz289_35822_TruncatedNameTest.java @@ -1,11 +1,15 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class Fuzz289_35822_TruncatedNameTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); @@ -13,6 +17,7 @@ public class Fuzz289_35822_TruncatedNameTest extends CBORTestBase // As per https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35822 // ArrayIndexOutOfBoundsException when 2 out of 3 bytes available before // end-of-input + @Test public void testInvalidSplitUtf8Unit() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32173LongTextTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32173LongTextTest.java index a76761b6a..3d2136786 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32173LongTextTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32173LongTextTest.java @@ -1,15 +1,18 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; -import com.fasterxml.jackson.core.io.JsonEOFException; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.io.JsonEOFException; import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class Fuzz32173LongTextTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testTruncatedLongText() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32250BigIntegerTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32250BigIntegerTest.java index 13ba8d7f2..049a0ab5c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32250BigIntegerTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32250BigIntegerTest.java @@ -2,14 +2,20 @@ import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class Fuzz32250BigIntegerTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidShortText() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32912ChunkedTextTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32912ChunkedTextTest.java index a4ef4baf8..04fd7b0cc 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32912ChunkedTextTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz32912ChunkedTextTest.java @@ -1,17 +1,20 @@ package com.fasterxml.jackson.dataformat.cbor.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.io.JsonEOFException; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class Fuzz32912ChunkedTextTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testInvalidShortText() throws Exception { final byte[] input = new byte[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/ArrayGenerationTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/ArrayGenerationTest.java index a098b5606..f1d8d3c11 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/ArrayGenerationTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/ArrayGenerationTest.java @@ -2,12 +2,13 @@ import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.JsonParser.NumberType; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.*; /** * Basic testing for scalar-array write methods added in 2.8. @@ -16,21 +17,25 @@ public class ArrayGenerationTest extends CBORTestBase { private final CBORFactory FACTORY = new CBORFactory(); + @Test public void testIntArray() throws Exception { _testIntArray(); } + @Test public void testLongArray() throws Exception { _testLongArray(); } + @Test public void testDoubleArray() throws Exception { _testDoubleArray(); } + @Test public void testMinimalIntValuesForInt() throws Exception { // Array with 3 values, with different sizing @@ -93,6 +98,7 @@ private void _testMinimalIntValuesForInt(int v1, int v2, p.close(); } + @Test public void testMinimalIntValuesForLong() throws Exception { // Array with 2 values that can't be passed as `int`s but DO fit @@ -150,6 +156,7 @@ public void testMinimalIntValuesForLong() throws Exception p.close(); } + @Test public void testMinimalFloatValuesForDouble() throws Exception { // Array with 2 values, one that can be represented as a float without losing precision and diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java index 0abb7402d..3332e7a93 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java @@ -5,6 +5,7 @@ import java.security.SecureRandom; import org.junit.*; +import org.junit.jupiter.api.Test; import org.junit.rules.TemporaryFolder; import com.fasterxml.jackson.core.JsonGenerator; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java index 2c9e45d7d..42d7e7c65 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java @@ -1,20 +1,19 @@ package com.fasterxml.jackson.dataformat.cbor.gen; -import java.io.*; +import java.io.ByteArrayOutputStream; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerationException; - import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.cbor.*; -import com.fasterxml.jackson.dataformat.cbor.CBORConstants; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.*; public class GeneratorSimpleTest extends CBORTestBase { @@ -23,6 +22,7 @@ public class GeneratorSimpleTest extends CBORTestBase /** * Test for verifying handling of 'true', 'false' and 'null' literals */ + @Test public void testSimpleLiterals() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -49,6 +49,7 @@ public void testSimpleLiterals() throws Exception _verifyBytes(out.toByteArray(), CBORConstants.BYTE_NULL); } + @Test public void testMinimalIntValues() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -87,6 +88,7 @@ public void testMinimalIntValues() throws Exception } // [dataformats-binary#201] + @Test public void testMinimalIntValues2() throws Exception { ByteArrayOutputStream out; @@ -113,6 +115,7 @@ public void testMinimalIntValues2() throws Exception (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF); } + @Test public void testIntValues() throws Exception { // first, single-byte @@ -179,6 +182,7 @@ public void testIntValues() throws Exception (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF); } + @Test public void testLongValues() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -198,6 +202,7 @@ public void testLongValues() throws Exception assertEquals(0, b[3]); } + @Test public void testFloatValues() throws Exception { // first, 32-bit float @@ -234,6 +239,7 @@ public void testFloatValues() throws Exception } // [dataformats-binary#139]: wrong encoding of BigDecimal + @Test public void testBigDecimalValues() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -254,6 +260,7 @@ public void testBigDecimalValues() throws Exception Assert.assertArrayEquals(spec, b); } + @Test public void testEmptyArray() throws Exception { // First: empty array (2 bytes) @@ -266,6 +273,7 @@ public void testEmptyArray() throws Exception CBORConstants.BYTE_BREAK); } + @Test public void testEmptyObject() throws Exception { // First: empty array (2 bytes) @@ -278,6 +286,7 @@ public void testEmptyObject() throws Exception CBORConstants.BYTE_BREAK); } + @Test public void testIntArray() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -313,6 +322,7 @@ public void testIntArray() throws Exception _verifyBytes(b, EXP); } + @Test public void testTrivialObject() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -344,6 +354,7 @@ public void testTrivialObject() throws Exception _verifyBytes(b, EXP); } + @Test public void testLongerText() throws Exception { // First, something with 8-bit length @@ -386,6 +397,7 @@ public void testLongerText() throws Exception b); } + @Test public void testInvalidWrites() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -414,6 +426,7 @@ public void testInvalidWrites() throws Exception gen.close(); } + @Test public void testCopyCurrentEventWithTag() throws Exception { final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream(); final CBORGenerator sourceGen = cborGenerator(sourceBytes); @@ -440,6 +453,7 @@ public void testCopyCurrentEventWithTag() throws Exception { targetBytes.toByteArray()); } + @Test public void testCopyCurrentStructureWithTaggedArray() throws Exception { final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream(); final CBORGenerator sourceGen = cborGenerator(sourceBytes); @@ -466,6 +480,7 @@ public void testCopyCurrentStructureWithTaggedArray() throws Exception { } + @Test public void testCopyCurrentStructureWithTaggedBinary() throws Exception { final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream(); final CBORGenerator sourceGen = cborGenerator(sourceBytes); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/LenientUnicodeCBORGenerationTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/LenientUnicodeCBORGenerationTest.java index 3843d31ac..b9a2eeca8 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/LenientUnicodeCBORGenerationTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/LenientUnicodeCBORGenerationTest.java @@ -2,15 +2,20 @@ import java.io.ByteArrayOutputStream; -import com.fasterxml.jackson.core.exc.StreamWriteException; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.exc.StreamWriteException; import com.fasterxml.jackson.dataformat.cbor.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class LenientUnicodeCBORGenerationTest extends CBORTestBase { /** * Test that encoding a String containing invalid surrogates fail with an exception */ + @Test public void testFailForInvalidSurrogate() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -70,6 +75,7 @@ public void testFailForInvalidSurrogate() throws Exception /** * Test that when the lenient unicode feature is enabled, the replacement character is used to fix invalid sequences */ + @Test public void testRecoverInvalidSurrogate1() throws Exception { ByteArrayOutputStream out; @@ -110,6 +116,7 @@ public void testRecoverInvalidSurrogate1() throws Exception (byte) (CBORConstants.PREFIX_TYPE_TEXT + b.length), b); } + @Test public void testRecoverInvalidSurrogate2() throws Exception { ByteArrayOutputStream out; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/TestGeneratorClosing.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/TestGeneratorClosing.java index 065a889b2..f1da3e834 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/TestGeneratorClosing.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/TestGeneratorClosing.java @@ -1,10 +1,14 @@ package com.fasterxml.jackson.dataformat.cbor.gen; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.testutil.ByteOutputStreamForTesting; +import static org.junit.jupiter.api.Assertions.*; + /** * Set of basic unit tests that verify aspect of closing a * {@link JsonGenerator} instance. This includes both closing @@ -30,6 +34,7 @@ public class TestGeneratorClosing extends CBORTestBase * automatic closing should occur, nor explicit one unless specific * forcing method is used. */ + @Test public void testNoAutoCloseGenerator() throws Exception { JsonFactory f = cborFactory(); @@ -52,6 +57,7 @@ public void testNoAutoCloseGenerator() throws Exception } } + @Test public void testCloseGenerator() throws Exception { JsonFactory f = cborFactory(); @@ -68,6 +74,7 @@ public void testCloseGenerator() throws Exception assertTrue(output.isClosed()); } + @Test public void testNoAutoCloseOutputStream() throws Exception { JsonFactory f = cborFactory(); @@ -83,6 +90,7 @@ public void testNoAutoCloseOutputStream() throws Exception } @SuppressWarnings("resource") + @Test public void testAutoFlushOrNot() throws Exception { JsonFactory f = cborFactory(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/DeeplyNestedCBORReadWriteTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/DeeplyNestedCBORReadWriteTest.java index db86a37e8..ed46b01df 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/DeeplyNestedCBORReadWriteTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/DeeplyNestedCBORReadWriteTest.java @@ -1,18 +1,19 @@ package com.fasterxml.jackson.dataformat.cbor.gen.constraints; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.StreamReadConstraints; -import com.fasterxml.jackson.core.StreamWriteConstraints; -import com.fasterxml.jackson.core.exc.StreamConstraintsException; +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.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; - import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class DeeplyNestedCBORReadWriteTest extends CBORTestBase { private final ObjectMapper MAPPER_VANILLA = cborMapper(); @@ -27,10 +28,12 @@ public class DeeplyNestedCBORReadWriteTest extends CBORTestBase .build() ); + @Test public void testDeepNestingArrayRead() throws Exception { _testDeepNestingRead(createDeepNestedArrayDoc(13)); } + @Test public void testDeepNestingObjectRead() throws Exception { _testDeepNestingRead(createDeepNestedObjectDoc(13)); } @@ -47,10 +50,12 @@ private void _testDeepNestingRead(JsonNode docRoot) throws Exception } } + @Test public void testDeepNestingArrayWrite() throws Exception { _testDeepNestingWrite(createDeepNestedArrayDoc(13)); } + @Test public void testDeepNestingObjectWrite() throws Exception { _testDeepNestingWrite(createDeepNestedObjectDoc(13)); } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/LongDocumentCBORReadTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/LongDocumentCBORReadTest.java index 17763d312..3dcda72e6 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/LongDocumentCBORReadTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/LongDocumentCBORReadTest.java @@ -4,15 +4,17 @@ import java.io.ByteArrayOutputStream; import java.util.UUID; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.StreamReadConstraints; -import com.fasterxml.jackson.core.exc.StreamConstraintsException; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + public class LongDocumentCBORReadTest extends CBORTestBase { private final ObjectMapper MAPPER_VANILLA = cborMapper(); @@ -25,6 +27,7 @@ public class LongDocumentCBORReadTest extends CBORTestBase .build() ).build()); + @Test public void testLongDocumentConstraint() throws Exception { // Need a bit longer than minimum since checking is approximate, not exact diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/dos/CyclicCBORDataSerTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/dos/CyclicCBORDataSerTest.java index 46e0cd112..4aaa828bf 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/dos/CyclicCBORDataSerTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/dos/CyclicCBORDataSerTest.java @@ -3,10 +3,16 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.StreamWriteConstraints; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.DatabindException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +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). @@ -15,6 +21,7 @@ public class CyclicCBORDataSerTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testListWithSelfReference() throws Exception { List list = new ArrayList<>(); list.add(list); @@ -24,8 +31,8 @@ public void testListWithSelfReference() throws Exception { } catch (DatabindException jmex) { String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); - assertTrue("DatabindException message is as expected?", - jmex.getMessage().startsWith(exceptionPrefix)); + assertTrue(jmex.getMessage().startsWith(exceptionPrefix), + "DatabindException message is as expected?"); } } } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java index ed2dbcf22..091cdc014 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java @@ -2,11 +2,14 @@ import java.util.*; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Bigger test to try to do smoke-testing of overall functionality, * using more sizable (500k of JSON, 200k of encoded data) dataset. diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java index 7a6e3570a..2ffa33913 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java @@ -1,8 +1,10 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.core.JsonParser; @@ -11,6 +13,8 @@ import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; +import static org.junit.jupiter.api.Assertions.*; + public class BinaryReadTest extends CBORTestBase { final static class Bytes { @@ -34,6 +38,7 @@ public Bytes3(byte[] b) { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testSmallBinaryValues() throws Exception { _testBinary(0); _testBinary(1); @@ -41,12 +46,14 @@ public void testSmallBinaryValues() throws Exception { _testBinary(100); } + @Test public void testMediumBinaryValues() throws Exception { _testBinary(500); _testBinary(1500); _testBinary(8900); } + @Test public void testLargeBinaryValues() throws Exception { _testBinary(99000); _testBinary(299000); @@ -54,6 +61,7 @@ public void testLargeBinaryValues() throws Exception { } // And then one test just to ensure no state corruption occurs + @Test public void testMultipleBinaryFields() throws Exception { byte[] inputBytes = new byte[900]; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java index 7666494ac..b36d1b199 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java @@ -1,16 +1,18 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; public class CBORMapperTest extends CBORTestBase { // For [dataformats-binary#301] + @Test public void testStreamingFeaturesViaMapper() throws Exception { final int SMALL_INT = 3; @@ -42,6 +44,7 @@ public void testStreamingFeaturesViaMapper() throws Exception } // [databind#3212] + @Test public void testMapperCopy() throws Exception { CBORMapper src = cborMapper(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/MapperSimpleReadTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/MapperSimpleReadTest.java index 7452dd870..f19016c47 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/MapperSimpleReadTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/MapperSimpleReadTest.java @@ -3,15 +3,20 @@ import java.util.LinkedHashMap; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class MapperSimpleReadTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testSimpleArray() throws Exception { byte[] b = MAPPER.writeValueAsBytes(new int[] { 1, 2, 3, 4}); @@ -22,6 +27,7 @@ public void testSimpleArray() throws Exception } } + @Test public void testSimpleObject() throws Exception { Map input = new LinkedHashMap(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java index 79aa22538..a89b85572 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java @@ -1,8 +1,13 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + public class NumberArrayBeanTest extends CBORTestBase { static class IntsWrapper { @@ -34,6 +39,7 @@ protected DoublesWrapper() { } private final ObjectMapper MAPPER = cborMapper(); + @Test public void testIntArrayRoundTrip() throws Exception { int[][] inputArray = new int[][]{ { -5, 3 } }; @@ -47,6 +53,7 @@ public void testIntArrayRoundTrip() throws Exception assertEquals(inputArray[0][1], result.values[0][1]); } + @Test public void testLongArrayRoundTrip() throws Exception { long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } }; @@ -61,6 +68,7 @@ public void testLongArrayRoundTrip() throws Exception } // for [dataformats-binary#31] + @Test public void testDoubleArrayRoundTrip() throws Exception { double[][] inputArray = new double[][]{ { 0.25, -1.5 } }; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java index 1401eca1a..801015176 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java @@ -4,16 +4,15 @@ import java.math.BigDecimal; import java.math.BigInteger; -import com.fasterxml.jackson.annotation.JsonUnwrapped; +import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.core.JsonParser.NumberType; - +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class NumberBeanTest extends CBORTestBase { @@ -56,6 +55,7 @@ static class NestedBigDecimalHolder2784 { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testIntRoundTrip() throws Exception { for (int i : new int[] { 0, 1, -1, @@ -69,6 +69,7 @@ public void testIntRoundTrip() throws Exception } } + @Test public void testLongRoundTrip() throws Exception { for (long v : new long[] { 0, 1, -1, @@ -100,6 +101,7 @@ private void _testLongRoundTrip(long v) throws Exception } // for [dataformats-binary#32] coercion of Float into Double + @Test public void testUntypedWithFloat() throws Exception { Object[] input = new Object[] { Float.valueOf(0.5f) }; @@ -110,6 +112,7 @@ public void testUntypedWithFloat() throws Exception assertEquals(input[0], result[0]); } + @Test public void testNumberTypeRetainingInt() throws Exception { NumberWrapper result; @@ -143,6 +146,7 @@ public void testNumberTypeRetainingInt() throws Exception assertEquals(BigInteger.valueOf(-42L), result.nr); } + @Test public void testNumberTypeRetainingFP() throws Exception { NumberWrapper result; @@ -176,6 +180,7 @@ public void testNumberTypeRetainingFP() throws Exception assertEquals(new BigDecimal("0.100"), result.nr); } + @Test public void testNumberTypeRetainingBuffering() throws Exception { ByteArrayOutputStream bytes; @@ -235,6 +240,7 @@ public void testNumberTypeRetainingBuffering() throws Exception } // [databind#2784] + @Test public void testBigDecimalWithBuffering() throws Exception { final BigDecimal VALUE = new BigDecimal("5.00"); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberMap269Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberMap269Test.java index e203f8cd2..38c18f88a 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberMap269Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberMap269Test.java @@ -1,11 +1,15 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; -// [dataformats-binary#269] +import static org.junit.jupiter.api.Assertions.assertEquals; + public class NumberMap269Test extends CBORTestBase { static class TestData269 { @@ -30,6 +34,7 @@ public Map getMap() { private final ObjectMapper MAPPER = cborMapper(); // [dataformats-binary#269] + @Test public void testInt32BoundaryWithMapKey() throws Exception { // First, with specific reported combo: diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java index 288b418f4..9959fe1f2 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java @@ -1,17 +1,21 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; + +import static org.junit.jupiter.api.Assertions.*; public class TreeNodesTest extends CBORTestBase { private final ObjectMapper MAPPER = new ObjectMapper(new CBORFactory()); + @Test public void testSimple() throws Exception { // create the serialized JSON with byte array @@ -36,6 +40,7 @@ public void testSimple() throws Exception Assert.assertArrayEquals(TEXT_BYTES, bytes); } + @Test public void testNumbers() throws Exception { ObjectNode root = MAPPER.createObjectNode(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/Base64AsBinaryTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/Base64AsBinaryTest.java index c6e56608d..48c7c70e9 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/Base64AsBinaryTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/Base64AsBinaryTest.java @@ -3,13 +3,15 @@ import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; -import org.junit.Assert; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class Base64AsBinaryTest extends CBORTestBase { private final static String ENCODED_BASE64 = "VGVzdCE="; @@ -24,6 +26,7 @@ public Base64AsBinaryTest() throws Exception { } // [dataformats-binary#284]: binary from Base64 encoded + @Test public void testGetBase64AsBinary() throws Exception { // First, verify regularly @@ -42,13 +45,14 @@ public void testGetBase64AsBinary() throws Exception assertToken(JsonToken.FIELD_NAME, p.nextToken()); assertToken(JsonToken.VALUE_STRING, p.nextToken()); byte[] binary = p.getBinaryValue(); - Assert.assertArrayEquals(DECODED_BASE64, binary); + assertArrayEquals(DECODED_BASE64, binary); assertToken(JsonToken.END_OBJECT, p.nextToken()); assertNull(p.nextToken()); } } // [dataformats-binary#284]: binary from Base64 encoded + @Test public void testReadBase64AsBinary() throws Exception { // And further via read @@ -59,7 +63,7 @@ public void testReadBase64AsBinary() throws Exception ByteArrayOutputStream bytes = new ByteArrayOutputStream(); int count = p.readBinaryValue(bytes); assertEquals(5, count); - Assert.assertArrayEquals(DECODED_BASE64, bytes.toByteArray()); + assertArrayEquals(DECODED_BASE64, bytes.toByteArray()); assertToken(JsonToken.END_OBJECT, p.nextToken()); assertNull(p.nextToken()); } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BasicParserTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BasicParserTest.java index 55889ae4e..dc287d8a1 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BasicParserTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BasicParserTest.java @@ -2,13 +2,14 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.dataformat.cbor.CBORConstants; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for simple value types. */ @@ -17,6 +18,7 @@ public class BasicParserTest extends CBORTestBase /** * Test for verifying handling of 'true', 'false' and 'null' literals */ + @Test public void testSimpleLiterals() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -50,6 +52,7 @@ public void testSimpleLiterals() throws Exception p.close(); } + @Test public void testMediumText() throws Exception { _testMedium(1100); @@ -80,6 +83,7 @@ private void _testMedium(int len) throws Exception p.close(); } + @Test public void testCurrentLocationByteOffset() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORGenerator gen = cborGenerator(out); @@ -108,6 +112,7 @@ public void testCurrentLocationByteOffset() throws Exception { assertEquals(22, p.currentLocation().getByteOffset()); } + @Test public void testLongNonChunkedText() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -147,6 +152,7 @@ public void testLongNonChunkedText() throws Exception p.close(); } + @Test public void testLongChunkedText() throws Exception { // First, try with ASCII content @@ -236,6 +242,7 @@ private void _debugDiff(String expected, String actual) +Integer.toHexString(actual.charAt(i))); } + @Test public void testStringField() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORGenerator generator = cborGenerator(out); @@ -266,6 +273,7 @@ public void testStringField() throws IOException { parser.close(); } + @Test public void testNestedObject() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -310,6 +318,7 @@ public void testNestedObject() throws IOException parser.close(); } + @Test public void testBufferRelease() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BinaryToStringCoercionTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BinaryToStringCoercionTest.java index dc12ac1a1..2a90f16d4 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BinaryToStringCoercionTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/BinaryToStringCoercionTest.java @@ -2,10 +2,13 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; -// Tests for [dataformat-binary#188], lacking coercions for Binary->String wrt containers +import static org.junit.jupiter.api.Assertions.assertEquals; + public class BinaryToStringCoercionTest extends CBORTestBase { static class BinaryListWrapper { @@ -44,6 +47,7 @@ static class StringMapWrapper { private final ObjectMapper CBOR_MAPPER = cborMapper(); + @Test public void testWithList() throws Exception { byte[] doc = CBOR_MAPPER.writeValueAsBytes(new BinaryListWrapper()); @@ -52,6 +56,7 @@ public void testWithList() throws Exception assertEquals(String.class, result.data.get(0).getClass()); } + @Test public void testWithSet() throws Exception { byte[] doc = CBOR_MAPPER.writeValueAsBytes(new BinarySetWrapper()); @@ -60,6 +65,7 @@ public void testWithSet() throws Exception assertEquals(String.class, result.data.iterator().next().getClass()); } + @Test public void testWithMap() throws Exception { byte[] doc = CBOR_MAPPER.writeValueAsBytes(new BinaryMapWrapper()); @@ -68,6 +74,7 @@ public void testWithMap() throws Exception assertEquals(String.class, result.data.get("key").getClass()); } + @Test public void testWithArray() throws Exception { byte[] doc = CBOR_MAPPER.writeValueAsBytes(new BinaryArrayWrapper()); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORBigNumberParserTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORBigNumberParserTest.java index d33a8c048..df5eba8d5 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORBigNumberParserTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORBigNumberParserTest.java @@ -4,14 +4,17 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -// tests for [cbor#17] public class CBORBigNumberParserTest extends CBORTestBase { + @Test public void testBigDecimalShort() throws Exception { _testBigDecimal(BigDecimal.ONE); @@ -33,6 +36,7 @@ public void testBigDecimalShort() throws Exception _testBigDecimal(bd.negate()); } + @Test public void testBigDecimalLonger() throws Exception { // ensure mantissa is beyond long; more than 22 digits or so @@ -90,6 +94,7 @@ private void _testBigDecimalInObject(BigDecimal expValue) throws Exception } } + @Test public void testBigInteger() throws Exception { _testBigInteger(BigInteger.TEN); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java index 95f9d2854..99aafeca2 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java @@ -13,10 +13,15 @@ import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; @SuppressWarnings("resource") +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + public class CBORNumberParseTest extends CBORTestBase { private final CBORFactory CBOR_F = cborFactory(); + @Test public void testIntValues() throws Exception { // first, single-byte @@ -71,6 +76,7 @@ private void _verifyInt(CBORFactory f, int value) throws Exception // Special tests for "gray area" for uint32 values that do not fit // in Java int; from [dataformats-binary#30] + @Test public void testInt32Overflow() throws Exception { // feed in max uint32, which is 2x+1 as big as Integer.MAX_VALUE @@ -111,6 +117,7 @@ public void testInt32Overflow() throws Exception p.close(); } + @Test public void testLongValues() throws Exception { _verifyLong(CBOR_F, 1L + Integer.MAX_VALUE); @@ -150,6 +157,7 @@ private void _verifyLong(CBORFactory f, long value) throws Exception // Special tests for "gray area" for uint64 values that do not fit // in Java long; from [dataformats-binary#30] + @Test public void testInt64Overflow() throws Exception { // feed in max uint64, which is 2x+1 as big as Long.MAX_VALUE @@ -197,6 +205,7 @@ public void testInt64Overflow() throws Exception p.close(); } + @Test public void testDoubleValues() throws Exception { _verifyDouble(CBOR_F, 0.25, false); @@ -233,6 +242,7 @@ private void _verifyDouble(CBORFactory f, double value, boolean isNaN) throws Ex p.close(); } + @Test public void testFloatValues() throws Exception { // first, single-byte @@ -308,6 +318,7 @@ private void _verifyHalfFloat(JsonFactory f, int i16, double value) throws IOExc p.close(); } + @Test public void testFloatNumberType() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORGenerator generator = cborGenerator(out); @@ -331,6 +342,7 @@ public void testFloatNumberType() throws IOException { p.close(); } + @Test public void testBigDecimalType() throws IOException { final BigDecimal NR = new BigDecimal("172.125"); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -350,6 +362,7 @@ public void testBigDecimalType() throws IOException { } } + @Test public void testBigDecimalType2() throws IOException { // Almost good. But [dataformats#139] to consider too, see // [https://tools.ietf.org/html/rfc7049#section-2.4.2] @@ -368,6 +381,7 @@ public void testBigDecimalType2() throws IOException { } } + @Test public void testVeryBigDecimalType() throws IOException { final int len = 10000; final StringBuilder sb = new StringBuilder(); @@ -392,6 +406,7 @@ public void testVeryBigDecimalType() throws IOException { } } + @Test public void testVeryBigDecimalWithUnlimitedNumLength() throws IOException { final int len = 10000; final StringBuilder sb = new StringBuilder(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseIncompleteArray240Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseIncompleteArray240Test.java index 30f232f05..e6f732f33 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseIncompleteArray240Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseIncompleteArray240Test.java @@ -1,16 +1,19 @@ package com.fasterxml.jackson.dataformat.cbor.parse; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.fail; public class ParseIncompleteArray240Test extends CBORTestBase { private final CBORFactory F = cborFactory(); // [dataformats-binary#240] + @Test public void testIncompleteFixedSizeArray() throws Exception { final byte[] input = { (byte) 0x84 }; @@ -25,6 +28,7 @@ public void testIncompleteFixedSizeArray() throws Exception } } + @Test public void testIncompleteMarkerBasedArray() throws Exception { final byte[] input = { (byte) 0x9F }; @@ -40,6 +44,7 @@ public void testIncompleteMarkerBasedArray() throws Exception } // And might as well do the same for Objects too + @Test public void testIncompleteFixedSizeObject() throws Exception { final byte[] input = { (byte) 0xA3 }; @@ -54,6 +59,7 @@ public void testIncompleteFixedSizeObject() throws Exception } } + @Test public void testIncompleteMarkerBasedObject() throws Exception { final byte[] input = { (byte) 0xBF }; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseInvalidUTF8String236Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseInvalidUTF8String236Test.java index 74775f0d6..21432fae1 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseInvalidUTF8String236Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParseInvalidUTF8String236Test.java @@ -1,14 +1,19 @@ package com.fasterxml.jackson.dataformat.cbor.parse; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.dataformat.cbor.CBORParser; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + public class ParseInvalidUTF8String236Test extends CBORTestBase { // [dataformats-binary#236]: Original version; broken UTF-8 all around. // but gets hit by end-of-input only (since content not validated) + @Test public void testShortString236Original() throws Exception { final byte[] input = {0x66, (byte) 0xef, 0x7d, 0x7d, 0xa, 0x2d, (byte) 0xda}; @@ -25,6 +30,7 @@ public void testShortString236Original() throws Exception // Variant where the length would be valid, but the last byte is partial UTF-8 // code point and no more bytes are available due to end-of-stream + @Test public void testShortString236EndsWithPartialUTF8AtEndOfStream() throws Exception { final byte[] input = {0x63, 0x41, 0x2d, (byte) 0xda}; @@ -41,6 +47,7 @@ public void testShortString236EndsWithPartialUTF8AtEndOfStream() throws Exceptio // Variant where the length would be valid, but the last byte is partial UTF-8 // code point and the subsequent byte would be a valid continuation byte, but belongs to next data item + @Test public void testShortString236EndsWithPartialUTF8() throws Exception { final byte[] input = {0x62, 0x33, (byte) 0xdb, (byte) 0xa0}; @@ -56,6 +63,7 @@ public void testShortString236EndsWithPartialUTF8() throws Exception } // Variant where the length itself exceeds buffer + @Test public void testShortString236TruncatedString() throws Exception { // String with length of 6 bytes claimed; only 5 provided @@ -71,6 +79,7 @@ public void testShortString236TruncatedString() throws Exception } } + @Test public void testShortString237InvalidTextValue() throws Exception { // String with length of 2 bytes, but a few null bytes as fillers to @@ -102,6 +111,7 @@ public void testShortString237InvalidTextValue() throws Exception } } + @Test public void testShortString237InvalidName() throws Exception { // Object with 2-byte invalid name diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserDupHandlingTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserDupHandlingTest.java index 8d0e50a8e..ad051c9fa 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserDupHandlingTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserDupHandlingTest.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.dataformat.cbor.parse; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class ParserDupHandlingTest extends CBORTestBase { + @Test public void testSimpleDups() throws Exception { for (String json : new String[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserInteropTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserInteropTest.java index abcf0d0c0..c2346ab9c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserInteropTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserInteropTest.java @@ -1,13 +1,12 @@ package com.fasterxml.jackson.dataformat.cbor.parse; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; -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.dataformat.cbor.CBORConstants; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.core.format.*; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests geared at testing issues that were raised due to @@ -24,6 +23,7 @@ public class ParserInteropTest extends CBORTestBase // for [cbor#5]; Perl CBOR::XS module uses binary encoding for // Map/Object keys; presumably in UTF-8. + @Test public void testBinaryEncodedKeys() throws Exception { // from equivalent of '{"query":{} }' @@ -42,6 +42,7 @@ public void testBinaryEncodedKeys() throws Exception } // for [Issue#6]: should be fine to have self-desc tag in general + @Test public void testSelfDescribeTagRead() throws Exception { CBORParser p = cborParser(SELF_DESC_PLUS_TRUE); @@ -58,6 +59,7 @@ public void testSelfDescribeTagRead() throws Exception } // as per [dataformats-binary#6], self-describe great for format auto-detection + @Test public void testFormatDetection() throws Exception { CBORFactory f = cborFactory(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java index 24f8d9b32..da10a0c68 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java @@ -3,21 +3,26 @@ import java.io.*; import java.util.Random; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; -// note: copied from test of same name from jackson-dataformat-smile +import static org.junit.jupiter.api.Assertions.*; + public class ParserNextXxxTest extends CBORTestBase { + @Test public void testIsNextTokenName() throws Exception { _testIsNextTokenName1(); _testIsNextTokenName2(); } + @Test public void testNextFieldName() throws Exception { final int TESTROUNDS = 223; @@ -59,6 +64,7 @@ public void testNextFieldName() throws Exception } } + @Test public void testIssue38() throws Exception { final CBORFactory f = new CBORFactory(); @@ -75,6 +81,7 @@ public void testIssue38() throws Exception parser.close(); } + @Test public void testNextNameWithLongContent() throws Exception { final CBORFactory f = new CBORFactory(); @@ -113,6 +120,7 @@ public void testNextNameWithLongContent() throws Exception parser.close(); } + @Test public void testNextValuesMisc() throws Exception { final CBORFactory f = new CBORFactory(); @@ -143,6 +151,7 @@ public void testNextValuesMisc() throws Exception parser.close(); } + @Test public void testNextTextValue() throws Exception { final CBORFactory f = new CBORFactory(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java index 4d1ea0d04..8cac206b5 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java @@ -1,18 +1,19 @@ package com.fasterxml.jackson.dataformat.cbor.parse; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.JsonParser.NumberType; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.dataformat.cbor.CBORConstants; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -// @since 2.12 public class SimpleValuesTest extends CBORTestBase { private final CBORFactory CBOR_F = new CBORFactory(); + @Test public void testTinySimpleValues() throws Exception { // Values 0..19 are unassigned, valid to encounter @@ -28,6 +29,7 @@ public void testTinySimpleValues() throws Exception } } + @Test public void testValidByteLengthMinimalValues() throws Exception { // Values 32..255 are unassigned, valid to encounter for (int v = 32; v <= 255; ++v) { @@ -41,6 +43,7 @@ public void testValidByteLengthMinimalValues() throws Exception { } } + @Test public void testInvalidByteLengthMinimalValues() throws Exception { // Values 0..31 are invalid for variant that takes 2 bytes... for (int v = 0; v <= 31; ++v) { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java index d781b106a..6f396597e 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java @@ -2,34 +2,42 @@ 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.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; -// For [dataformats-binary#312]: null handling +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class SymbolTable312Test extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); + @Test public void testNullHandling1Quad() throws Exception { _testNullHandling(1); _testNullHandling(2); } + @Test public void testNullHandling2Quads() throws Exception { _testNullHandling(5); _testNullHandling(6); } + @Test public void testNullHandling3Quads() throws Exception { _testNullHandling(9); _testNullHandling(10); } + @Test public void testNullHandlingNQuads() throws Exception { _testNullHandling(13); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTableTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTableTest.java index dda6d754f..5f805370d 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTableTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTableTest.java @@ -3,17 +3,16 @@ import java.lang.reflect.Field; import java.util.Random; -import com.fasterxml.jackson.core.JsonFactory; -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.core.io.SerializedString; import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer; - -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper; +import static org.junit.jupiter.api.Assertions.*; + public class SymbolTableTest extends CBORTestBase { static class Point { @@ -25,6 +24,7 @@ static class Point { .build()) .build(); + @Test public void testSimpleDefault() throws Exception { final CBORMapper vanillaMapper = cborMapper(); @@ -82,6 +82,7 @@ public void testSimpleDefault() throws Exception // [dataformats-binary#253]: should be able to prevent canonicalization // Assumption: there is still non-null symbol table, but has "no canonicalization" + @Test public void testNoCanonicalizeWithMapper() throws Exception { final byte[] doc = cborDoc(a2q("{ 'x':13, 'y':-999}")); @@ -93,6 +94,7 @@ public void testNoCanonicalizeWithMapper() throws Exception } // [dataformats-binary#252]: should be able to prevent canonicalization + @Test public void testSimpleNoCanonicalize() throws Exception { final String[] fieldNames = new String[] { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/TagParsing185Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/TagParsing185Test.java index 00c9b8191..047b5f3da 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/TagParsing185Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/TagParsing185Test.java @@ -1,13 +1,17 @@ package com.fasterxml.jackson.dataformat.cbor.parse; -import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.dataformat.cbor.*; +import static org.junit.jupiter.api.Assertions.fail; + public class TagParsing185Test extends CBORTestBase { private final CBORFactory CBOR_F = new CBORFactory(); + @Test public void testRecursiveTags() throws Exception { _testRecursiveTags(20000); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java index 3e60fa67f..1bfc47c14 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java @@ -2,20 +2,22 @@ import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.dataformat.cbor.CBORConstants; -import com.fasterxml.jackson.dataformat.cbor.CBORFactory; -import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; -import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import com.fasterxml.jackson.dataformat.cbor.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -// for [dataformat-binary#93] public class UndefinedValueTest extends CBORTestBase { private final static byte BYTE_UNDEFINED = (byte) 0xF7; private final CBORFactory CBOR_F = cborFactory(); + @Test public void testUndefinedLiteralStreaming() throws Exception { JsonParser p = cborParser(CBOR_F, new byte[] { BYTE_UNDEFINED }); @@ -24,6 +26,7 @@ public void testUndefinedLiteralStreaming() throws Exception p.close(); } + @Test public void testUndefinedInArray() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -38,6 +41,7 @@ public void testUndefinedInArray() throws Exception p.close(); } + @Test public void testUndefinedInObject() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UnicodeHandlingTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UnicodeHandlingTest.java index 68ba8349a..f462cba63 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UnicodeHandlingTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UnicodeHandlingTest.java @@ -2,14 +2,20 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.dataformat.cbor.*; import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class UnicodeHandlingTest extends CBORTestBase { private final CBORFactory F = new CBORFactory(); + @Test public void testShortUnicodeWithSurrogates() throws IOException { _testLongUnicodeWithSurrogates(28, false); @@ -18,6 +24,7 @@ public void testShortUnicodeWithSurrogates() throws IOException _testLongUnicodeWithSurrogates(230, false); } + @Test public void testLongUnicodeWithSurrogates() throws IOException { _testLongUnicodeWithSurrogates(900, false); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java index 2d932105a..2414eb6e0 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java @@ -3,17 +3,21 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.exc.StreamConstraintsException; - import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.fail; + /** * Unit tests for deeply nested JSON */ public class DeepNestingCBORParserTest extends CBORTestBase { + @Test public void testDeeplyNestedObjects() throws Exception { final int depth = 1500; @@ -32,6 +36,7 @@ public void testDeeplyNestedObjects() throws Exception } } + @Test public void testDeeplyNestedObjectsWithUnconstrainedMapper() throws Exception { final int depth = 1500; @@ -47,6 +52,7 @@ public void testDeeplyNestedObjectsWithUnconstrainedMapper() throws Exception } } + @Test public void testDeeplyNestedArrays() throws Exception { final int depth = 750; @@ -65,6 +71,7 @@ public void testDeeplyNestedArrays() throws Exception } } + @Test public void testDeeplyNestedArraysWithUnconstrainedMapper() throws Exception { final int depth = 750; diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java index c67a15d63..acd00ef23 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java @@ -2,13 +2,16 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.databind.*; - import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class ReadTreesTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); @@ -23,6 +26,7 @@ static class IdValue { /********************************************************** */ + @Test public void testReadTreeSequence() throws Exception { final byte[] INPUT = concat( @@ -66,6 +70,7 @@ public void testReadTreeSequence() throws Exception /********************************************************** */ + @Test public void testReadTreeSequenceLowStringLimit() throws Exception { final byte[] INPUT = concat( diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/SequenceWriterTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/SequenceWriterTest.java index 9181bfaba..b977a87fe 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/SequenceWriterTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/SequenceWriterTest.java @@ -2,14 +2,13 @@ import java.io.ByteArrayOutputStream; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.MappingIterator; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SequenceWriter; +import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import static org.junit.jupiter.api.Assertions.*; public class SequenceWriterTest extends CBORTestBase { @@ -31,6 +30,7 @@ public IdValue(int id, int value) { /********************************************************** */ + @Test public void testSimpleSeqWrite() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixInputDecorator.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixInputDecorator.java index 09ca415bb..866fce054 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixInputDecorator.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixInputDecorator.java @@ -1,16 +1,12 @@ package com.fasterxml.jackson.dataformat.cbor.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; import com.fasterxml.jackson.core.io.InputDecorator; + @SuppressWarnings("serial") public class PrefixInputDecorator extends InputDecorator { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixOutputDecorator.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixOutputDecorator.java index fe7bb770e..ce605a63c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixOutputDecorator.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/PrefixOutputDecorator.java @@ -1,13 +1,11 @@ package com.fasterxml.jackson.dataformat.cbor.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; + @SuppressWarnings("serial") public class PrefixOutputDecorator extends OutputDecorator { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java index 571b28b5d..a0a11f786 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java @@ -22,6 +22,7 @@ * @Test * @JacksonTestFailureExpected * @Test + @Test public void testFeatureNotYetImplemented() { * // Test code that is expected to fail * } From da8851299482ab727adb93af62d8170316fff1da Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 11:31:17 +0900 Subject: [PATCH 2/5] Migrate remaining --- .../cbor/gen/GeneratorBinaryTest.java | 27 ++++++++++++------- .../cbor/gen/GeneratorSimpleTest.java | 9 +++---- .../cbor/mapper/BiggerDataTest.java | 5 ++++ .../cbor/mapper/BinaryReadTest.java | 13 +++++---- .../cbor/mapper/CBORMapperTest.java | 9 +++---- .../dataformat/cbor/mapper/TreeNodesTest.java | 3 +-- .../cbor/parse/CBORNumberParseTest.java | 10 +++---- .../parse/dos/DeepNestingCBORParserTest.java | 9 ++++--- .../dataformat/cbor/seq/ReadTreesTest.java | 4 +-- 9 files changed, 49 insertions(+), 40 deletions(-) diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java index 3332e7a93..5c8678020 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorBinaryTest.java @@ -4,32 +4,39 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import org.junit.*; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORParser; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class GeneratorBinaryTest //extends CBORTestBase { final static int SMALL_LENGTH = 100; final static int LARGE_LENGTH = /*CBORGenerator.BYTE_BUFFER_FOR_OUTPUT*/ 16000 + 500; - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; private File binaryInputFile; private File cborFile; private File binaryOutputFile; - @Before + @BeforeEach public void before() throws IOException { - binaryInputFile = tempFolder.newFile("sourceData.bin"); - cborFile = tempFolder.newFile("cbor.bin"); - binaryOutputFile = tempFolder.newFile("outputData.bin"); + binaryInputFile = new File(tempFolder, "sourceData.bin"); + binaryInputFile.createNewFile(); + + cborFile = new File(tempFolder, "cbor.bin"); + cborFile.createNewFile(); + + binaryOutputFile = new File(tempFolder, "outputData.bin"); + binaryOutputFile.createNewFile(); } @Test @@ -100,12 +107,12 @@ private void assertFileEquals(File file1, File file2) throws IOException FileInputStream fis1 = new FileInputStream(file1); FileInputStream fis2 = new FileInputStream(file2); - Assert.assertEquals(file1.length(), file2.length()); + assertEquals(file1.length(), file2.length()); int ch; while ((ch = fis1.read()) >= 0) { - Assert.assertEquals(ch, fis2.read()); + assertEquals(ch, fis2.read()); } fis1.close(); fis2.close(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java index 42d7e7c65..a3626f86e 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java @@ -6,7 +6,6 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Assert; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonGenerationException; @@ -257,7 +256,7 @@ public void testBigDecimalValues() throws Exception 0x19, 0x6a, (byte) 0xb3 // int 27315 }; assertEquals(spec.length, b.length); - Assert.assertArrayEquals(spec, b); + assertArrayEquals(spec, b); } @Test @@ -444,7 +443,7 @@ public void testCopyCurrentEventWithTag() throws Exception { // copyCurrentEvent doesn't preserve fixed arrays, so we can't // compare with the source bytes. - Assert.assertArrayEquals(new byte[] { + assertArrayEquals(new byte[] { CBORConstants.BYTE_TAG_DECIMAL_FRACTION, CBORConstants.BYTE_ARRAY_2_ELEMENTS, 0, @@ -470,7 +469,7 @@ public void testCopyCurrentStructureWithTaggedArray() throws Exception { // copyCurrentEvent doesn't preserve fixed arrays, so we can't // compare with the source bytes. - Assert.assertArrayEquals(new byte[] { + assertArrayEquals(new byte[] { CBORConstants.BYTE_TAG_DECIMAL_FRACTION, CBORConstants.BYTE_ARRAY_2_ELEMENTS, 0, @@ -495,7 +494,7 @@ public void testCopyCurrentStructureWithTaggedBinary() throws Exception { gen.close(); cborParser.close(); - Assert.assertArrayEquals( + assertArrayEquals( sourceBytes.toByteArray(), targetBytes.toByteArray()); } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java index 091cdc014..08ee5208d 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BiggerDataTest.java @@ -2,6 +2,8 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; @@ -85,6 +87,7 @@ static class Area { final ObjectMapper MAPPER = new ObjectMapper(); + @Test public void testReading() throws Exception { Citm citm0 = MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"), @@ -115,6 +118,7 @@ public void testReading() throws Exception assertEquals(1, citm.venueNames.size()); } + @Test public void testRoundTrip() throws Exception { Citm citm0 = MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"), @@ -143,6 +147,7 @@ public void testRoundTrip() throws Exception assertEquals(citm.venueNames.size(), citm2.venueNames.size()); } + @Test public void testRoundTripStringref() throws Exception { Citm citm0 = MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"), diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java index 2ffa33913..e62dfffe6 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/BinaryReadTest.java @@ -3,7 +3,6 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; -import org.junit.Assert; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @@ -72,9 +71,9 @@ public void testMultipleBinaryFields() throws Exception byte[] raw = MAPPER.writeValueAsBytes(input); Bytes3 result = MAPPER.readValue(raw, Bytes3.class); - Assert.assertArrayEquals(input.bytes1, result.bytes1); - Assert.assertArrayEquals(input.bytes2, result.bytes2); - Assert.assertArrayEquals(input.bytes3, result.bytes3); + assertArrayEquals(input.bytes1, result.bytes1); + assertArrayEquals(input.bytes2, result.bytes2); + assertArrayEquals(input.bytes3, result.bytes3); } public void _testBinary(int size) throws Exception @@ -88,14 +87,14 @@ public void _testBinary(int size) throws Exception byte[] raw = MAPPER.writeValueAsBytes(input); byte[] b2 = MAPPER.readValue(raw, byte[].class); assertNotNull(b2); - Assert.assertArrayEquals(input, b2); + assertArrayEquals(input, b2); // then as POJO member raw = MAPPER.writeValueAsBytes(new Bytes(input)); Bytes bytes = MAPPER.readValue(raw, Bytes.class); assertNotNull(bytes); assertNotNull(bytes.bytes); - Assert.assertArrayEquals(input, bytes.bytes); + assertArrayEquals(input, bytes.bytes); // then using incremental access method raw = MAPPER.writeValueAsBytes(input); @@ -107,7 +106,7 @@ public void _testBinary(int size) throws Exception assertEquals(input.length, p.readBinaryValue(bout)); assertEquals(input.length, bout.size()); b2 = bout.toByteArray(); - Assert.assertArrayEquals(input, b2); + assertArrayEquals(input, b2); assertNull(p.nextToken()); p.close(); in.close(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java index b36d1b199..4ab56b821 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/CBORMapperTest.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; -import org.junit.Assert; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,10 +36,10 @@ public void testStreamingFeaturesViaMapper() throws Exception assertEquals(29, encodedNotMinimal.length); // And then verify we can read it back, either way - Assert.assertArrayEquals(minimalValues, mapperWithMinimal.readValue(encodedMinimal, Object[].class)); - Assert.assertArrayEquals(values, mapperWithMinimal.readValue(encodedNotMinimal, Object[].class)); - Assert.assertArrayEquals(minimalValues, mapperFull.readValue(encodedMinimal, Object[].class)); - Assert.assertArrayEquals(values, mapperFull.readValue(encodedNotMinimal, Object[].class)); + assertArrayEquals(minimalValues, mapperWithMinimal.readValue(encodedMinimal, Object[].class)); + assertArrayEquals(values, mapperWithMinimal.readValue(encodedNotMinimal, Object[].class)); + assertArrayEquals(minimalValues, mapperFull.readValue(encodedMinimal, Object[].class)); + assertArrayEquals(values, mapperFull.readValue(encodedNotMinimal, Object[].class)); } // [databind#3212] diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java index 9959fe1f2..af177f758 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/TreeNodesTest.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.dataformat.cbor.mapper; -import org.junit.Assert; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.JsonNode; @@ -37,7 +36,7 @@ public void testSimple() throws Exception fail("Expected binary node; got "+datNode.getClass().getName()); } byte[] bytes = datNode.binaryValue(); - Assert.assertArrayEquals(TEXT_BYTES, bytes); + assertArrayEquals(TEXT_BYTES, bytes); } @Test diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java index 99aafeca2..59016ae1b 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/CBORNumberParseTest.java @@ -5,6 +5,8 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.JsonParser.NumberType; import com.fasterxml.jackson.core.JsonParser.NumberTypeFP; @@ -12,11 +14,9 @@ import com.fasterxml.jackson.dataformat.cbor.*; import com.fasterxml.jackson.dataformat.cbor.testutil.ThrottledInputStream; -@SuppressWarnings("resource") import static org.junit.jupiter.api.Assertions.*; -import org.junit.jupiter.api.Test; - +@SuppressWarnings("resource") public class CBORNumberParseTest extends CBORTestBase { private final CBORFactory CBOR_F = cborFactory(); @@ -400,8 +400,8 @@ public void testVeryBigDecimalType() throws IOException { parser.nextToken(); fail("expected StreamConstraintsException"); } catch (StreamConstraintsException e) { - assertTrue("unexpected exception message: " + e.getMessage(), - e.getMessage().startsWith("Number value length (4153) exceeds the maximum allowed")); + assertTrue(e.getMessage().startsWith("Number value length (4153) exceeds the maximum allowed"), + "unexpected exception message: " + e.getMessage()); } } } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java index 2414eb6e0..36f3a6b33 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/dos/DeepNestingCBORParserTest.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; /** @@ -31,8 +32,8 @@ public void testDeeplyNestedObjects() throws Exception } catch (StreamConstraintsException e) { String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", StreamReadConstraints.DEFAULT_MAX_DEPTH + 1); - assertTrue("JsonMappingException message is as expected?", - e.getMessage().startsWith(exceptionPrefix)); + assertTrue(e.getMessage().startsWith(exceptionPrefix), + "JsonMappingException message is as expected?"); } } @@ -66,8 +67,8 @@ public void testDeeplyNestedArrays() throws Exception } catch (StreamConstraintsException e) { String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", StreamReadConstraints.DEFAULT_MAX_DEPTH + 1); - assertTrue("JsonMappingException message is as expected?", - e.getMessage().startsWith(exceptionPrefix)); + assertTrue(e.getMessage().startsWith(exceptionPrefix), + "JsonMappingException message is as expected?"); } } diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java index acd00ef23..abb323431 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/seq/ReadTreesTest.java @@ -89,8 +89,8 @@ public void testReadTreeSequenceLowStringLimit() throws Exception it.nextValue(); fail("expected IllegalStateException"); } catch (StreamConstraintsException ise) { - assertTrue("unexpected exception message: " + ise.getMessage(), - ise.getMessage().startsWith("String value length (2) exceeds the maximum allowed")); + assertTrue(ise.getMessage().startsWith("String value length (2) exceeds the maximum allowed"), + "unexpected exception message: " + ise.getMessage()); } } } From b303f3cc2d4d33b7a409d118d95e8c21dbb61e27 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 11:34:50 +0900 Subject: [PATCH 3/5] Fix test error --- .../com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java index eec8a456c..cd5cfb8c2 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/CBORTestBase.java @@ -201,7 +201,7 @@ protected String getAndVerifyText(JsonParser p) throws IOException if (str.length() != actLen) { fail("Internal problem (p.token == "+p.getCurrentToken()+"): p.getText().length() ['"+str+"'] == "+str.length()+"; p.getTextLength() == "+actLen); } - assertEquals("String access via getText(), getTextXxx() must be the same", str, str2); + assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same"); return str; } From c2632136f4cb2cdc63eecfbf6926bbbaaee5942b Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 16:04:10 +0900 Subject: [PATCH 4/5] Update JacksonTestFailureExpected.java --- .../cbor/testutil/failure/JacksonTestFailureExpected.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java index a0a11f786..d439ed201 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java @@ -21,12 +21,9 @@ * * @Test * @JacksonTestFailureExpected - * @Test - @Test - public void testFeatureNotYetImplemented() { + * public void testFeatureNotYetImplemented() { * // Test code that is expected to fail * } - * } * * *

From 83dd5fc054f2280bace41f1535a31381920c18a9 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 12 Jan 2025 16:09:50 +0900 Subject: [PATCH 5/5] Put back comments --- .../jackson/dataformat/cbor/BrokenLongBinary186Test.java | 1 + .../fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java | 1 + .../jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java | 1 + .../dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java | 1 + .../jackson/dataformat/cbor/parse/ParserNextXxxTest.java | 1 + .../jackson/dataformat/cbor/parse/SimpleValuesTest.java | 1 + .../jackson/dataformat/cbor/parse/SymbolTable312Test.java | 1 + .../jackson/dataformat/cbor/parse/UndefinedValueTest.java | 1 + 8 files changed, 8 insertions(+) diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java index b496f445e..71b0d4e39 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/BrokenLongBinary186Test.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; +// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload public class BrokenLongBinary186Test extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java index 49940d3c7..c00a53852 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/FloatPrecisionTest.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; +// for [jackson-core#730] public class FloatPrecisionTest extends CBORTestBase { // for [jackson-core#730] diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java index 2c2be4062..de1b184c1 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/SharedRawGeneratorBufferTest.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; +// for [dataformats-binary#43] public class SharedRawGeneratorBufferTest extends CBORTestBase { public static class RawBean { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java index 28375bd77..62ddbda94 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/fuzz/Fuzz264_32381BigDecimalScaleTest.java @@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.*; +// [dataformats-binary#264] public class Fuzz264_32381BigDecimalScaleTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java index da10a0c68..18f894466 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNextXxxTest.java @@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.*; +// note: copied from test of same name from jackson-dataformat-smile public class ParserNextXxxTest extends CBORTestBase { @Test diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java index 8cac206b5..d72f0175c 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SimpleValuesTest.java @@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; +// @since 2.12 public class SimpleValuesTest extends CBORTestBase { private final CBORFactory CBOR_F = new CBORFactory(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java index 6f396597e..6ed4884a8 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java @@ -12,6 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; +// For [dataformats-binary#312]: null handling public class SymbolTable312Test extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java index 1bfc47c14..7ee4aaa60 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.java @@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +// for [dataformat-binary#93] public class UndefinedValueTest extends CBORTestBase { private final static byte BYTE_UNDEFINED = (byte) 0xF7;