Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.fasterxml.jackson.dataformat.smile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.util.Arrays;

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;

import static org.junit.jupiter.api.Assertions.*;

public abstract class BaseTestForSmile
extends junit.framework.TestCase
{
// From JSON specification, sample doc...
protected final static int SAMPLE_SPEC_VALUE_WIDTH = 800;
Expand Down Expand Up @@ -210,7 +206,7 @@ protected void verifyException(Throwable e, String... matches)

protected void _verifyBytes(byte[] actBytes, byte... expBytes)
{
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

/**
Expand All @@ -229,7 +225,7 @@ protected String getAndVerifyText(JsonParser p) throws IOException
if (str.length() != actLen) {
fail("Internal problem (p.token == "+p.getCurrentToken()+"): p.getText().length() ['"+str+"'] == "+str.length()+"; p.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same");

return str;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.fasterxml.jackson.dataformat.smile;

import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;

import static org.junit.Assert.assertArrayEquals;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

// for [jackson-core#730]
public class FloatPrecisionTest extends BaseTestForSmile
{
// for [jackson-core#730]
@Test
public void testFloatRoundtrips() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.fasterxml.jackson.dataformat.smile;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.StreamReadCapability;
import com.fasterxml.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class FormatDefaultsTest extends BaseTestForSmile
{
private final ObjectMapper MAPPER = smileMapper();

@Test
public void testParserDefaults() throws Exception
{
try (JsonParser p = MAPPER.createParser(new byte[4])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import java.io.InputStream;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class ParserInternalsTest extends BaseTestForSmile
{
private final ByteQuadsCanonicalizer ROOT_SYMBOLS = ByteQuadsCanonicalizer.createRoot();

@Test
public void testPositiveVIntGoodCases() throws Exception
{
// First, couple of known good cases
Expand All @@ -20,6 +26,7 @@ public void testPositiveVIntGoodCases() throws Exception
});
}

@Test
public void testPositiveVIntOverflows() throws Exception
{
// Bad: ends at 5th, but overflows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.dataformat.smile.async.NonBlockingByteArrayParser;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
* Miscellaneous tests for {@link SmileFactory}, and for some aspects
* of generators and parsers it creates.
*/
public class SmileFactoryPropertiesTest extends BaseTestForSmile
{
private final static String SIMPLE_DOC_AS_JSON = "{\"simple\":[1,true,{}]}";

private final static SmileFactory SMILE_F = new SmileFactory();

@Test
public void testFactoryDefaults() {
SmileFactory f = new SmileFactory();

Expand All @@ -30,6 +30,7 @@ public void testFactoryDefaults() {
f.isEnabled(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES));
}

@Test
public void testFactorySerializable() throws Exception
{
SmileFactory f = new SmileFactory();
Expand All @@ -44,6 +45,7 @@ public void testFactorySerializable() throws Exception
assertArrayEquals(doc, docOut);
}

@Test
public void testFactoryCopy() throws Exception
{
SmileFactory f2 = SMILE_F.copy();
Expand All @@ -53,6 +55,7 @@ public void testFactoryCopy() throws Exception
assertNotNull(doc);
}

@Test
public void testVersions() throws Exception
{
SmileFactory f = SMILE_F;
Expand All @@ -69,6 +72,7 @@ public void testVersions() throws Exception
p.close();
}

@Test
public void testCapabilities() throws Exception
{
assertTrue(SMILE_F.canHandleBinaryNatively());
Expand All @@ -77,6 +81,7 @@ public void testCapabilities() throws Exception
assertEquals(SmileGenerator.Feature.class, SMILE_F.getFormatWriteFeatureType());
}

@Test
public void testInabilityToReadChars() throws Exception
{
final String EXP = "for character-based";
Expand All @@ -100,6 +105,7 @@ public void testInabilityToReadChars() throws Exception
}
}

@Test
public void testInabilityToWriteChars() throws Exception
{
try {
Expand All @@ -112,6 +118,7 @@ public void testInabilityToWriteChars() throws Exception
}

// One lesser known feature is the ability to fall back to using JSON...
@Test
public void testFallbackReadFromJson() throws Exception
{
SmileFactory f = new SmileFactory();
Expand All @@ -122,6 +129,7 @@ public void testFallbackReadFromJson() throws Exception
}

// One lesser known feature is the ability to fall back to using JSON...
@Test
public void testFallbackWriteAsJson() throws Exception
{
SmileFactory f = new SmileFactory();
Expand All @@ -135,6 +143,7 @@ public void testFallbackWriteAsJson() throws Exception
assertEquals("[]", w.toString());
}

@Test
public void testCanonicalization() throws Exception
{
try (NonBlockingByteArrayParser parser = new SmileFactory()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.fasterxml.jackson.dataformat.smile;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SmileUtilTest extends BaseTestForSmile
{
/**
* Verification of helper methods used to handle with zigzag encoding
*/
@Test
public void testZigZagInt()
{
// simple encode
Expand All @@ -26,6 +31,7 @@ public void testZigZagInt()
assertEquals(Integer.MAX_VALUE, SmileUtil.zigzagDecode(SmileUtil.zigzagEncode(Integer.MAX_VALUE)));
}

@Test
public void testZigZagLong()
{
assertEquals(0L, SmileUtil.zigzagEncode(0L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import java.io.IOException;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;

// Tests that have to reside in this package, due to access restrictions
import static org.junit.jupiter.api.Assertions.*;

public class SymbolHandlingTest extends BaseTestForSmile
{
@Test
public void testSymbolTable() throws IOException
{
final String STR1 = "a";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.fasterxml.jackson.dataformat.smile;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Comment on lines +3 to +4
Copy link
Member Author

@JooHyukKim JooHyukKim Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cowtowncoder One thing tho, IntelliJ doesn't provide per-package wildcard handling 🤔 minimum 3 required to use wildcard. But with that trade off, we get to order imports Jackson way that I configured like below (There are more above and below)

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that ideally we'd usually left imports as-is and avoid mechanical changes.

But FWTW, the usual cut-off is 5-or-more, I think. Then again for some packages (java.io, java.util) could use star-include for lower numbers.

I think that order of imports is more important than exact threshold for start includes, if that helps? (i.e. I'd rather have strict(er) ordering than worry about explicit vs star inclusion, if only one can be restricted).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to hear that ordering comes first!
Though I hope merging into master doesn't complicate as much tho


import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.Versioned;

/**
* Tests to verify [JACKSON-278]
*/
import static org.junit.jupiter.api.Assertions.assertEquals;

public class VersionsTest extends BaseTestForSmile
{
@Test
public void testMapperVersions() throws IOException
{
SmileFactory f = new SmileFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package com.fasterxml.jackson.dataformat.smile.async;

import java.io.*;
import java.io.IOException;
import java.util.Random;

import com.fasterxml.jackson.core.*;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;

import static org.junit.jupiter.api.Assertions.*;

public class AsyncParserNamesTest extends AsyncTestBase
{
@Test
public void testLongNames() throws IOException
{
_testWithName(generateName(5000));
}

@Test
public void testEvenLongerName() throws Exception
{
StringBuilder nameBuf = new StringBuilder("longString");
Expand All @@ -25,6 +31,7 @@ public void testEvenLongerName() throws Exception
_testWithName(name);
}

@Test
public void testSymbolTable() throws IOException
{
final String STR1 = "a";
Expand Down
Loading
Loading