Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ JSTEP-10 ] Migrate cbor module tests to JUnit 5 #550

Merged
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
Expand Up @@ -6,8 +6,8 @@
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.io.IOContext;

/**
* Factory used for constructing {@link CBORParser} and {@link CBORGenerator}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.fasterxml.jackson.dataformat.cbor;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;

import com.fasterxml.jackson.core.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.*;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.json.DupDetector;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.core.util.TextBuffer;
import com.fasterxml.jackson.core.util.*;

import static com.fasterxml.jackson.dataformat.cbor.CBORConstants.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.fasterxml.jackson.dataformat.cbor;

import java.io.*;
import java.io.IOException;
import java.io.InputStream;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
import com.fasterxml.jackson.core.io.IOContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.Version;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.MapperBuilder;

import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.dataformat.cbor.CBORGenerator;
import com.fasterxml.jackson.dataformat.cbor.PackageVersion;
import com.fasterxml.jackson.dataformat.cbor.*;

/**
* Specialized {@link ObjectMapper} to use with CBOR format backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.io.ByteArrayOutputStream;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.ObjectMapper;

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

// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload
public class BrokenLongBinary186Test extends CBORTestBase
{
Expand All @@ -20,12 +22,14 @@ public class BrokenLongBinary186Test extends CBORTestBase
*/

// [dataformats-binary#186]
@Test
public void testCorruptVeryLongBinary() throws Exception {
// Let's do about 2 GB to likely trigger failure
_testCorruptLong(1_999_999_999, 95000);
}

// [dataformats-binary#186]
@Test
public void testCorruptQuiteLongBinary() throws Exception {
// Value below limit for chunked handling
_testCorruptLong(CBORParser.LONGEST_NON_CHUNKED_BINARY >> 1, 37);
Expand All @@ -51,6 +55,7 @@ private void _testCorruptLong(int allegedLength, int actualIncluded) throws Exce
*/

// [dataformats-binary#186]
@Test
public void testQuiteLongStreaming() throws Exception
{
// Can try bit shorter here, like 500 megs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;

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

/**
* Miscellaneous tests for {@link CBORFactory}, and for some aspects
Expand All @@ -16,6 +18,7 @@ public class CBORFactoryPropertiesTest extends CBORTestBase

private final static CBORFactory CBOR_F = new CBORFactory();

@Test
public void testCBORFactorySerializable() throws Exception
{
CBORFactory f = new CBORFactory();
Expand All @@ -30,6 +33,7 @@ public void testCBORFactorySerializable() throws Exception
assertArrayEquals(doc, docOut);
}

@Test
public void testCBORFactoryCopy() throws Exception
{
CBORFactory f2 = CBOR_F.copy();
Expand All @@ -39,6 +43,7 @@ public void testCBORFactoryCopy() throws Exception
assertNotNull(doc);
}

@Test
public void testVersions() throws Exception
{
CBORFactory f = CBOR_F;
Expand All @@ -55,6 +60,7 @@ public void testVersions() throws Exception
p.close();
}

@Test
public void testCapabilities() throws Exception
{
assertTrue(CBOR_F.canHandleBinaryNatively());
Expand All @@ -63,6 +69,7 @@ public void testCapabilities() throws Exception
assertEquals(CBORGenerator.Feature.class, CBOR_F.getFormatWriteFeatureType());
}

@Test
public void testInabilityToReadChars() throws Exception
{
final String EXP = "non-byte-based source";
Expand All @@ -86,6 +93,7 @@ public void testInabilityToReadChars() throws Exception
}
}

@Test
public void testInabilityToWriteChars() throws Exception
{
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.fasterxml.jackson.dataformat.cbor;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Random;

import org.junit.Assert;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper;

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

public abstract class CBORTestBase
extends junit.framework.TestCase
{
/*
/**********************************************************
Expand Down Expand Up @@ -161,22 +158,22 @@ protected void verifyException(Throwable e, String... matches)
}

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

protected void _verifyBytes(byte[] actBytes, byte exp1, byte[] expRest) {
byte[] expBytes = new byte[expRest.length+1];
System.arraycopy(expRest, 0, expBytes, 1, expRest.length);
expBytes[0] = exp1;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte[] expRest) {
byte[] expBytes = new byte[expRest.length+2];
System.arraycopy(expRest, 0, expBytes, 2, expRest.length);
expBytes[0] = exp1;
expBytes[1] = exp2;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, byte[] expRest) {
Expand All @@ -185,7 +182,7 @@ protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, by
expBytes[0] = exp1;
expBytes[1] = exp2;
expBytes[2] = exp3;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

/**
Expand All @@ -204,7 +201,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
Expand Up @@ -3,13 +3,15 @@
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 CBORTestBase
{
// 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.cbor;

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 CBORTestBase
{
private final ObjectMapper MAPPER = cborMapper();

@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
@@ -1,11 +1,16 @@
package com.fasterxml.jackson.dataformat.cbor;

import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;

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

public class GeneratorDeepNestingTest extends CBORTestBase
{
private final ObjectMapper MAPPER = cborMapper();
Expand All @@ -18,6 +23,7 @@ public class GeneratorDeepNestingTest extends CBORTestBase

// for [dataformats-binary#62]
@SuppressWarnings("unchecked")
@Test
public void testDeeplyNestedMap() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down Expand Up @@ -65,6 +71,7 @@ private void _verifyNestedMap(Map<String,?> map, int level) {
}
}

@Test
public void testDeeplyNestedArray() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package com.fasterxml.jackson.dataformat.cbor;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;

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

public class GeneratorDupHandlingTest extends CBORTestBase
{
@Test
public void testSimpleDupsEagerlyBytes() throws Exception {
_testSimpleDups(false, new JsonFactory());
}

// Testing ability to enable checking after construction of
// generator, not just via JsonFactory
@Test
public void testSimpleDupsLazilyBytes() throws Exception {
final JsonFactory f = new JsonFactory();
assertFalse(f.isEnabled(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

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

/**
* Unit tests geared at testing issues that were raised due to
* inter-operability with other CBOR codec implementations
Expand All @@ -16,6 +20,7 @@ public class GeneratorInteropTest extends CBORTestBase
};

// Test for [Issue#6], for optional writing of CBOR Type Description Tag
@Test
public void testTypeDescriptionTag() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand All @@ -28,6 +33,7 @@ public void testTypeDescriptionTag() throws Exception
_verifyBytes(out.toByteArray(), TYPE_DESC_AND_TRUE);
}

@Test
public void testAutoTypeDescription() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonGenerationException;

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

public class GeneratorInvalidCallsTest extends CBORTestBase
{
@Test
public void testInvalidFieldNameInRoot() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Loading