Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 27, 2023
1 parent ae170b2 commit 8f7c9b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.junit.Assert;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.util.BufferRecycler;
import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper;

public abstract class BaseTestForSmile
Expand Down Expand Up @@ -149,6 +151,16 @@ protected SmileGenerator smileGenerator(SmileFactory f,
return f.createGenerator(result, null);
}

/**
* 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);
}

/*
/**********************************************************
/* Additional assertion methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.io.InputStream;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream;

Expand Down Expand Up @@ -74,9 +71,7 @@ private void _verifyVIntBad(byte[] doc, String... msgs) throws Exception
}

private SmileParser _minimalParser(byte[] doc) {
IOContext ctxt = new IOContext(StreamReadConstraints.defaults(),
null, ContentReference.rawReference(doc), false);
return new SmileParser(ctxt, // IOContext
return new SmileParser(testIOContext(),
0, 0, // flags
null, // (codec)
ROOT_SYMBOLS.makeChild(0), // ByteQuadsCanonicalizer
Expand All @@ -85,9 +80,7 @@ private SmileParser _minimalParser(byte[] doc) {
}

private SmileParser _minimalParser(InputStream in) {
IOContext ctxt = new IOContext(StreamReadConstraints.defaults(),
null, ContentReference.rawReference(in), false);
return new SmileParser(ctxt, // IOContext
return new SmileParser(testIOContext(),
0, 0, // flags
null, // (codec)
ROOT_SYMBOLS.makeChild(0), // ByteQuadsCanonicalizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ public void testFallbackWriteAsJson() throws Exception
assertEquals("[]", w.toString());
}

// There is one constructor designed for direct generator instantiation,
// not used by factory; need to ensure it does not fail spectacularly
public void testGeneratorConstruction() throws Exception
{
SmileFactory f = new SmileFactory();
IOContext ctxt = new IOContext(StreamReadConstraints.defaults(),
f._getBufferRecycler(),
ContentReference.rawReference("doc"), false);
OutputStream bytes = new ByteArrayOutputStream();
byte[] buf = new byte[1000];
SmileGenerator g = new SmileGenerator(ctxt, 0, 0,
null, bytes, buf, 0, false);
g.writeStartArray();
g.writeEndArray();
g.close();
}

public void testCanonicalization() throws Exception
{
try (NonBlockingByteArrayParser parser = new SmileFactory()
Expand Down

0 comments on commit 8f7c9b9

Please sign in to comment.