Skip to content

Commit

Permalink
[ JSTEP-10 ] Migrate smile module tests to JUnit 5 (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Jan 14, 2025
1 parent 697797b commit ec58aab
Show file tree
Hide file tree
Showing 81 changed files with 690 additions and 260 deletions.
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;

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

0 comments on commit ec58aab

Please sign in to comment.