Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 26, 2023
2 parents 2cdbd46 + ec3504b commit 3d73290
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 50 deletions.
12 changes: 0 additions & 12 deletions src/main/java/tools/jackson/core/io/IOContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,6 @@ public IOContext(StreamReadConstraints src, StreamWriteConstraints swc,
_encoding = enc;
}

/**
* Factory method for use by test code: NOT to be used for non-test use
*
* Since 2.16
*/
public static IOContext testIOContext() {
return new IOContext(StreamReadConstraints.defaults(), StreamWriteConstraints.defaults(),
ErrorReportConfiguration.defaults(),
new BufferRecycler(), ContentReference.unknown(), false,
JsonEncoding.UTF8);
}

/*
/**********************************************************************
/* Public API, accessors
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/tools/jackson/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import tools.jackson.core.io.IOContext;
import tools.jackson.core.json.JsonFactory;
import tools.jackson.core.json.JsonFactoryBuilder;
import tools.jackson.core.testsupport.MockDataInput;
import tools.jackson.core.testsupport.TestSupport;
import tools.jackson.core.testsupport.ThrottledInputStream;
import tools.jackson.core.testsupport.ThrottledReader;
import tools.jackson.core.util.Named;
Expand Down Expand Up @@ -432,6 +434,16 @@ protected JsonGenerator createGenerator(TokenStreamFactory f, Writer w) {

/*
/**********************************************************************
/* Helper type construction
/**********************************************************************
*/

protected static IOContext testIOContext() {
return TestSupport.testIOContext();
}

/*
/**********************************************************
/* Helper read/write methods
/**********************************************************************
*/
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/tools/jackson/core/TestVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public void testCoreVersions() throws Exception
{
final JsonFactory f = new JsonFactory();
assertVersion(f.version());
JsonParser jp = f.createParser(ObjectReadContext.empty(),
new StringReader("true"));
assertVersion(jp.version());
jp.close();
JsonGenerator jg = f.createGenerator(ObjectWriteContext.empty(),
new ByteArrayOutputStream());
assertVersion(jg.version());
jg.close();
try (JsonParser jp = f.createParser(ObjectReadContext.empty(),
new StringReader("true"))) {
assertVersion(jp.version());
}
try (JsonGenerator jg = f.createGenerator(ObjectWriteContext.empty(),
new ByteArrayOutputStream())) {
assertVersion(jg.version());
}
}

public void testMisc() {
Expand All @@ -36,9 +36,9 @@ public void testMisc() {
}

/*
/**********************************************************
/**********************************************************************
/* Helper methods
/**********************************************************
/**********************************************************************
*/

private void assertVersion(Version v)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tools/jackson/core/io/TestMergedStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TestMergedStream
{
public void testSimple() throws Exception
{
IOContext ctxt = IOContext.testIOContext();
IOContext ctxt = testIOContext();
// bit complicated; must use recyclable buffer...
byte[] first = ctxt.allocReadIOBuffer();
System.arraycopy("ABCDE".getBytes("UTF-8"), 0, first, 99, 5);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tools/jackson/core/io/UTF8WriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ public void testSurrogatesFail() throws Exception
}

private IOContext _ioContext() {
return IOContext.testIOContext();
return testIOContext();
}
}
34 changes: 34 additions & 0 deletions src/test/java/tools/jackson/core/testsupport/TestSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package tools.jackson.core.testsupport;

import tools.jackson.core.*;
import tools.jackson.core.io.ContentReference;
import tools.jackson.core.io.IOContext;
import tools.jackson.core.util.BufferRecycler;

/**
* Container for various factories needed by (unit) tests.
*
* @since 2.16
*/
public class TestSupport
{
/**
* Factory method for creating {@link IOContext}s for tests
*/
public static IOContext testIOContext() {
return new IOContext(StreamReadConstraints.defaults(), StreamWriteConstraints.defaults(),
ErrorReportConfiguration.defaults(),
new BufferRecycler(), ContentReference.unknown(), false,
JsonEncoding.UTF8);
}

/**
* Factory method for creating {@link IOContext}s for tests
*/
public static IOContext testIOContext(StreamWriteConstraints swc) {
return new IOContext(StreamReadConstraints.defaults(), swc,
ErrorReportConfiguration.defaults(),
new BufferRecycler(), ContentReference.unknown(), false,
JsonEncoding.UTF8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class JsonParserSequenceTest extends BaseTest
{
public void testClose() throws IOException {
IOContext ioContext = IOContext.testIOContext();
IOContext ioContext = testIOContext();
ReaderBasedJsonParser readerBasedJsonParser = new ReaderBasedJsonParser(
ObjectReadContext.empty(),
ioContext,
Expand All @@ -41,7 +41,7 @@ public void testClose() throws IOException {

public void testSkipChildren() throws IOException {
JsonParser[] jsonParserArray = new JsonParser[3];
IOContext ioContext = IOContext.testIOContext();
IOContext ioContext = testIOContext();
byte[] byteArray = new byte[8];
InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray, 0, (byte) 58);
UTF8StreamJsonParser uTF8StreamJsonParser = new UTF8StreamJsonParser(ObjectReadContext.empty(),
Expand Down
40 changes: 16 additions & 24 deletions src/test/java/tools/jackson/core/write/UTF8GeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import tools.jackson.core.filter.FilteringGeneratorDelegate;
import tools.jackson.core.filter.JsonPointerBasedFilter;
import tools.jackson.core.filter.TokenFilter.Inclusion;
import tools.jackson.core.io.ContentReference;
import tools.jackson.core.io.IOContext;
import tools.jackson.core.json.JsonFactory;
import tools.jackson.core.json.UTF8JsonGenerator;
import tools.jackson.core.util.BufferRecycler;
import tools.jackson.core.testsupport.TestSupport;

public class UTF8GeneratorTest extends BaseTest
{
Expand All @@ -20,7 +19,7 @@ public class UTF8GeneratorTest extends BaseTest
public void testUtf8Issue462() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = IOContext.testIOContext();
IOContext ioc = testIOContext();
JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, 0, bytes,
JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null,
0, '"');
Expand Down Expand Up @@ -49,7 +48,8 @@ public void testUtf8Issue462() throws Exception
public void testNestingDepthWithSmallLimit() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = _ioContext(StreamWriteConstraints.builder().maxNestingDepth(1).build());
IOContext ioc = TestSupport.testIOContext(StreamWriteConstraints
.builder().maxNestingDepth(1).build());
try (JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, 0, bytes,
JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null,
0, '"')) {
Expand All @@ -66,7 +66,8 @@ public void testNestingDepthWithSmallLimit() throws Exception
public void testNestingDepthWithSmallLimitNestedObject() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = _ioContext(StreamWriteConstraints.builder().maxNestingDepth(1).build());
IOContext ioc = TestSupport.testIOContext(StreamWriteConstraints.builder()
.maxNestingDepth(1).build());
try (JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, 0, bytes,
JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null,
0, '"')) {
Expand Down Expand Up @@ -139,24 +140,15 @@ public void testFilteringWithEscapedChars() throws Exception
gen.writeEndObject();
gen.close();

JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toByteArray());

assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("escapes", p.currentName());

assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(SAMPLE_WITH_QUOTES, p.getText());
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertNull(p.nextToken());
p.close();
}

private IOContext _ioContext(StreamWriteConstraints swc) {
return new IOContext(StreamReadConstraints.defaults(),
swc,
ErrorReportConfiguration.defaults(),
new BufferRecycler(),
ContentReference.unknown(), true, JsonEncoding.UTF8);
try (JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toByteArray())) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("escapes", p.currentName());

assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(SAMPLE_WITH_QUOTES, p.getText());
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertNull(p.nextToken());
}
}
}

0 comments on commit 3d73290

Please sign in to comment.