diff --git a/src/test/java/com/fasterxml/jackson/core/JUnit5TestBase.java b/src/test/java/com/fasterxml/jackson/core/JUnit5TestBase.java index da045c1d37..ef98c3cc97 100644 --- a/src/test/java/com/fasterxml/jackson/core/JUnit5TestBase.java +++ b/src/test/java/com/fasterxml/jackson/core/JUnit5TestBase.java @@ -243,6 +243,38 @@ public static IOContext testIOContext() { return TestSupport.testIOContext(); } + protected void writeJsonDoc(JsonFactory f, String doc, JsonGenerator g) throws IOException + { + JsonParser p = f.createParser(a2q(doc)); + + while (p.nextToken() != null) { + g.copyCurrentStructure(p); + } + p.close(); + g.close(); + } + + protected String readAndWrite(JsonFactory f, JsonParser p) throws IOException + { + StringWriter sw = new StringWriter(100); + JsonGenerator g = f.createGenerator(sw); + g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); + try { + while (p.nextToken() != null) { + g.copyCurrentEvent(p); + } + } catch (IOException e) { + g.flush(); + throw new AssertionError( + "Unexpected problem during `readAndWrite`. Output so far: '" + + sw + "'; problem: " + e.getMessage(), + e); + } + p.close(); + g.close(); + return sw.toString(); + } + /* /********************************************************************** /* Assertions @@ -364,6 +396,30 @@ private static void fieldNameFor(StringBuilder sb, int index) } } + protected int[] calcQuads(String word) { + return calcQuads(utf8Bytes(word)); + } + + protected int[] calcQuads(byte[] wordBytes) { + int blen = wordBytes.length; + int[] result = new int[(blen + 3) / 4]; + for (int i = 0; i < blen; ++i) { + int x = wordBytes[i] & 0xFF; + + if (++i < blen) { + x = (x << 8) | (wordBytes[i] & 0xFF); + if (++i < blen) { + x = (x << 8) | (wordBytes[i] & 0xFF); + if (++i < blen) { + x = (x << 8) | (wordBytes[i] & 0xFF); + } + } + } + result[i >> 2] = x; + } + return result; + } + public static byte[] readResource(String ref) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/src/test/java/com/fasterxml/jackson/core/base64/Base64BinaryParsingTest.java b/src/test/java/com/fasterxml/jackson/core/base64/Base64BinaryParsingTest.java index 46ea8bd714..fae04c8a56 100644 --- a/src/test/java/com/fasterxml/jackson/core/base64/Base64BinaryParsingTest.java +++ b/src/test/java/com/fasterxml/jackson/core/base64/Base64BinaryParsingTest.java @@ -8,13 +8,13 @@ import static org.junit.jupiter.api.Assertions.*; -public class Base64BinaryParsingTest - extends JUnit5TestBase +class Base64BinaryParsingTest + extends JUnit5TestBase { private final JsonFactory JSON_F = newStreamFactory(); @Test - public void testBase64UsingInputStream() throws Exception + void base64UsingInputStream() throws Exception { _testBase64Text(MODE_INPUT_STREAM); _testBase64Text(MODE_INPUT_STREAM_THROTTLED); @@ -22,13 +22,13 @@ public void testBase64UsingInputStream() throws Exception } @Test - public void testBase64UsingReader() throws Exception + void base64UsingReader() throws Exception { _testBase64Text(MODE_READER); } @Test - public void testStreaming() throws IOException + void streaming() throws IOException { _testStreaming(MODE_INPUT_STREAM); _testStreaming(MODE_INPUT_STREAM_THROTTLED); @@ -37,7 +37,7 @@ public void testStreaming() throws IOException } @Test - public void testSimple() throws IOException + void simple() throws IOException { for (int mode : ALL_MODES) { // [core#414]: Allow leading/trailign white-space, ensure it is accepted @@ -49,7 +49,7 @@ public void testSimple() throws IOException } @Test - public void testInArray() throws IOException + void inArray() throws IOException { for (int mode : ALL_MODES) { _testInArray(mode); @@ -57,21 +57,21 @@ public void testInArray() throws IOException } @Test - public void testWithEscaped() throws IOException { + void withEscaped() throws IOException { for (int mode : ALL_MODES) { _testEscaped(mode); } } @Test - public void testWithEscapedPadding() throws IOException { + void withEscapedPadding() throws IOException { for (int mode : ALL_MODES) { _testEscapedPadding(mode); } } @Test - public void testInvalidTokenForBase64() throws IOException + void invalidTokenForBase64() throws IOException { for (int mode : ALL_MODES) { @@ -90,7 +90,7 @@ public void testInvalidTokenForBase64() throws IOException } @Test - public void testInvalidChar() throws IOException + void invalidChar() throws IOException { for (int mode : ALL_MODES) { @@ -130,7 +130,7 @@ public void testInvalidChar() throws IOException } @Test - public void testOkMissingPadding() throws IOException { + void okMissingPadding() throws IOException { final byte[] DOC1 = new byte[] { (byte) 0xAD }; _testOkMissingPadding(DOC1, MODE_INPUT_STREAM); _testOkMissingPadding(DOC1, MODE_INPUT_STREAM_THROTTLED); @@ -158,7 +158,7 @@ private void _testOkMissingPadding(byte[] input, int mode) throws IOException } @Test - public void testFailDueToMissingPadding() throws IOException { + void failDueToMissingPadding() throws IOException { final String DOC1 = q("fQ"); // 1 bytes, no padding _testFailDueToMissingPadding(DOC1, MODE_INPUT_STREAM); _testFailDueToMissingPadding(DOC1, MODE_INPUT_STREAM_THROTTLED); diff --git a/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java b/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java index 2c17d4b5eb..fba48aa987 100644 --- a/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java +++ b/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java @@ -8,11 +8,11 @@ import static org.junit.jupiter.api.Assertions.*; -public class Base64CodecTest - extends JUnit5TestBase +class Base64CodecTest + extends JUnit5TestBase { @Test - public void testVariantAccess() + void variantAccess() { for (Base64Variant var : new Base64Variant[] { Base64Variants.MIME, @@ -32,7 +32,7 @@ public void testVariantAccess() } @Test - public void testProps() + void props() { Base64Variant std = Base64Variants.MIME; // let's verify basic props of std cocec @@ -47,7 +47,7 @@ public void testProps() } @Test - public void testCharEncoding() throws Exception + void charEncoding() throws Exception { Base64Variant std = Base64Variants.MIME; assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char('?')); @@ -82,7 +82,7 @@ public void testCharEncoding() throws Exception } @Test - public void testConvenienceMethods() throws Exception + void convenienceMethods() throws Exception { final Base64Variant std = Base64Variants.MIME; @@ -105,7 +105,7 @@ public void testConvenienceMethods() throws Exception } @Test - public void testConvenienceMethodWithLFs() throws Exception + void convenienceMethodWithLFs() throws Exception { final Base64Variant std = Base64Variants.MIME; @@ -133,7 +133,7 @@ public void testConvenienceMethodWithLFs() throws Exception @SuppressWarnings("unused") @Test - public void testErrors() throws Exception + void errors() throws Exception { try { Base64Variant b = new Base64Variant("foobar", "xyz", false, '!', 24); @@ -158,7 +158,7 @@ public void testErrors() throws Exception } @Test - public void testPaddingReadBehaviour() throws Exception { + void paddingReadBehaviour() throws Exception { for (Base64Variant variant: Arrays.asList(Base64Variants.MIME, Base64Variants.MIME_NO_LINEFEEDS, Base64Variants.PEM)) { diff --git a/src/test/java/com/fasterxml/jackson/core/base64/Base64GenerationTest.java b/src/test/java/com/fasterxml/jackson/core/base64/Base64GenerationTest.java index 94de5e5d4e..fd295c1903 100644 --- a/src/test/java/com/fasterxml/jackson/core/base64/Base64GenerationTest.java +++ b/src/test/java/com/fasterxml/jackson/core/base64/Base64GenerationTest.java @@ -7,10 +7,10 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.testsupport.ThrottledInputStream; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class Base64GenerationTest - extends JUnit5TestBase +class Base64GenerationTest + extends JUnit5TestBase { /* The usual sample input string, from Thomas Hobbes's "Leviathan" * (via Wikipedia) @@ -50,7 +50,7 @@ public class Base64GenerationTest private final JsonFactory JSON_F = new JsonFactory(); @Test - public void testStreamingBinaryWrites() throws Exception + void streamingBinaryWrites() throws Exception { _testStreamingWrites(JSON_F, true); _testStreamingWrites(JSON_F, false); @@ -58,7 +58,7 @@ public void testStreamingBinaryWrites() throws Exception // For [core#55] @Test - public void testIssue55() throws Exception + void issue55() throws Exception { final JsonFactory f = new JsonFactory(); @@ -91,7 +91,7 @@ public void testIssue55() throws Exception * test things, as it does need writers to construct the data first. */ @Test - public void testSimpleBinaryWrite() throws Exception + void simpleBinaryWrite() throws Exception { _testSimpleBinaryWrite(false); _testSimpleBinaryWrite(true); @@ -99,7 +99,7 @@ public void testSimpleBinaryWrite() throws Exception // for [core#318] @Test - public void testBinaryAsEmbeddedObject() throws Exception + void binaryAsEmbeddedObject() throws Exception { JsonGenerator g; diff --git a/src/test/java/com/fasterxml/jackson/core/base64/Base64Padding912Test.java b/src/test/java/com/fasterxml/jackson/core/base64/Base64Padding912Test.java index 6613820a63..0e40c699fa 100644 --- a/src/test/java/com/fasterxml/jackson/core/base64/Base64Padding912Test.java +++ b/src/test/java/com/fasterxml/jackson/core/base64/Base64Padding912Test.java @@ -7,26 +7,26 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class Base64Padding912Test - extends JUnit5TestBase +class Base64Padding912Test + extends JUnit5TestBase { private final JsonFactory JSON_F = newStreamFactory(); @Test - public void testPaddingUsingInputStream() throws Exception + void paddingUsingInputStream() throws Exception { _testPadding(MODE_INPUT_STREAM); _testPadding(MODE_INPUT_STREAM_THROTTLED); } @Test - public void testPaddingUsingReader() throws Exception + void paddingUsingReader() throws Exception { _testPadding(MODE_READER); } @Test - public void testPaddingUsingDataInput() throws Exception + void paddingUsingDataInput() throws Exception { _testPadding(MODE_DATA_INPUT); } diff --git a/src/test/java/com/fasterxml/jackson/core/constraints/DeeplyNestedContentReadTest.java b/src/test/java/com/fasterxml/jackson/core/constraints/DeeplyNestedContentReadTest.java index 95f73663d4..d03f6fc5d0 100644 --- a/src/test/java/com/fasterxml/jackson/core/constraints/DeeplyNestedContentReadTest.java +++ b/src/test/java/com/fasterxml/jackson/core/constraints/DeeplyNestedContentReadTest.java @@ -1,22 +1,28 @@ package com.fasterxml.jackson.core.constraints; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.exc.StreamConstraintsException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * Unit test(s) for verifying handling of new (in 2.15) StreamReadConstraints * wrt maximum nesting depth. */ -public class DeeplyNestedContentReadTest - extends com.fasterxml.jackson.core.BaseTest +class DeeplyNestedContentReadTest + extends com.fasterxml.jackson.core.JUnit5TestBase { private final JsonFactory JSON_F = newStreamFactory(); private final int MAX_NESTING = StreamReadConstraints.DEFAULT_MAX_DEPTH; private final int TESTED_NESTING = MAX_NESTING + 50; - - public void testDeepNestingStreaming() throws Exception + + @Test + void deepNestingStreaming() throws Exception { final String DOC = createDeepNestedDoc(TESTED_NESTING); for (int mode : ALL_STREAMING_MODES) { @@ -37,7 +43,8 @@ private void _testDeepNesting(JsonParser p) throws Exception } } - public void testLegacyConstraintSettingTest() throws Exception + @Test + void legacyConstraintSettingTest() throws Exception { final int LOWER_MAX = 40; diff --git a/src/test/java/com/fasterxml/jackson/core/constraints/LargeDocReadTest.java b/src/test/java/com/fasterxml/jackson/core/constraints/LargeDocReadTest.java index 37decffb77..b184ee87b2 100644 --- a/src/test/java/com/fasterxml/jackson/core/constraints/LargeDocReadTest.java +++ b/src/test/java/com/fasterxml/jackson/core/constraints/LargeDocReadTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.fail; // [core#1047]: Add max-name-length constraints -public class LargeDocReadTest extends AsyncTestBase +class LargeDocReadTest extends AsyncTestBase { private final JsonFactory JSON_F_DEFAULT = newStreamFactory(); @@ -22,7 +22,7 @@ public class LargeDocReadTest extends AsyncTestBase // Test name that is below default max name @Test - public void testLargeNameBytes() throws Exception { + void largeNameBytes() throws Exception { final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); try (JsonParser p = createParserUsingStream(JSON_F_DEFAULT, doc, "UTF-8")) { consumeTokens(p); @@ -30,7 +30,7 @@ public void testLargeNameBytes() throws Exception { } @Test - public void testLargeNameChars() throws Exception { + void largeNameChars() throws Exception { final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); try (JsonParser p = createParserUsingReader(JSON_F_DEFAULT, doc)) { consumeTokens(p); @@ -38,7 +38,7 @@ public void testLargeNameChars() throws Exception { } @Test - public void testLargeNameWithSmallLimitBytes() throws Exception + void largeNameWithSmallLimitBytes() throws Exception { final String doc = generateJSON(12_000); try (JsonParser p = createParserUsingStream(JSON_F_DOC_10K, doc, "UTF-8")) { @@ -50,7 +50,7 @@ public void testLargeNameWithSmallLimitBytes() throws Exception } @Test - public void testLargeNameWithSmallLimitChars() throws Exception + void largeNameWithSmallLimitChars() throws Exception { final String doc = generateJSON(12_000); try (JsonParser p = createParserUsingReader(JSON_F_DOC_10K, doc)) { @@ -62,7 +62,7 @@ public void testLargeNameWithSmallLimitChars() throws Exception } @Test - public void testLargeNameWithSmallLimitAsync() throws Exception + void largeNameWithSmallLimitAsync() throws Exception { final byte[] doc = utf8Bytes(generateJSON(12_000)); diff --git a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNameReadTest.java b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNameReadTest.java index 0ef4cac43a..a2ac0d4610 100644 --- a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNameReadTest.java +++ b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNameReadTest.java @@ -3,12 +3,16 @@ import java.io.IOException; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser; +import static org.junit.jupiter.api.Assertions.fail; + // [core#1047]: Add max-name-length constraints -public class LargeNameReadTest extends BaseTest +class LargeNameReadTest extends JUnit5TestBase { private final JsonFactory JSON_F_DEFAULT = newStreamFactory(); @@ -23,21 +27,24 @@ public class LargeNameReadTest extends BaseTest } // Test name that is below default max name - public void testLargeNameBytes() throws Exception { + @Test + void largeNameBytes() throws Exception { final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); try (JsonParser p = createParserUsingStream(JSON_F_DEFAULT, doc, "UTF-8")) { consumeTokens(p); } } - public void testLargeNameChars() throws Exception { + @Test + void largeNameChars() throws Exception { final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); try (JsonParser p = createParserUsingReader(JSON_F_DEFAULT, doc)) { consumeTokens(p); } } - public void testLargeNameWithSmallLimitBytes() throws Exception { + @Test + void largeNameWithSmallLimitBytes() throws Exception { _testLargeNameWithSmallLimitBytes(JSON_F_NAME_100); _testLargeNameWithSmallLimitBytes(JSON_F_NAME_100_B); } @@ -53,7 +60,8 @@ private void _testLargeNameWithSmallLimitBytes(JsonFactory jf) throws Exception } } - public void testLargeNameWithSmallLimitChars() throws Exception { + @Test + void largeNameWithSmallLimitChars() throws Exception { _testLargeNameWithSmallLimitChars(JSON_F_NAME_100); _testLargeNameWithSmallLimitChars(JSON_F_NAME_100_B); } @@ -69,7 +77,8 @@ private void _testLargeNameWithSmallLimitChars(JsonFactory jf) throws Exception } } - public void testLargeNameWithSmallLimitAsync() throws Exception + @Test + void largeNameWithSmallLimitAsync() throws Exception { final byte[] doc = utf8Bytes(generateJSON(1000)); diff --git a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberReadTest.java b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberReadTest.java index 24eb8ba8e4..458f8ab3b6 100644 --- a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberReadTest.java +++ b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberReadTest.java @@ -3,16 +3,21 @@ import java.math.BigDecimal; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.exc.StreamConstraintsException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * Set of basic unit tests for verifying that "too big" number constraints * are caught by various JSON parser backends. */ @SuppressWarnings("resource") -public class LargeNumberReadTest - extends com.fasterxml.jackson.core.BaseTest +class LargeNumberReadTest + extends com.fasterxml.jackson.core.JUnit5TestBase { private final JsonFactory JSON_F = newStreamFactory(); @@ -22,13 +27,15 @@ public class LargeNumberReadTest /********************************************************************** */ - public void testBigBigDecimalsBytesFailByDefault() throws Exception + @Test + void bigBigDecimalsBytesFailByDefault() throws Exception { _testBigBigDecimals(MODE_INPUT_STREAM, true); _testBigBigDecimals(MODE_INPUT_STREAM_THROTTLED, true); } - public void testBigBigDecimalsBytes() throws Exception + @Test + void bigBigDecimalsBytes() throws Exception { try { _testBigBigDecimals(MODE_INPUT_STREAM, false); @@ -44,7 +51,8 @@ public void testBigBigDecimalsBytes() throws Exception } } - public void testBigBigDecimalsCharsFailByDefault() throws Exception + @Test + void bigBigDecimalsCharsFailByDefault() throws Exception { try { _testBigBigDecimals(MODE_READER, false); @@ -54,12 +62,14 @@ public void testBigBigDecimalsCharsFailByDefault() throws Exception } } - public void testBigBigDecimalsChars() throws Exception + @Test + void bigBigDecimalsChars() throws Exception { _testBigBigDecimals(MODE_READER, true); } - public void testBigBigDecimalsDataInputFailByDefault() throws Exception + @Test + void bigBigDecimalsDataInputFailByDefault() throws Exception { try { _testBigBigDecimals(MODE_DATA_INPUT, false); @@ -69,7 +79,8 @@ public void testBigBigDecimalsDataInputFailByDefault() throws Exception } } - public void testBigBigDecimalsDataInput() throws Exception + @Test + void bigBigDecimalsDataInput() throws Exception { _testBigBigDecimals(MODE_DATA_INPUT, true); } diff --git a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberWriteTest.java b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberWriteTest.java index dfaf5f3769..fa4414bea8 100644 --- a/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberWriteTest.java +++ b/src/test/java/com/fasterxml/jackson/core/constraints/LargeNumberWriteTest.java @@ -10,12 +10,12 @@ import java.math.BigDecimal; import java.math.BigInteger; -import com.fasterxml.jackson.core.BaseTest; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.StreamReadConstraints; +import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Tests verifying that there are no limits for writing very long numbers @@ -24,7 +24,7 @@ * * @since 2.15 */ -public class LargeNumberWriteTest extends BaseTest +class LargeNumberWriteTest extends JUnit5TestBase { private final JsonFactory VANILLA_JSON_F = new JsonFactory(); @@ -50,7 +50,8 @@ public class LargeNumberWriteTest extends BaseTest BIG_INT = new BigInteger(sb.toString()); } - public void testWriteLargeIntegerByteArray() throws Exception + @Test + void writeLargeIntegerByteArray() throws Exception { try( ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -63,7 +64,8 @@ public void testWriteLargeIntegerByteArray() throws Exception } } - public void testWriteLargeIntegerStringWriter() throws Exception + @Test + void writeLargeIntegerStringWriter() throws Exception { try( StringWriter out = new StringWriter(); @@ -76,7 +78,8 @@ public void testWriteLargeIntegerStringWriter() throws Exception } } - public void testWriteLargeIntegerDataOutput() throws Exception + @Test + void writeLargeIntegerDataOutput() throws Exception { try( ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -95,7 +98,8 @@ public void testWriteLargeIntegerDataOutput() throws Exception } } - public void testWriteLargeDecimalByteArray() throws Exception + @Test + void writeLargeDecimalByteArray() throws Exception { try( ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -108,7 +112,8 @@ public void testWriteLargeDecimalByteArray() throws Exception } } - public void testWriteLargeDecimalStringWriter() throws Exception + @Test + void writeLargeDecimalStringWriter() throws Exception { try( StringWriter out = new StringWriter(); @@ -121,7 +126,8 @@ public void testWriteLargeDecimalStringWriter() throws Exception } } - public void testWriteLargeDecimalDataOutput() throws Exception + @Test + void writeLargeDecimalDataOutput() throws Exception { try( ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/src/test/java/com/fasterxml/jackson/core/filter/BasicGeneratorFilteringTest.java b/src/test/java/com/fasterxml/jackson/core/filter/BasicGeneratorFilteringTest.java index cc83bae739..6549c80159 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/BasicGeneratorFilteringTest.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/BasicGeneratorFilteringTest.java @@ -6,15 +6,19 @@ import java.util.*; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; import com.fasterxml.jackson.core.io.SerializedString; +import static org.junit.jupiter.api.Assertions.*; + /** * Low-level tests for explicit, hand-written tests for generator-side * filtering. */ @SuppressWarnings("resource") -public class BasicGeneratorFilteringTest extends BaseTest +class BasicGeneratorFilteringTest extends JUnit5TestBase { static final TokenFilter INCLUDE_ALL_SCALARS = new TokenFilter(); @@ -171,7 +175,8 @@ public boolean _includeScalar() { private final JsonFactory JSON_F = new JsonFactory(); - public void testNonFiltering() throws Exception + @Test + void nonFiltering() throws Exception { // First, verify non-filtering StringWriter w = new StringWriter(); @@ -183,7 +188,8 @@ public void testNonFiltering() throws Exception w.toString()); } - public void testSingleMatchFilteringWithoutPath() throws Exception + @Test + void singleMatchFilteringWithoutPath() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -202,7 +208,8 @@ public void testSingleMatchFilteringWithoutPath() throws Exception assertEquals("3", w.toString()); } - public void testSingleMatchFilteringWithPath() throws Exception + @Test + void singleMatchFilteringWithPath() throws Exception { StringWriter w = new StringWriter(); JsonGenerator origGen = _createGenerator(w); @@ -224,7 +231,8 @@ public void testSingleMatchFilteringWithPath() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testSingleMatchFilteringWithPathSkippedArray() throws Exception + @Test + void singleMatchFilteringWithPathSkippedArray() throws Exception { StringWriter w = new StringWriter(); JsonGenerator origGen = _createGenerator(w); @@ -247,7 +255,8 @@ public void testSingleMatchFilteringWithPathSkippedArray() throws Exception } // Alternative take, using slightly different calls for FIELD_NAME, START_ARRAY - public void testSingleMatchFilteringWithPathAlternate1() throws Exception { + @Test + void singleMatchFilteringWithPathAlternate1() throws Exception { _testSingleMatchFilteringWithPathAlternate1(false); _testSingleMatchFilteringWithPathAlternate1(true); } @@ -302,7 +311,8 @@ private void _testSingleMatchFilteringWithPathAlternate1(boolean exclude) throws } } - public void testSingleMatchFilteringWithPathRawBinary() throws Exception + @Test + void singleMatchFilteringWithPathRawBinary() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -353,7 +363,8 @@ public void testSingleMatchFilteringWithPathRawBinary() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testMultipleMatchFilteringWithPath1() throws Exception + @Test + void multipleMatchFilteringWithPath1() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -380,7 +391,8 @@ public void testMultipleMatchFilteringWithPath1() throws Exception assertEquals(a2q("{'a':123,'b':true}"), w.toString()); } - public void testMultipleMatchFilteringWithPath2() throws Exception + @Test + void multipleMatchFilteringWithPath2() throws Exception { StringWriter w = new StringWriter(); @@ -393,7 +405,8 @@ public void testMultipleMatchFilteringWithPath2() throws Exception assertEquals(3, gen.getMatchCount()); } - public void testMultipleMatchFilteringWithPath3() throws Exception + @Test + void multipleMatchFilteringWithPath3() throws Exception { StringWriter w = new StringWriter(); @@ -406,7 +419,8 @@ public void testMultipleMatchFilteringWithPath3() throws Exception assertEquals(2, gen.getMatchCount()); } - public void testNoMatchFiltering1() throws Exception + @Test + void noMatchFiltering1() throws Exception { StringWriter w = new StringWriter(); @@ -419,7 +433,8 @@ public void testNoMatchFiltering1() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testNoMatchFiltering2() throws Exception + @Test + void noMatchFiltering2() throws Exception { StringWriter w = new StringWriter(); @@ -433,7 +448,8 @@ public void testNoMatchFiltering2() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testNoMatchFiltering3() throws Exception + @Test + void noMatchFiltering3() throws Exception { StringWriter w = new StringWriter(); @@ -447,7 +463,8 @@ public void testNoMatchFiltering3() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testNoMatchFiltering4() throws Exception + @Test + void noMatchFiltering4() throws Exception { StringWriter w = new StringWriter(); @@ -460,7 +477,8 @@ public void testNoMatchFiltering4() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testNoMatchFiltering5() throws Exception + @Test + void noMatchFiltering5() throws Exception { StringWriter w = new StringWriter(); @@ -474,7 +492,8 @@ public void testNoMatchFiltering5() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testNoMatchFiltering6() throws Exception + @Test + void noMatchFiltering6() throws Exception { StringWriter w = new StringWriter(); @@ -488,7 +507,8 @@ public void testNoMatchFiltering6() throws Exception assertEquals(0, gen.getMatchCount()); } - public void testValueOmitsFieldName1() throws Exception + @Test + void valueOmitsFieldName1() throws Exception { StringWriter w = new StringWriter(); @@ -501,7 +521,8 @@ public void testValueOmitsFieldName1() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testMultipleMatchFilteringWithPath4() throws Exception + @Test + void multipleMatchFilteringWithPath4() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -513,7 +534,8 @@ public void testMultipleMatchFilteringWithPath4() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testValueOmitsFieldName2() throws Exception + @Test + void valueOmitsFieldName2() throws Exception { StringWriter w = new StringWriter(); @@ -526,7 +548,8 @@ public void testValueOmitsFieldName2() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testIndexMatchWithPath1() throws Exception + @Test + void indexMatchWithPath1() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -545,7 +568,8 @@ public void testIndexMatchWithPath1() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testIndexMatchWithPath2() throws Exception + @Test + void indexMatchWithPath2() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -585,7 +609,8 @@ public void testIndexMatchWithPath2() throws Exception assertEquals(1, gen.getMatchCount()); } - public void testWriteStartObjectWithObject() throws Exception + @Test + void writeStartObjectWithObject() throws Exception { StringWriter w = new StringWriter(); @@ -611,7 +636,8 @@ public void testWriteStartObjectWithObject() throws Exception } // [core#580] - public void testRawValueDelegationWithArray() throws Exception + @Test + void rawValueDelegationWithArray() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -631,7 +657,8 @@ public void testRawValueDelegationWithArray() throws Exception } // [core#588] - public void testRawValueDelegationWithObject() throws Exception + @Test + void rawValueDelegationWithObject() throws Exception { StringWriter w = new StringWriter(); FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(_createGenerator(w), @@ -648,7 +675,8 @@ public void testRawValueDelegationWithObject() throws Exception assertEquals(a2q("{'f1':1,'f2':12.3,'f3':3}"), w.toString()); } - public void testIncludeEmptyArrayIfNotFiltered() throws Exception + @Test + void includeEmptyArrayIfNotFiltered() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -669,7 +697,8 @@ public void testIncludeEmptyArrayIfNotFiltered() throws Exception assertEquals(a2q("{'empty_array':[]}"), w.toString()); } - public void testIncludeEmptyArray() throws Exception + @Test + void includeEmptyArray() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -690,7 +719,8 @@ public void testIncludeEmptyArray() throws Exception assertEquals(a2q("{'empty_array':[],'filtered_array':[]}"), w.toString()); } - public void testIncludeEmptyObjectIfNotFiltered() throws Exception + @Test + void includeEmptyObjectIfNotFiltered() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -713,7 +743,8 @@ public void testIncludeEmptyObjectIfNotFiltered() throws Exception assertEquals(a2q("{'empty_object':{}}"), w.toString()); } - public void testIncludeEmptyObject() throws Exception + @Test + void includeEmptyObject() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -734,7 +765,8 @@ public void testIncludeEmptyObject() throws Exception assertEquals(a2q("{'empty_object':{},'filtered_object':{}}"), w.toString()); } - public void testIncludeEmptyArrayInObjectIfNotFiltered() throws Exception + @Test + void includeEmptyArrayInObjectIfNotFiltered() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -759,7 +791,8 @@ public void testIncludeEmptyArrayInObjectIfNotFiltered() throws Exception assertEquals(a2q("{'object_with_empty_array':{'foo':[]}}"), w.toString()); } - public void testIncludeEmptyArrayInObject() throws Exception + @Test + void includeEmptyArrayInObject() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -785,7 +818,8 @@ public void testIncludeEmptyArrayInObject() throws Exception } - public void testIncludeEmptyObjectInArrayIfNotFiltered() throws Exception + @Test + void includeEmptyObjectInArrayIfNotFiltered() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -810,7 +844,8 @@ public void testIncludeEmptyObjectInArrayIfNotFiltered() throws Exception assertEquals(a2q("{'array_with_empty_object':[{}]}"), w.toString()); } - public void testIncludeEmptyObjectInArray() throws Exception + @Test + void includeEmptyObjectInArray() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -838,7 +873,8 @@ public void testIncludeEmptyObjectInArray() throws Exception } - public void testIncludeEmptyTopLevelObject() throws Exception + @Test + void includeEmptyTopLevelObject() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( @@ -854,7 +890,8 @@ public void testIncludeEmptyTopLevelObject() throws Exception assertEquals(a2q("{}"), w.toString()); } - public void testIncludeEmptyTopLevelArray() throws Exception + @Test + void includeEmptyTopLevelArray() throws Exception { StringWriter w = new StringWriter(); JsonGenerator gen = new FilteringGeneratorDelegate( diff --git a/src/test/java/com/fasterxml/jackson/core/filter/BasicParserFilteringTest.java b/src/test/java/com/fasterxml/jackson/core/filter/BasicParserFilteringTest.java index 7490ff8117..32c20c9c36 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/BasicParserFilteringTest.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/BasicParserFilteringTest.java @@ -4,10 +4,14 @@ import java.util.*; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; +import static org.junit.jupiter.api.Assertions.*; + @SuppressWarnings("resource") -public class BasicParserFilteringTest extends BaseTest +class BasicParserFilteringTest extends JUnit5TestBase { static class NameMatchFilter extends TokenFilter { @@ -207,14 +211,16 @@ public boolean _includeScalar() { private final String SIMPLE = a2q( "{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':0.25},'b':true}"); - public void testNonFiltering() throws Exception + @Test + void nonFiltering() throws Exception { JsonParser p = JSON_F.createParser(SIMPLE); String result = readAndWrite(JSON_F, p); assertEquals(SIMPLE, result); } - public void testSingleMatchFilteringWithoutPath() throws Exception + @Test + void singleMatchFilteringWithoutPath() throws Exception { JsonParser p0 = JSON_F.createParser(SIMPLE); FilteringParserDelegate p = new FilteringParserDelegate(p0, @@ -227,7 +233,8 @@ public void testSingleMatchFilteringWithoutPath() throws Exception assertEquals(1, p.getMatchCount()); } - public void testSingleMatchFilteringWithPath1() throws Exception + @Test + void singleMatchFilteringWithPath1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -241,7 +248,8 @@ public void testSingleMatchFilteringWithPath1() throws Exception assertEquals(1, p.getMatchCount()); } - public void testSingleMatchFilteringWithPath2() throws Exception + @Test + void singleMatchFilteringWithPath2() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -255,7 +263,8 @@ public void testSingleMatchFilteringWithPath2() throws Exception assertEquals(1, p.getMatchCount()); } - public void testSingleMatchFilteringWithPath3() throws Exception + @Test + void singleMatchFilteringWithPath3() throws Exception { String jsonString = a2q("{'a':123,'ob':{'value0':2,'value':3,'value2':4},'array':[1,2],'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -269,7 +278,8 @@ public void testSingleMatchFilteringWithPath3() throws Exception assertEquals(1, p.getMatchCount()); } - public void testNotAllowMultipleMatchesWithoutPath1() throws Exception + @Test + void notAllowMultipleMatchesWithoutPath1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -283,7 +293,8 @@ public void testNotAllowMultipleMatchesWithoutPath1() throws Exception assertEquals(1, p.getMatchCount()); } - public void testNotAllowMultipleMatchesWithoutPath2() throws Exception + @Test + void notAllowMultipleMatchesWithoutPath2() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'array':[3,4],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -297,7 +308,8 @@ public void testNotAllowMultipleMatchesWithoutPath2() throws Exception assertEquals(1, p.getMatchCount()); } - public void testNotAllowMultipleMatchesWithPath1() throws Exception + @Test + void notAllowMultipleMatchesWithPath1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'array':[3,4],'ob':{'value':3,'array':[5,6],'value':{'value0':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -312,7 +324,8 @@ public void testNotAllowMultipleMatchesWithPath1() throws Exception } - public void testNotAllowMultipleMatchesWithPath2() throws Exception + @Test + void notAllowMultipleMatchesWithPath2() throws Exception { String jsonString = a2q("{'a':123,'ob':{'value':3,'array':[1,2],'value':{'value0':2}},'array':[3,4]}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -326,7 +339,8 @@ public void testNotAllowMultipleMatchesWithPath2() throws Exception assertEquals(1, p.getMatchCount()); } - public void testNotAllowMultipleMatchesWithPath3() throws Exception + @Test + void notAllowMultipleMatchesWithPath3() throws Exception { String jsonString = a2q("{'ob':{'value':3,'ob':{'value':2}},'value':\"val\"}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -340,7 +354,8 @@ public void testNotAllowMultipleMatchesWithPath3() throws Exception assertEquals(1, p.getMatchCount()); } - public void testNotAllowMultipleMatchesWithPath4() throws Exception + @Test + void notAllowMultipleMatchesWithPath4() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value1':1},'ob2':{'ob':{'value2':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -354,7 +369,8 @@ public void testNotAllowMultipleMatchesWithPath4() throws Exception assertEquals(1, p.getMatchCount()); } - public void testAllowMultipleMatchesWithoutPath() throws Exception + @Test + void allowMultipleMatchesWithoutPath() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -368,7 +384,8 @@ public void testAllowMultipleMatchesWithoutPath() throws Exception assertEquals(3, p.getMatchCount()); } - public void testAllowMultipleMatchesWithPath1() throws Exception + @Test + void allowMultipleMatchesWithPath1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -382,7 +399,8 @@ public void testAllowMultipleMatchesWithPath1() throws Exception assertEquals(3, p.getMatchCount()); } - public void testAllowMultipleMatchesWithPath2() throws Exception + @Test + void allowMultipleMatchesWithPath2() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'array':[3,4],'value':{'value0':2}},'value':\"val\",'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -396,7 +414,8 @@ public void testAllowMultipleMatchesWithPath2() throws Exception assertEquals(2, p.getMatchCount()); } - public void testMultipleMatchFilteringWithPath1() throws Exception + @Test + void multipleMatchFilteringWithPath1() throws Exception { JsonParser p0 = JSON_F.createParser(SIMPLE); FilteringParserDelegate p = new FilteringParserDelegate(p0, @@ -408,7 +427,8 @@ public void testMultipleMatchFilteringWithPath1() throws Exception } - public void testMultipleMatchFilteringWithPath2() throws Exception + @Test + void multipleMatchFilteringWithPath2() throws Exception { String INPUT = a2q("{'a':123,'ob':{'value0':2,'value':3,'value2':4},'b':true}"); JsonParser p0 = JSON_F.createParser(INPUT); @@ -421,7 +441,8 @@ public void testMultipleMatchFilteringWithPath2() throws Exception assertEquals(2, p.getMatchCount()); } - public void testMultipleMatchFilteringWithPath3() throws Exception + @Test + void multipleMatchFilteringWithPath3() throws Exception { final String JSON = a2q("{'root':{'a0':true,'a':{'value':3},'b':{'value':\"foo\"}},'b0':false}"); JsonParser p0 = JSON_F.createParser(JSON); @@ -433,7 +454,8 @@ public void testMultipleMatchFilteringWithPath3() throws Exception assertEquals(2, p.getMatchCount()); } - public void testNoMatchFiltering1() throws Exception + @Test + void noMatchFiltering1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -447,7 +469,8 @@ public void testNoMatchFiltering1() throws Exception assertEquals(0, p.getMatchCount()); } - public void testNoMatchFiltering2() throws Exception + @Test + void noMatchFiltering2() throws Exception { String object = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); String jsonString = String.format("[%s,%s,%s]", object, object, object); @@ -462,7 +485,8 @@ public void testNoMatchFiltering2() throws Exception assertEquals(0, p.getMatchCount()); } - public void testNoMatchFiltering3() throws Exception + @Test + void noMatchFiltering3() throws Exception { String object = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); String jsonString = String.format("[[%s],[%s],[%s]]", object, object, object); @@ -477,7 +501,8 @@ public void testNoMatchFiltering3() throws Exception assertEquals(0, p.getMatchCount()); } - public void testNoMatchFiltering4() throws Exception + @Test + void noMatchFiltering4() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -491,7 +516,8 @@ public void testNoMatchFiltering4() throws Exception assertEquals(0, p.getMatchCount()); } - public void testNoMatchFiltering5() throws Exception + @Test + void noMatchFiltering5() throws Exception { String object = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); String jsonString = String.format("[%s,%s,%s]", object, object, object); @@ -506,7 +532,8 @@ public void testNoMatchFiltering5() throws Exception assertEquals(0, p.getMatchCount()); } - public void testNoMatchFiltering6() throws Exception + @Test + void noMatchFiltering6() throws Exception { String object = a2q("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}"); String jsonString = String.format("[[%s],[%s],[%s]]", object, object, object); @@ -521,7 +548,8 @@ public void testNoMatchFiltering6() throws Exception assertEquals(0, p.getMatchCount()); } - public void testValueOmitsFieldName1() throws Exception + @Test + void valueOmitsFieldName1() throws Exception { String jsonString = a2q("{'a':123,'array':[1,2]}"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -535,7 +563,8 @@ public void testValueOmitsFieldName1() throws Exception assertEquals(1, p.getMatchCount()); } - public void testValueOmitsFieldName2() throws Exception + @Test + void valueOmitsFieldName2() throws Exception { String jsonString = a2q("['a',{'value0':3,'b':{'value':4}},123]"); JsonParser p0 = JSON_F.createParser(jsonString); @@ -549,7 +578,8 @@ public void testValueOmitsFieldName2() throws Exception assertEquals(2, p.getMatchCount()); } - public void testIndexMatchWithPath1() throws Exception + @Test + void indexMatchWithPath1() throws Exception { FilteringParserDelegate p = new FilteringParserDelegate(JSON_F.createParser(SIMPLE), new IndexMatchFilter(1), Inclusion.INCLUDE_ALL_AND_PATH, true); @@ -564,7 +594,8 @@ public void testIndexMatchWithPath1() throws Exception assertEquals(1, p.getMatchCount()); } - public void testIndexMatchWithPath2() throws Exception + @Test + void indexMatchWithPath2() throws Exception { FilteringParserDelegate p = new FilteringParserDelegate(JSON_F.createParser(SIMPLE), new IndexMatchFilter(0, 1), Inclusion.INCLUDE_ALL_AND_PATH, true); @@ -578,7 +609,8 @@ public void testIndexMatchWithPath2() throws Exception assertEquals(3, p.getMatchCount()); } - public void testBasicSingleMatchFilteringWithPath() throws Exception + @Test + void basicSingleMatchFilteringWithPath() throws Exception { JsonParser p0 = JSON_F.createParser(SIMPLE); JsonParser p = new FilteringParserDelegate(p0, @@ -592,7 +624,8 @@ public void testBasicSingleMatchFilteringWithPath() throws Exception assertEquals(a2q("{'ob':{'value':3}}"), result); } - public void testTokensSingleMatchWithPath() throws Exception + @Test + void tokensSingleMatchWithPath() throws Exception { JsonParser p0 = JSON_F.createParser(SIMPLE); JsonParser p = new FilteringParserDelegate(p0, @@ -669,7 +702,8 @@ public void testTokensSingleMatchWithPath() throws Exception p.close(); } - public void testSkippingForSingleWithPath() throws Exception + @Test + void skippingForSingleWithPath() throws Exception { JsonParser p0 = JSON_F.createParser(SIMPLE); JsonParser p = new FilteringParserDelegate(p0, @@ -684,7 +718,8 @@ public void testSkippingForSingleWithPath() throws Exception assertNull(p.nextToken()); } - public void testIncludeEmptyArrayIfNotFiltered() throws Exception { + @Test + void includeEmptyArrayIfNotFiltered() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'empty_array':[],'filtered_array':[5]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -695,7 +730,8 @@ public void testIncludeEmptyArrayIfNotFiltered() throws Exception { assertEquals(a2q("{'empty_array':[]}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyArray() throws Exception { + @Test + void includeEmptyArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'empty_array':[],'filtered_array':[5]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -706,7 +742,8 @@ public void testIncludeEmptyArray() throws Exception { assertEquals(a2q("{'empty_array':[],'filtered_array':[]}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyObjectIfNotFiltered() throws Exception { + @Test + void includeEmptyObjectIfNotFiltered() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'empty_object':{},'filtered_object':{'foo':5}}")); JsonParser p = new FilteringParserDelegate(p0, @@ -717,7 +754,8 @@ public void testIncludeEmptyObjectIfNotFiltered() throws Exception { assertEquals(a2q("{'empty_object':{}}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyObject() throws Exception { + @Test + void includeEmptyObject() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'empty_object':{},'filtered_object':{'foo':5}}")); JsonParser p = new FilteringParserDelegate(p0, @@ -728,7 +766,8 @@ public void testIncludeEmptyObject() throws Exception { assertEquals(a2q("{'empty_object':{},'filtered_object':{}}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyArrayInObjectIfNotFiltered() throws Exception { + @Test + void includeEmptyArrayInObjectIfNotFiltered() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'object_with_empty_array':{'foo':[]},'object_with_filtered_array':{'foo':[5]}}")); JsonParser p = new FilteringParserDelegate(p0, @@ -739,7 +778,8 @@ public void testIncludeEmptyArrayInObjectIfNotFiltered() throws Exception { assertEquals(a2q("{'object_with_empty_array':{'foo':[]}}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyArrayInObject() throws Exception { + @Test + void includeEmptyArrayInObject() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'object_with_empty_array':{'foo':[]},'object_with_filtered_array':{'foo':[5]}}")); JsonParser p = new FilteringParserDelegate(p0, @@ -752,7 +792,8 @@ public void testIncludeEmptyArrayInObject() throws Exception { readAndWrite(JSON_F, p)); } - public void testIncludeEmptyObjectInArrayIfNotFiltered() throws Exception { + @Test + void includeEmptyObjectInArrayIfNotFiltered() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'array_with_empty_object':[{}],'array_with_filtered_object':[{'foo':5}]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -763,7 +804,8 @@ public void testIncludeEmptyObjectInArrayIfNotFiltered() throws Exception { assertEquals(a2q("{'array_with_empty_object':[{}]}"), readAndWrite(JSON_F, p)); } - public void testIncludeEmptyObjectInArray() throws Exception { + @Test + void includeEmptyObjectInArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'array_with_empty_object':[{}],'array_with_filtered_object':[{'foo':5}]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -776,7 +818,8 @@ public void testIncludeEmptyObjectInArray() throws Exception { readAndWrite(JSON_F, p)); } - public void testIncludeEmptyArrayIfNotFilteredAfterFiltered() throws Exception { + @Test + void includeEmptyArrayIfNotFilteredAfterFiltered() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "[5, {'empty_array':[],'filtered_array':[5]}]")); JsonParser p = new FilteringParserDelegate(p0, @@ -787,7 +830,8 @@ public void testIncludeEmptyArrayIfNotFilteredAfterFiltered() throws Exception { assertEquals(a2q("[{'empty_array':[]}]"), readAndWrite(JSON_F, p)); } - public void testExcludeObjectAtTheBeginningOfArray() throws Exception { + @Test + void excludeObjectAtTheBeginningOfArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'parent':[{'exclude':false},{'include':true}]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -798,7 +842,8 @@ public void testExcludeObjectAtTheBeginningOfArray() throws Exception { assertEquals(a2q("{'parent':[{'include':true}]}"), readAndWrite(JSON_F, p)); } - public void testExcludeObjectAtTheEndOfArray() throws Exception { + @Test + void excludeObjectAtTheEndOfArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'parent':[{'include':true},{'exclude':false}]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -809,7 +854,8 @@ public void testExcludeObjectAtTheEndOfArray() throws Exception { assertEquals(a2q("{'parent':[{'include':true}]}"), readAndWrite(JSON_F, p)); } - public void testExcludeObjectInMiddleOfArray() throws Exception { + @Test + void excludeObjectInMiddleOfArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "{'parent':[{'include-1':1},{'skip':0},{'include-2':2}]}")); JsonParser p = new FilteringParserDelegate(p0, @@ -820,7 +866,8 @@ public void testExcludeObjectInMiddleOfArray() throws Exception { assertEquals(a2q("{'parent':[{'include-1':1},{'include-2':2}]}"), readAndWrite(JSON_F, p)); } - public void testExcludeLastArrayInsideArray() throws Exception { + @Test + void excludeLastArrayInsideArray() throws Exception { JsonParser p0 = JSON_F.createParser(a2q( "['skipped', [], ['skipped']]")); JsonParser p = new FilteringParserDelegate(p0, @@ -831,7 +878,8 @@ public void testExcludeLastArrayInsideArray() throws Exception { assertEquals(a2q("[[]]"), readAndWrite(JSON_F, p)); } - public void testCallbacksFromFilteringParserDelegate1() throws Exception { + @Test + void callbacksFromFilteringParserDelegate1() throws Exception { LoggingFilter loggingFilter = new LoggingFilter(new JsonPointerBasedFilter("/parent")); JsonParser p0 = JSON_F.createParser(a2q( diff --git a/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering609Test.java b/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering609Test.java index 52373253a4..2b60fd04ca 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering609Test.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering609Test.java @@ -3,12 +3,16 @@ import java.io.*; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; import com.fasterxml.jackson.core.util.JsonGeneratorDelegate; +import static org.junit.jupiter.api.Assertions.assertEquals; + // for [core#609] -public class GeneratorFiltering609Test - extends com.fasterxml.jackson.core.BaseTest +class GeneratorFiltering609Test + extends com.fasterxml.jackson.core.JUnit5TestBase { static class NullExcludingTokenFilter extends TokenFilter { static final NullExcludingTokenFilter INSTANCE = @@ -58,7 +62,8 @@ public void writeFieldName(String name) throws IOException { } // for [core#609]: will pass in 2.10 for some cases - public void testIssue609() throws Exception + @Test + void issue609() throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JsonGenerator g = createGenerator(outputStream); diff --git a/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering890Test.java b/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering890Test.java index 579bdabfd2..a9bd5c6773 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering890Test.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/GeneratorFiltering890Test.java @@ -1,9 +1,10 @@ package com.fasterxml.jackson.core.filter; -import com.fasterxml.jackson.core.BaseTest; +import com.fasterxml.jackson.core.JUnit5TestBase; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonPointer; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -14,9 +15,11 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.junit.jupiter.api.Assertions.assertEquals; + // for [core#890] -public class GeneratorFiltering890Test - extends BaseTest +class GeneratorFiltering890Test + extends JUnit5TestBase { private static final class OrTokenFilter extends TokenFilter { @@ -70,7 +73,8 @@ private TokenFilter executeDelegates(final UnaryOperator operator) } } - public void testIssue890_singleProperty() throws Exception + @Test + void issue890SingleProperty() throws Exception { // GIVEN final Set jsonPointers = Stream.of("/0/id").collect(Collectors.toSet()); @@ -92,7 +96,8 @@ public void testIssue890_singleProperty() throws Exception assertEquals("[{\"id\":1}]", json); } - public void testIssue890_twoProperties() throws Exception + @Test + void issue890TwoProperties() throws Exception { // GIVEN final Set jsonPointers = Stream.of("/0/id", "/0/stuff/0/name").collect(Collectors.toSet()); @@ -114,7 +119,8 @@ public void testIssue890_twoProperties() throws Exception assertEquals("[{\"id\":1,\"stuff\":[{\"name\":\"first\"}]}]", json); } - public void testIssue890_fullArray() throws Exception + @Test + void issue890FullArray() throws Exception { // GIVEN final Set jsonPointers = Stream.of("//id", "//stuff//name").collect(Collectors.toSet()); diff --git a/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerGeneratorFilteringTest.java b/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerGeneratorFilteringTest.java index e52ee35969..896f0e3b8f 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerGeneratorFilteringTest.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerGeneratorFilteringTest.java @@ -3,16 +3,21 @@ import java.io.*; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; +import static org.junit.jupiter.api.Assertions.assertEquals; + @SuppressWarnings("resource") -public class JsonPointerGeneratorFilteringTest extends com.fasterxml.jackson.core.BaseTest +class JsonPointerGeneratorFilteringTest extends com.fasterxml.jackson.core.JUnit5TestBase { private final JsonFactory JSON_F = new JsonFactory(); final String SIMPLE_INPUT = a2q("{'a':1,'b':[1,2,3],'c':{'d':{'a':true}},'d':null}"); - public void testSimplePropertyWithPath() throws Exception + @Test + void simplePropertyWithPath() throws Exception { _assert(SIMPLE_INPUT, "/c", Inclusion.INCLUDE_ALL_AND_PATH, "{'c':{'d':{'a':true}}}", false); _assert(SIMPLE_INPUT, "/c/d", Inclusion.INCLUDE_ALL_AND_PATH, "{'c':{'d':{'a':true}}}", false); @@ -27,7 +32,8 @@ public void testSimplePropertyWithPath() throws Exception _assert(SIMPLE_INPUT, "/x", Inclusion.INCLUDE_ALL_AND_PATH, "", false); } - public void testSimplePropertyWithoutPath() throws Exception + @Test + void simplePropertyWithoutPath() throws Exception { _assert(SIMPLE_INPUT, "/c", Inclusion.ONLY_INCLUDE_ALL, "{'d':{'a':true}}", false); _assert(SIMPLE_INPUT, "/c/d", Inclusion.ONLY_INCLUDE_ALL, "{'a':true}", false); @@ -40,7 +46,8 @@ public void testSimplePropertyWithoutPath() throws Exception _assert(SIMPLE_INPUT, "/x", Inclusion.ONLY_INCLUDE_ALL, "", false); } - public void testArrayElementWithPath() throws Exception + @Test + void arrayElementWithPath() throws Exception { _assert(SIMPLE_INPUT, "/b", Inclusion.INCLUDE_ALL_AND_PATH, "{'b':[1,2,3]}", false); _assert(SIMPLE_INPUT, "/b/1", Inclusion.INCLUDE_ALL_AND_PATH, "{'b':[2]}", false); @@ -50,7 +57,8 @@ public void testArrayElementWithPath() throws Exception _assert(SIMPLE_INPUT, "/b/8", Inclusion.INCLUDE_ALL_AND_PATH, "", false); } - public void testArrayNestedWithPath() throws Exception + @Test + void arrayNestedWithPath() throws Exception { _assert("{'a':[true,{'b':3,'d':2},false]}", "/a/1/b", Inclusion.INCLUDE_ALL_AND_PATH, "{'a':[{'b':3}]}", false); _assert("[true,[1]]", "/0", Inclusion.INCLUDE_ALL_AND_PATH, "[true]", false); @@ -63,7 +71,8 @@ public void testArrayNestedWithPath() throws Exception _assert("[true,[1,2,[true],3],0]", "/1/3/0", Inclusion.INCLUDE_ALL_AND_PATH, "", false); } - public void testArrayNestedWithoutPath() throws Exception + @Test + void arrayNestedWithoutPath() throws Exception { _assert("{'a':[true,{'b':3,'d':2},false]}", "/a/1/b", Inclusion.ONLY_INCLUDE_ALL, "3", false); _assert("[true,[1,2,[true],3],0]", "/0", Inclusion.ONLY_INCLUDE_ALL, "true", false); @@ -77,7 +86,8 @@ public void testArrayNestedWithoutPath() throws Exception // final String SIMPLE_INPUT = aposToQuotes("{'a':1,'b':[1,2,3],'c':{'d':{'a':true}},'d':null}"); - public void testArrayElementWithoutPath() throws Exception + @Test + void arrayElementWithoutPath() throws Exception { _assert(SIMPLE_INPUT, "/b", Inclusion.ONLY_INCLUDE_ALL, "[1,2,3]", false); _assert(SIMPLE_INPUT, "/b/1", Inclusion.ONLY_INCLUDE_ALL, "2", false); @@ -89,7 +99,8 @@ public void testArrayElementWithoutPath() throws Exception _assert(SIMPLE_INPUT, "/x", Inclusion.ONLY_INCLUDE_ALL, "", false); } - public void testAllowMultipleMatchesWithPath() throws Exception + @Test + void allowMultipleMatchesWithPath() throws Exception { _assert("[1,2,3]", "/0", Inclusion.INCLUDE_ALL_AND_PATH, "[1]", true); _assert("[1,2,3]", "/1", Inclusion.INCLUDE_ALL_AND_PATH, "[2]", true); @@ -132,15 +143,18 @@ private void _assert(String input, String pathExpr, Inclusion tokenFilterInclusi // for [core#582]: regression wrt array filtering - public void testArrayFiltering582WithoutObject() throws IOException { + @Test + void arrayFiltering582WithoutObject() throws IOException { _testArrayFiltering582(0); } - public void testArrayFiltering582WithoutSize() throws IOException { + @Test + void arrayFiltering582WithoutSize() throws IOException { _testArrayFiltering582(1); } - public void testArrayFiltering582WithSize() throws IOException { + @Test + void arrayFiltering582WithSize() throws IOException { _testArrayFiltering582(2); } diff --git a/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerParserFilteringTest.java b/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerParserFilteringTest.java index 7c1097f65f..b843505f87 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerParserFilteringTest.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/JsonPointerParserFilteringTest.java @@ -3,9 +3,13 @@ import java.io.StringWriter; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; -public class JsonPointerParserFilteringTest extends com.fasterxml.jackson.core.BaseTest +import static org.junit.jupiter.api.Assertions.assertEquals; + +class JsonPointerParserFilteringTest extends com.fasterxml.jackson.core.JUnit5TestBase { private final JsonFactory JSON_F = new JsonFactory(); @@ -13,7 +17,8 @@ public class JsonPointerParserFilteringTest extends com.fasterxml.jackson.core.B final String SIMPLE_INPUT = a2q("{'a':1,'b':[1,2,3],'c':{'d':{'a':true}},'d':null}"); - public void testSimplestWithPath() throws Exception + @Test + void simplestWithPath() throws Exception { _assert(SIMPLEST_INPUT, "/a", Inclusion.INCLUDE_ALL_AND_PATH, "{'a':1}"); _assert(SIMPLEST_INPUT, "/b", Inclusion.INCLUDE_ALL_AND_PATH, "{'b':2}"); @@ -22,7 +27,8 @@ public void testSimplestWithPath() throws Exception _assert(SIMPLEST_INPUT, "/d", Inclusion.INCLUDE_ALL_AND_PATH, ""); } - public void testSimplestNoPath() throws Exception + @Test + void simplestNoPath() throws Exception { _assert(SIMPLEST_INPUT, "/a", Inclusion.ONLY_INCLUDE_ALL, "1"); _assert(SIMPLEST_INPUT, "/b", Inclusion.ONLY_INCLUDE_ALL, "2"); @@ -31,7 +37,8 @@ public void testSimplestNoPath() throws Exception _assert(SIMPLEST_INPUT, "/d", Inclusion.ONLY_INCLUDE_ALL, ""); } - public void testSimpleWithPath() throws Exception + @Test + void simpleWithPath() throws Exception { _assert(SIMPLE_INPUT, "/c", Inclusion.INCLUDE_ALL_AND_PATH, "{'c':{'d':{'a':true}}}"); _assert(SIMPLE_INPUT, "/c/d", Inclusion.INCLUDE_ALL_AND_PATH, "{'c':{'d':{'a':true}}}"); @@ -43,7 +50,8 @@ public void testSimpleWithPath() throws Exception _assert(SIMPLE_INPUT, "/b/3", Inclusion.INCLUDE_ALL_AND_PATH, ""); } - public void testSimpleNoPath() throws Exception + @Test + void simpleNoPath() throws Exception { _assert(SIMPLE_INPUT, "/c", Inclusion.ONLY_INCLUDE_ALL, "{'d':{'a':true}}"); diff --git a/src/test/java/com/fasterxml/jackson/core/filter/ParserFiltering700Test.java b/src/test/java/com/fasterxml/jackson/core/filter/ParserFiltering700Test.java index 16d31d0062..99198677ce 100644 --- a/src/test/java/com/fasterxml/jackson/core/filter/ParserFiltering700Test.java +++ b/src/test/java/com/fasterxml/jackson/core/filter/ParserFiltering700Test.java @@ -1,10 +1,14 @@ package com.fasterxml.jackson.core.filter; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion; +import static org.junit.jupiter.api.Assertions.*; + @SuppressWarnings("resource") -public class ParserFiltering700Test extends BaseTest +class ParserFiltering700Test extends JUnit5TestBase { static class NoTypeFilter extends TokenFilter { @Override @@ -25,7 +29,8 @@ public TokenFilter includeProperty(String name) { private final JsonFactory JSON_F = newStreamFactory(); // [core#700], simplified - public void testSkippingRootLevel() throws Exception + @Test + void skippingRootLevel() throws Exception { final String json = a2q("{'@type':'yyy','value':12}"); // should become: {"value":12} @@ -54,7 +59,8 @@ public void testSkippingRootLevel() throws Exception } // [core#700], medium test - public void testSkippingOneNested() throws Exception + @Test + void skippingOneNested() throws Exception { final String json = a2q("{'value':{'@type':'yyy','a':12}}"); // should become: {"value":{"a":12}} @@ -87,7 +93,8 @@ public void testSkippingOneNested() throws Exception } // [core#700], full test - public void testSkippingForSingleWithPath() throws Exception + @Test + void skippingForSingleWithPath() throws Exception { _testSkippingForSingleWithPath(false); _testSkippingForSingleWithPath(true); diff --git a/src/test/java/com/fasterxml/jackson/core/format/DataFormatMatcherTest.java b/src/test/java/com/fasterxml/jackson/core/format/DataFormatMatcherTest.java index c4d4377e4f..00664d93f6 100644 --- a/src/test/java/com/fasterxml/jackson/core/format/DataFormatMatcherTest.java +++ b/src/test/java/com/fasterxml/jackson/core/format/DataFormatMatcherTest.java @@ -5,14 +5,19 @@ import com.fasterxml.jackson.core.JsonFactory; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for class {@link DataFormatMatcher}. */ -public class DataFormatMatcherTest extends com.fasterxml.jackson.core.BaseTest +class DataFormatMatcherTest extends com.fasterxml.jackson.core.JUnit5TestBase { private final JsonFactory JSON_F = new JsonFactory(); - public void testGetDataStream() throws IOException { + @Test + void getDataStream() throws IOException { byte[] byteArray = new byte[2]; MatchStrength matchStrength = MatchStrength.WEAK_MATCH; DataFormatMatcher dataFormatMatcher = new DataFormatMatcher(null, @@ -26,7 +31,8 @@ public void testGetDataStream() throws IOException { inputStream.close(); } - public void testCreatesDataFormatMatcherTwo() throws IOException { + @Test + void createsDataFormatMatcherTwo() throws IOException { try { @SuppressWarnings("unused") DataFormatMatcher dataFormatMatcher = new DataFormatMatcher(null, @@ -37,7 +43,8 @@ public void testCreatesDataFormatMatcherTwo() throws IOException { } } - public void testGetMatchedFormatNameReturnsNameWhenMatches() { + @Test + void getMatchedFormatNameReturnsNameWhenMatches() { DataFormatMatcher dataFormatMatcher = new DataFormatMatcher(null, new byte[2], 1, @@ -47,7 +54,8 @@ public void testGetMatchedFormatNameReturnsNameWhenMatches() { assertEquals(JsonFactory.FORMAT_NAME_JSON, dataFormatMatcher.getMatchedFormatName()); } - public void testDetectorConfiguration() { + @Test + void detectorConfiguration() { DataFormatDetector df0 = new DataFormatDetector(JSON_F); // Defaults are: SOLID for optimal, WEAK for minimum, so: diff --git a/src/test/java/com/fasterxml/jackson/core/format/TestJsonFormatDetection.java b/src/test/java/com/fasterxml/jackson/core/format/TestJsonFormatDetection.java index 863a540322..63242a9410 100644 --- a/src/test/java/com/fasterxml/jackson/core/format/TestJsonFormatDetection.java +++ b/src/test/java/com/fasterxml/jackson/core/format/TestJsonFormatDetection.java @@ -4,9 +4,14 @@ import com.fasterxml.jackson.core.*; -public class TestJsonFormatDetection extends com.fasterxml.jackson.core.BaseTest +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class TestJsonFormatDetection extends com.fasterxml.jackson.core.JUnit5TestBase { - public void testSimpleValidArray() throws Exception + @Test + void simpleValidArray() throws Exception { JsonFactory jsonF = new JsonFactory(); DataFormatDetector detector = new DataFormatDetector(jsonF); @@ -28,7 +33,8 @@ public void testSimpleValidArray() throws Exception jp.close(); } - public void testSimpleValidObject() throws Exception + @Test + void simpleValidObject() throws Exception { JsonFactory jsonF = new JsonFactory(); DataFormatDetector detector = new DataFormatDetector(jsonF); @@ -55,7 +61,8 @@ public void testSimpleValidObject() throws Exception * While JSON String is not a strong match alone, it should * be detected unless some better match is available */ - public void testSimpleValidString() throws Exception + @Test + void simpleValidString() throws Exception { JsonFactory jsonF = new JsonFactory(); DataFormatDetector detector = new DataFormatDetector(jsonF); @@ -80,7 +87,8 @@ private void _testSimpleValidString(JsonFactory jsonF, DataFormatMatcher matcher jp.close(); } - public void testSimpleInvalid() throws Exception + @Test + void simpleInvalid() throws Exception { DataFormatDetector detector = new DataFormatDetector(new JsonFactory()); final String NON_JSON = ""; diff --git a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz32208UTF32ParseTest.java b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz32208UTF32ParseTest.java index 8e16d388c3..9cab10dab7 100644 --- a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz32208UTF32ParseTest.java +++ b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz32208UTF32ParseTest.java @@ -5,16 +5,21 @@ import java.io.InputStream; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.io.UTF32Reader; import com.fasterxml.jackson.core.testsupport.ThrottledInputStream; +import static org.junit.jupiter.api.Assertions.fail; + // Trying to repro: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32216 // but so far without success (fails on seemingly legit validation problem) -public class Fuzz32208UTF32ParseTest extends BaseTest +class Fuzz32208UTF32ParseTest extends JUnit5TestBase { private final byte[] DOC = readResource("/data/fuzz-json-utf32-32208.json"); - public void testFuzz32208ViaParser() throws Exception + @Test + void fuzz32208ViaParser() throws Exception { final JsonFactory f = new JsonFactory(); @@ -30,7 +35,8 @@ public void testFuzz32208ViaParser() throws Exception } // How about through UTF32Reader itself? - public void testFuzz32208Direct() throws Exception + @Test + void fuzz32208Direct() throws Exception { _testFuzz32208Direct(1); _testFuzz32208Direct(2); @@ -43,7 +49,8 @@ public void testFuzz32208Direct() throws Exception _testFuzz32208Direct(991); } - public void testFuzz32208DirectSingleByte() throws Exception + @Test + void fuzz32208DirectSingleByte() throws Exception { UTF32Reader r = new UTF32Reader(null, new ByteArrayInputStream(DOC), new byte[500], 0, 0, false); diff --git a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz34435ParseTest.java b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz34435ParseTest.java index d3689a525e..201419fb5a 100644 --- a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz34435ParseTest.java +++ b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz34435ParseTest.java @@ -1,15 +1,20 @@ package com.fasterxml.jackson.core.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.core.json.JsonReadFeature; +import static org.junit.jupiter.api.Assertions.fail; + // Trying to repro: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34435 -public class Fuzz34435ParseTest extends BaseTest +class Fuzz34435ParseTest extends JUnit5TestBase { private final byte[] DOC = readResource("/data/fuzz-json-34435.json"); - public void testFuzz34435ViaParser() throws Exception + @Test + void fuzz34435ViaParser() throws Exception { final JsonFactory f = JsonFactory.builder() // NOTE: test set up enables a few non-standard features diff --git a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz52688ParseTest.java b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz52688ParseTest.java index fb1f2bab25..a6b51c3042 100644 --- a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz52688ParseTest.java +++ b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz52688ParseTest.java @@ -4,12 +4,17 @@ import java.math.BigInteger; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.core.testsupport.ThrottledInputStream; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + // Reproducing: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52688 // (reported as [core#834] -public class Fuzz52688ParseTest extends BaseTest +class Fuzz52688ParseTest extends JUnit5TestBase { private final JsonFactory JSON_F = new JsonFactory(); @@ -19,7 +24,8 @@ public class Fuzz52688ParseTest extends BaseTest +"2222" +"222"); - public void testBigNumberUTF16Parse() throws Exception + @Test + void bigNumberUTF16Parse() throws Exception { // 41 bytes as UTF16-LE; becomes 21 characters (last broken) final byte[] DOC = { @@ -49,7 +55,8 @@ public void testBigNumberUTF16Parse() throws Exception } } - public void testBigNumberUTF8Parse() throws Exception + @Test + void bigNumberUTF8Parse() throws Exception { // Similar to UTF-16 case final byte[] DOC = { diff --git a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz61198_1169_NumberParseTest.java b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz61198_1169_NumberParseTest.java index 9704ddf8f1..b5acdac54d 100644 --- a/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz61198_1169_NumberParseTest.java +++ b/src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz61198_1169_NumberParseTest.java @@ -1,13 +1,17 @@ package com.fasterxml.jackson.core.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.json.JsonReadFeature; +import static org.junit.jupiter.api.Assertions.fail; + // For // // * [core#1169], // * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61198 -public class Fuzz61198_1169_NumberParseTest extends BaseTest +class Fuzz61198_1169_NumberParseTest extends JUnit5TestBase { // NOTE! Not enough to enable just first, but both it seem private final JsonFactory JSON_F = JsonFactory.builder() @@ -15,17 +19,20 @@ public class Fuzz61198_1169_NumberParseTest extends BaseTest .enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS) .build(); - public void testLeadingPlusSignMalformedBytes() throws Exception { + @Test + void leadingPlusSignMalformedBytes() throws Exception { _testLeadingPlusMalformed(JSON_F, MODE_INPUT_STREAM); _testLeadingPlusMalformed(JSON_F, MODE_INPUT_STREAM_THROTTLED); } - public void testLeadingPlusSignMalformedReader() throws Exception { + @Test + void leadingPlusSignMalformedReader() throws Exception { _testLeadingPlusMalformed(JSON_F, MODE_READER); _testLeadingPlusMalformed(JSON_F, MODE_READER_THROTTLED); } - public void testLeadingPlusSignMalformedOther() throws Exception { + @Test + void leadingPlusSignMalformedOther() throws Exception { _testLeadingPlusMalformed(JSON_F, MODE_DATA_INPUT); } diff --git a/src/test/java/com/fasterxml/jackson/core/jsonptr/Fuzz51806JsonPointerParse818Test.java b/src/test/java/com/fasterxml/jackson/core/jsonptr/Fuzz51806JsonPointerParse818Test.java index 22a3ad3339..fbb6247ac6 100644 --- a/src/test/java/com/fasterxml/jackson/core/jsonptr/Fuzz51806JsonPointerParse818Test.java +++ b/src/test/java/com/fasterxml/jackson/core/jsonptr/Fuzz51806JsonPointerParse818Test.java @@ -1,11 +1,15 @@ package com.fasterxml.jackson.core.jsonptr; -import com.fasterxml.jackson.core.BaseTest; +import com.fasterxml.jackson.core.JUnit5TestBase; import com.fasterxml.jackson.core.JsonPointer; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; // For https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51806 // (reported as [core#818] -public class Fuzz51806JsonPointerParse818Test extends BaseTest +class Fuzz51806JsonPointerParse818Test extends JUnit5TestBase { // Before fix, StackOverflowError with 6_000 or so, // and OOME with 20_000. @@ -15,12 +19,14 @@ public class Fuzz51806JsonPointerParse818Test extends BaseTest // Verify that a very deep/long (by number of segments) JsonPointer // may still be parsed ok, for "simple" case (no quoted chars) - public void testJsonPointerParseTailSimple() + @Test + void jsonPointerParseTailSimple() { _testJsonPointer(_generatePath(TOO_DEEP_PATH, false)); } - public void testJsonPointerParseTailWithQuoted() + @Test + void jsonPointerParseTailWithQuoted() { _testJsonPointer(_generatePath(TOO_DEEP_PATH, true)); } diff --git a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointer1168Test.java b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointer1168Test.java index cb4f3f89a5..2f0d8ab6f9 100644 --- a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointer1168Test.java +++ b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointer1168Test.java @@ -1,12 +1,16 @@ package com.fasterxml.jackson.core.jsonptr; -import com.fasterxml.jackson.core.BaseTest; +import com.fasterxml.jackson.core.JUnit5TestBase; import com.fasterxml.jackson.core.JsonPointer; +import org.junit.jupiter.api.Test; -public class JsonPointer1168Test extends BaseTest +import static org.junit.jupiter.api.Assertions.assertEquals; + +class JsonPointer1168Test extends JUnit5TestBase { // [core#1168] - public void testAppendWithTail() + @Test + void appendWithTail() { JsonPointer original = JsonPointer.compile("/a1/b/c"); JsonPointer tailPointer = original.tail(); diff --git a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerOOME736Test.java b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerOOME736Test.java index d2f4e0bff0..2886f6952b 100644 --- a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerOOME736Test.java +++ b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerOOME736Test.java @@ -1,12 +1,17 @@ package com.fasterxml.jackson.core.jsonptr; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.exc.StreamReadException; -public class JsonPointerOOME736Test extends BaseTest +import static org.junit.jupiter.api.Assertions.assertEquals; + +class JsonPointerOOME736Test extends JUnit5TestBase { // such as https://github.com/nst/JSONTestSuite/blob/master/test_parsing/n_structure_100000_opening_arrays.json - public void testDeepJsonPointer() throws Exception { + @Test + void deepJsonPointer() throws Exception { int MAX_DEPTH = 120_000; // Create nesting of 120k arrays String INPUT = new String(new char[MAX_DEPTH]).replace("\0", "["); diff --git a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerTest.java b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerTest.java index 78c2af1277..4d80d06ed0 100644 --- a/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerTest.java +++ b/src/test/java/com/fasterxml/jackson/core/jsonptr/JsonPointerTest.java @@ -1,13 +1,17 @@ package com.fasterxml.jackson.core.jsonptr; -import com.fasterxml.jackson.core.BaseTest; +import com.fasterxml.jackson.core.JUnit5TestBase; import com.fasterxml.jackson.core.JsonPointer; +import org.junit.jupiter.api.Test; -public class JsonPointerTest extends BaseTest +import static org.junit.jupiter.api.Assertions.*; + +class JsonPointerTest extends JUnit5TestBase { private final JsonPointer EMPTY_PTR = JsonPointer.empty(); - public void testSimplePath() throws Exception + @Test + void simplePath() throws Exception { final String INPUT = "/Image/15/name"; @@ -47,7 +51,8 @@ public void testSimplePath() throws Exception assertEquals(-1, ptr.getMatchingIndex()); } - public void testSimplePathLonger() throws Exception + @Test + void simplePathLonger() throws Exception { final String INPUT = "/a/b/c/d/e/f/0"; JsonPointer ptr = JsonPointer.compile(INPUT); @@ -60,7 +65,8 @@ public void testSimplePathLonger() throws Exception assertEquals(INPUT, ptr.toString()); } - public void testSimpleTail() throws Exception + @Test + void simpleTail() throws Exception { final String INPUT = "/root/leaf"; JsonPointer ptr = JsonPointer.compile(INPUT); @@ -69,14 +75,16 @@ public void testSimpleTail() throws Exception assertEquals("", ptr.tail().tail().toString()); } - public void testWonkyNumber173() throws Exception + @Test + void wonkyNumber173() throws Exception { JsonPointer ptr = JsonPointer.compile("/1e0"); assertFalse(ptr.matches()); } // [core#176]: do not allow leading zeroes - public void testIZeroIndex() throws Exception + @Test + void iZeroIndex() throws Exception { JsonPointer ptr = JsonPointer.compile("/0"); assertEquals(0, ptr.getMatchingIndex()); @@ -84,7 +92,8 @@ public void testIZeroIndex() throws Exception assertEquals(-1, ptr.getMatchingIndex()); } - public void testLast() + @Test + void last() { String INPUT = "/Image/name"; @@ -103,7 +112,8 @@ public void testLast() assertEquals("name", leaf.getMatchingProperty()); } - public void testEmptyPointer() + @Test + void emptyPointer() { assertSame(EMPTY_PTR, JsonPointer.compile("")); assertEquals("", EMPTY_PTR.toString()); @@ -115,7 +125,8 @@ public void testEmptyPointer() assertNull(EMPTY_PTR.getMatchingProperty()); } - public void testPointerWithEmptyPropertyName() + @Test + void pointerWithEmptyPropertyName() { // note: this is acceptable, to match property in '{"":3}', for example // and NOT same as what empty point, "", is. @@ -135,12 +146,13 @@ public void testPointerWithEmptyPropertyName() } // mostly for test coverage, really... - public void testEquality() { - assertFalse(JsonPointer.empty().equals(JsonPointer.compile("/"))); + @Test + void equality() { + assertNotEquals(JsonPointer.empty(), JsonPointer.compile("/")); assertEquals(JsonPointer.compile("/foo/3"), JsonPointer.compile("/foo/3")); - assertFalse(JsonPointer.empty().equals(JsonPointer.compile("/12"))); - assertFalse(JsonPointer.compile("/12").equals(JsonPointer.empty())); + assertNotEquals(JsonPointer.empty(), JsonPointer.compile("/12")); + assertNotEquals(JsonPointer.compile("/12"), JsonPointer.empty()); assertEquals(JsonPointer.compile("/a/b/c").tail(), JsonPointer.compile("/foo/b/c").tail()); @@ -151,10 +163,11 @@ public void testEquality() { assertEquals(def, abcDef.tail()); // expr != String - assertFalse(JsonPointer.empty().equals("/")); + assertNotEquals("/", JsonPointer.empty()); } - public void testProperties() { + @Test + void properties() { assertTrue(JsonPointer.compile("/foo").mayMatchProperty()); assertFalse(JsonPointer.compile("/foo").mayMatchElement()); @@ -164,7 +177,8 @@ public void testProperties() { assertTrue(JsonPointer.compile("/12").mayMatchProperty()); } - public void testAppend() + @Test + void append() { final String INPUT = "/Image/15/name"; final String APPEND = "/extension"; @@ -179,7 +193,8 @@ public void testAppend() assertEquals("/Image/15/name/extension", appended.toString()); } - public void testAppendWithFinalSlash() + @Test + void appendWithFinalSlash() { final String INPUT = "/Image/15/name/"; final String APPEND = "/extension"; @@ -196,7 +211,8 @@ public void testAppendWithFinalSlash() assertEquals("/Image/15/name//extension", appended.toString()); } - public void testAppendProperty() + @Test + void appendProperty() { final String INPUT = "/Image/15/name"; final String APPEND_NO_SLASH = "extension"; @@ -214,7 +230,8 @@ public void testAppendProperty() } // [core#1145]: Escape property - public void testAppendPropertyEmpty() + @Test + void appendPropertyEmpty() { final String BASE = "/Image/72/src"; @@ -229,7 +246,8 @@ public void testAppendPropertyEmpty() assertEquals(BASE+"/", sub.toString()); } - public void testAppendIndex() + @Test + void appendIndex() { final String INPUT = "/Image/15/name"; final int INDEX = 12; @@ -240,7 +258,8 @@ public void testAppendIndex() assertEquals(12, appended.last().getMatchingIndex()); } - public void testQuotedPath() throws Exception + @Test + void quotedPath() throws Exception { final String INPUT = "/w~1out/til~0de/~1ab"; @@ -274,7 +293,8 @@ public void testQuotedPath() throws Exception } // [core#133] - public void testLongNumbers() throws Exception + @Test + void longNumbers() throws Exception { final long LONG_ID = (Integer.MAX_VALUE) + 1L; diff --git a/src/test/java/com/fasterxml/jackson/core/jsonptr/PointerFromContextTest.java b/src/test/java/com/fasterxml/jackson/core/jsonptr/PointerFromContextTest.java index e61199031f..3b3f4795ba 100644 --- a/src/test/java/com/fasterxml/jackson/core/jsonptr/PointerFromContextTest.java +++ b/src/test/java/com/fasterxml/jackson/core/jsonptr/PointerFromContextTest.java @@ -2,14 +2,13 @@ import java.io.StringWriter; -import com.fasterxml.jackson.core.BaseTest; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonPointer; -import com.fasterxml.jackson.core.JsonToken; - -public class PointerFromContextTest extends BaseTest +import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PointerFromContextTest extends JUnit5TestBase { /* /********************************************************** @@ -21,7 +20,8 @@ public class PointerFromContextTest extends BaseTest private final JsonPointer EMPTY_PTR = JsonPointer.empty(); - public void testViaParser() throws Exception + @Test + void viaParser() throws Exception { final String SIMPLE = a2q("{'a':123,'array':[1,2,[3],5,{'obInArray':4}]," +"'ob':{'first':[false,true],'second':{'sub':37}},'b':true}"); @@ -106,7 +106,8 @@ public void testViaParser() throws Exception p.close(); } - public void testViaGenerator() throws Exception + @Test + void viaGenerator() throws Exception { StringWriter w = new StringWriter(); JsonGenerator g = JSON_F.createGenerator(w); @@ -150,7 +151,8 @@ public void testViaGenerator() throws Exception /********************************************************** */ - public void testParserWithRoot() throws Exception + @Test + void parserWithRoot() throws Exception { final String JSON = a2q("{'a':1,'b':3}\n" +"{'a':5,'c':[1,2]}\n[1,2]\n"); @@ -213,7 +215,8 @@ public void testParserWithRoot() throws Exception p.close(); } - public void testGeneratorWithRoot() throws Exception + @Test + void generatorWithRoot() throws Exception { StringWriter w = new StringWriter(); JsonGenerator g = JSON_F.createGenerator(w); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/PlaceholderSymbolTableTest.java b/src/test/java/com/fasterxml/jackson/core/sym/PlaceholderSymbolTableTest.java index 4d0aa0819a..4db1b3458c 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/PlaceholderSymbolTableTest.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/PlaceholderSymbolTableTest.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.core.sym; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + // Simple tests to verify "placeholder" variant added in 2.13 -public class PlaceholderSymbolTableTest extends com.fasterxml.jackson.core.BaseTest +class PlaceholderSymbolTableTest extends com.fasterxml.jackson.core.JUnit5TestBase { // Test to verify it is ok to try to find names, and that none // are ever found - public void testBasicPlaceholderLookups() throws Exception + @Test + void basicPlaceholderLookups() throws Exception { final ByteQuadsCanonicalizer root = ByteQuadsCanonicalizer.createRoot(137); assertEquals(0, root.size()); @@ -26,7 +31,8 @@ public void testBasicPlaceholderLookups() throws Exception } // Also: should not allow additions - public void testBasicPlaceholderAddFails() throws Exception + @Test + void basicPlaceholderAddFails() throws Exception { final ByteQuadsCanonicalizer root = ByteQuadsCanonicalizer.createRoot(137); ByteQuadsCanonicalizer placeholder = root.makeChildOrPlaceholder(0); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/SymbolTableMergingTest.java b/src/test/java/com/fasterxml/jackson/core/sym/SymbolTableMergingTest.java index a2f1acd64d..59f90edb1e 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/SymbolTableMergingTest.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/SymbolTableMergingTest.java @@ -3,16 +3,20 @@ import java.io.IOException; import com.fasterxml.jackson.core.*; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.json.ReaderBasedJsonParser; import com.fasterxml.jackson.core.json.UTF8StreamJsonParser; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Unit tests for verifying that {@link JsonParser} instances properly * merge back symbols to the root symbol table */ @SuppressWarnings("serial") -public class SymbolTableMergingTest - extends com.fasterxml.jackson.core.BaseTest +class SymbolTableMergingTest + extends com.fasterxml.jackson.core.JUnit5TestBase { /** * To peek into state of "root" symbol tables (parent of all symbol @@ -27,12 +31,14 @@ final static class MyJsonFactory extends JsonFactory final static String JSON = "{ \"a\" : 3, \"aaa\" : 4, \"_a\" : 0 }"; - public void testByteSymbolsWithClose() throws Exception + @Test + void byteSymbolsWithClose() throws Exception { _testWithClose(true); } - public void testByteSymbolsWithEOF() throws Exception + @Test + void byteSymbolsWithEOF() throws Exception { MyJsonFactory f = new MyJsonFactory(); JsonParser jp = _getParser(f, JSON, true); @@ -46,7 +52,8 @@ public void testByteSymbolsWithEOF() throws Exception assertEquals(3, f.byteSymbolCount()); } - public void testHashCalc() throws Exception + @Test + void hashCalc() throws Exception { CharsToNameCanonicalizer sym = CharsToNameCanonicalizer.createRoot(new JsonFactory()); char[] str1 = "foo".toCharArray(); @@ -55,12 +62,14 @@ public void testHashCalc() throws Exception assertEquals(sym.calcHash(str1, 0, 3), sym.calcHash(str2, 1, 3)); } - public void testCharSymbolsWithClose() throws Exception + @Test + void charSymbolsWithClose() throws Exception { _testWithClose(false); } - public void testCharSymbolsWithEOF() throws Exception + @Test + void charSymbolsWithEOF() throws Exception { MyJsonFactory f = new MyJsonFactory(); JsonParser jp = _getParser(f, JSON, false); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/SymbolsViaParserTest.java b/src/test/java/com/fasterxml/jackson/core/sym/SymbolsViaParserTest.java index 545b955195..a2115c3a5e 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/SymbolsViaParserTest.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/SymbolsViaParserTest.java @@ -5,28 +5,37 @@ import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + // Tests to guarad against [core#213]: does not verify symbol tables // directly but only indirect issue(s). public class SymbolsViaParserTest - extends com.fasterxml.jackson.core.BaseTest + extends com.fasterxml.jackson.core.JUnit5TestBase { // for [jackson-core#213] - public void test17CharSymbols() throws Exception { + @Test + void test17CharSymbols() throws Exception { _test17Chars(false); } // for [jackson-core#213] - public void test17ByteSymbols() throws Exception { + @Test + void test17ByteSymbols() throws Exception { _test17Chars(true); } // for [jackson-core#216] - public void testSymbolTableExpansionChars() throws Exception { + @Test + void symbolTableExpansionChars() throws Exception { _testSymbolTableExpansion(false); } // for [jackson-core#216] - public void testSymbolTableExpansionBytes() throws Exception { + @Test + void symbolTableExpansionBytes() throws Exception { _testSymbolTableExpansion(true); } diff --git a/src/test/java/com/fasterxml/jackson/core/sym/TestByteBasedSymbols.java b/src/test/java/com/fasterxml/jackson/core/sym/TestByteBasedSymbols.java index 2d6a876b1a..6e40698a40 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/TestByteBasedSymbols.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/TestByteBasedSymbols.java @@ -7,12 +7,16 @@ import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + /** * Unit test(s) to verify that handling of (byte-based) symbol tables * is working. */ -public class TestByteBasedSymbols - extends com.fasterxml.jackson.core.BaseTest +class TestByteBasedSymbols + extends com.fasterxml.jackson.core.JUnit5TestBase { final static String[] FIELD_NAMES = new String[] { "a", "b", "c", "x", "y", "b13", "abcdefg", "a123", @@ -27,7 +31,8 @@ public class TestByteBasedSymbols * This unit test checks that [JACKSON-5] is fixed; if not, a * symbol table corruption should result in odd problems. */ - public void testSharedSymbols() throws Exception + @Test + void sharedSymbols() throws Exception { // MUST share a single json factory JsonFactory jf = new JsonFactory(); @@ -75,7 +80,8 @@ public void testSharedSymbols() throws Exception jp0.close(); } - public void testAuxMethodsWithNewSymboTable() throws Exception + @Test + void auxMethodsWithNewSymboTable() throws Exception { final int A_BYTES = 0x41414141; // "AAAA" final int B_BYTES = 0x42424242; // "BBBB" @@ -100,7 +106,8 @@ public void testAuxMethodsWithNewSymboTable() throws Exception } // as per name, for [core#207] - public void testIssue207() throws Exception + @Test + void issue207() throws Exception { ByteQuadsCanonicalizer nc = ByteQuadsCanonicalizer.createRoot(-523743345); Field byteSymbolCanonicalizerField = JsonFactory.class.getDeclaredField("_byteSymbolCanonicalizer"); @@ -122,7 +129,8 @@ public void testIssue207() throws Exception } // [core#548] - public void testQuadsIssue548() throws Exception + @Test + void quadsIssue548() throws Exception { Random r = new Random(42); ByteQuadsCanonicalizer root = ByteQuadsCanonicalizer.createRoot(); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/TestHashCollisionChars.java b/src/test/java/com/fasterxml/jackson/core/sym/TestHashCollisionChars.java index 3e9b9b07e4..6f3d68da51 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/TestHashCollisionChars.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/TestHashCollisionChars.java @@ -5,6 +5,10 @@ import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + /** * Some unit tests to try to exercise part of parser code that * deals with symbol (table) management. @@ -15,7 +19,7 @@ * sources, however. */ public class TestHashCollisionChars - extends BaseTest + extends JUnit5TestBase { // // // And then a nastier variant; collisions generated using // // // CollisionGenerator @@ -34,7 +38,8 @@ public class TestHashCollisionChars }; */ - public void testReaderCollisions() throws Exception + @Test + void readerCollisions() throws Exception { StringBuilder sb = new StringBuilder(); List coll = collisions(); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolTables.java b/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolTables.java index 9b41b855bd..6c7be74da8 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolTables.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolTables.java @@ -7,17 +7,22 @@ import com.fasterxml.jackson.core.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + /** * Tests that directly modify/access underlying low-level symbol tables * (instead of indirectly using them via JsonParser). */ -public class TestSymbolTables extends com.fasterxml.jackson.core.BaseTest +class TestSymbolTables extends com.fasterxml.jackson.core.JUnit5TestBase { private final static JsonFactory JSON_F = new JsonFactory(); // Test for verifying stability of hashCode, wrt collisions, using // synthetic field name generation and character-based input - public void testSyntheticWithChars() throws IOException + @Test + void syntheticWithChars() throws IOException { // pass seed, to keep results consistent: CharsToNameCanonicalizer symbols = CharsToNameCanonicalizer.createRoot(JSON_F, -1).makeChild(); @@ -45,7 +50,8 @@ public void testSyntheticWithChars() throws IOException symbols.verifyInternalConsistency(); } - public void testSyntheticWithBytesNew() throws IOException + @Test + void syntheticWithBytesNew() throws IOException { // pass seed, to keep results consistent: final int SEED = 33333; @@ -74,7 +80,8 @@ public void testSyntheticWithBytesNew() throws IOException } // [Issue#145] - public void testThousandsOfSymbolsWithChars() throws IOException + @Test + void thousandsOfSymbolsWithChars() throws IOException { CharsToNameCanonicalizer symbolsCRoot = CharsToNameCanonicalizer.createRoot(JSON_F); int exp = 0; @@ -104,7 +111,8 @@ public void testThousandsOfSymbolsWithChars() throws IOException } // Since 2.6 - public void testThousandsOfSymbolsWithNew() throws IOException + @Test + void thousandsOfSymbolsWithNew() throws IOException { final int SEED = 33333; @@ -144,7 +152,8 @@ public void testThousandsOfSymbolsWithNew() throws IOException } // And then one more test just for Bytes-based symbol table - public void testByteBasedSymbolTable() throws Exception + @Test + void byteBasedSymbolTable() throws Exception { // combination of short, medium1/2, long names... final String JSON = a2q("{'abc':1, 'abc\\u0000':2, '\\u0000abc':3, " @@ -189,7 +198,8 @@ private ByteQuadsCanonicalizer _findSymbols(JsonParser p) throws Exception } // [core#187]: unexpectedly high number of collisions for straight numbers - public void testCollisionsWithChars187() throws IOException + @Test + void collisionsWithChars187() throws IOException { CharsToNameCanonicalizer symbols = CharsToNameCanonicalizer.createRoot(JSON_F, -1).makeChild(); final int COUNT = 30000; @@ -208,7 +218,8 @@ public void testCollisionsWithChars187() throws IOException } // [core#187]: unexpectedly high number of collisions for straight numbers - public void testCollisionsWithBytesNew187a() throws IOException + @Test + void collisionsWithBytesNew187a() throws IOException { ByteQuadsCanonicalizer symbols = ByteQuadsCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults()); @@ -235,7 +246,8 @@ public void testCollisionsWithBytesNew187a() throws IOException } // Another variant, but with 1-quad names - public void testCollisionsWithBytesNew187b() throws IOException + @Test + void collisionsWithBytesNew187b() throws IOException { ByteQuadsCanonicalizer symbols = ByteQuadsCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults()); @@ -262,7 +274,8 @@ public void testCollisionsWithBytesNew187b() throws IOException } // [core#191]: similarly, but for "short" symbols: - public void testShortNameCollisionsViaParser() throws Exception + @Test + void shortNameCollisionsViaParser() throws Exception { JsonFactory f = new JsonFactory(); String json = _shortDoc191(); @@ -300,7 +313,8 @@ private String _shortDoc191() { } // [core#191] - public void testShortQuotedDirectChars() throws IOException + @Test + void shortQuotedDirectChars() throws IOException { final int COUNT = 400; @@ -317,7 +331,8 @@ public void testShortQuotedDirectChars() throws IOException assertEquals(2, symbols.maxCollisionLength()); } - public void testShortQuotedDirectBytes() throws IOException + @Test + void shortQuotedDirectBytes() throws IOException { final int COUNT = 400; ByteQuadsCanonicalizer symbols = @@ -337,7 +352,8 @@ public void testShortQuotedDirectBytes() throws IOException } // [core#191] - public void testShortNameCollisionsDirect() throws IOException + @Test + void shortNameCollisionsDirect() throws IOException { final int COUNT = 600; @@ -357,7 +373,8 @@ public void testShortNameCollisionsDirect() throws IOException } } - public void testShortNameCollisionsDirectNew() throws IOException + @Test + void shortNameCollisionsDirectNew() throws IOException { final int COUNT = 700; { @@ -385,7 +402,8 @@ public void testShortNameCollisionsDirectNew() throws IOException // to verify [jackson-core#213] -- did not fail, but ruled out low-level bug - public void testLongSymbols17Bytes() throws Exception + @Test + void longSymbols17Bytes() throws Exception { ByteQuadsCanonicalizer symbolsB = ByteQuadsCanonicalizer.createRoot(3).makeChild(JsonFactory.Feature.collectDefaults()); diff --git a/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolsWithMediaItem.java b/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolsWithMediaItem.java index 3592e675b6..ebf92c5963 100644 --- a/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolsWithMediaItem.java +++ b/src/test/java/com/fasterxml/jackson/core/sym/TestSymbolsWithMediaItem.java @@ -4,7 +4,11 @@ import com.fasterxml.jackson.core.*; -public class TestSymbolsWithMediaItem extends com.fasterxml.jackson.core.BaseTest +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestSymbolsWithMediaItem extends com.fasterxml.jackson.core.JUnit5TestBase { private final String JSON = a2q( "{'media' : {\n" @@ -32,7 +36,8 @@ public class TestSymbolsWithMediaItem extends com.fasterxml.jackson.core.BaseTes +" } ]\n" +"}\n"); - public void testSmallSymbolSetWithBytes() throws IOException + @Test + void smallSymbolSetWithBytes() throws IOException { final int SEED = 33333; @@ -63,7 +68,8 @@ public void testSmallSymbolSetWithBytes() throws IOException assertEquals(0, symbols.spilloverCount()); // and couple of leftovers } - public void testSmallSymbolSetWithChars() throws IOException + @Test + void smallSymbolSetWithChars() throws IOException { final int SEED = 33333;