Skip to content

Commit

Permalink
Unit test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 26, 2023
1 parent 9b666b2 commit 3e1cbb9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ public static IOContext testIOContext() {
ErrorReportConfiguration.defaults());
}

/**
* Factory method for creating {@link IOContext}s for tests
*/
public static IOContext testIOContext(StreamReadConstraints src) {
return testIOContext(src,
StreamWriteConstraints.defaults(),
ErrorReportConfiguration.defaults());
}

/**
* Factory method for creating {@link IOContext}s for tests
*/
public static IOContext testIOContext(StreamWriteConstraints swc) {
return testIOContext(StreamReadConstraints.defaults(),
swc,
ErrorReportConfiguration.defaults());
}

private static IOContext testIOContext(StreamReadConstraints src,
StreamWriteConstraints swc,
ErrorReportConfiguration erc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.json.UTF8JsonGenerator;
import com.fasterxml.jackson.core.testsupport.TestSupport;

public class UTF8GeneratorTest extends BaseTest
{
private final JsonFactory JSON_F = new JsonFactory();

private final JsonFactory JSON_MAX_NESTING_1 = JsonFactory.builder()
.streamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(1).build())
.build();

public void testUtf8Issue462() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Expand Down Expand Up @@ -45,9 +48,7 @@ public void testUtf8Issue462() throws Exception
public void testNestingDepthWithSmallLimit() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = TestSupport.testIOContext(StreamWriteConstraints
.builder().maxNestingDepth(1).build());
try (JsonGenerator gen = new UTF8JsonGenerator(ioc, 0, null, bytes, '"')) {
try (JsonGenerator gen = JSON_MAX_NESTING_1.createGenerator(bytes)) {
gen.writeStartObject();
gen.writeFieldName("array");
gen.writeStartArray();
Expand All @@ -61,9 +62,7 @@ public void testNestingDepthWithSmallLimit() throws Exception
public void testNestingDepthWithSmallLimitNestedObject() throws Exception
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = TestSupport.testIOContext(StreamWriteConstraints.builder()
.maxNestingDepth(1).build());
try (JsonGenerator gen = new UTF8JsonGenerator(ioc, 0, null, bytes, '"')) {
try (JsonGenerator gen = JSON_MAX_NESTING_1.createGenerator(bytes)) {
gen.writeStartObject();
gen.writeFieldName("object");
gen.writeStartObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
import java.io.StringWriter;

import com.fasterxml.jackson.core.BaseTest;
import com.fasterxml.jackson.core.ErrorReportConfiguration;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.StreamWriteConstraints;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.json.WriterBasedJsonGenerator;
import com.fasterxml.jackson.core.util.BufferRecycler;

public class WriterBasedJsonGeneratorTest extends BaseTest
{
private final JsonFactory JSON_MAX_NESTING_1 = JsonFactory.builder()
.streamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(1).build())
.build();

public void testNestingDepthWithSmallLimit() throws Exception
{
StringWriter sw = new StringWriter();
IOContext ioc = _ioContext(StreamWriteConstraints.builder().maxNestingDepth(1).build());
try (JsonGenerator gen = new WriterBasedJsonGenerator(ioc, 0, null, sw, '"')) {
try (JsonGenerator gen = JSON_MAX_NESTING_1.createGenerator(sw)) {
gen.writeStartObject();
gen.writeFieldName("array");
gen.writeStartArray();
Expand All @@ -33,8 +31,7 @@ public void testNestingDepthWithSmallLimit() throws Exception
public void testNestingDepthWithSmallLimitNestedObject() throws Exception
{
StringWriter sw = new StringWriter();
IOContext ioc = _ioContext(StreamWriteConstraints.builder().maxNestingDepth(1).build());
try (JsonGenerator gen = new WriterBasedJsonGenerator(ioc, 0, null, sw, '"')) {
try (JsonGenerator gen = JSON_MAX_NESTING_1.createGenerator(sw)) {
gen.writeStartObject();
gen.writeFieldName("object");
gen.writeStartObject();
Expand All @@ -44,12 +41,4 @@ public void testNestingDepthWithSmallLimitNestedObject() throws Exception
assertEquals(expected, sce.getMessage());
}
}

private IOContext _ioContext(StreamWriteConstraints swc) {
return new IOContext(StreamReadConstraints.defaults(),
swc,
ErrorReportConfiguration.defaults(),
new BufferRecycler(),
ContentReference.unknown(), true);
}
}

0 comments on commit 3e1cbb9

Please sign in to comment.