Skip to content

Commit

Permalink
Continue JUnit5 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 11, 2024
1 parent ca81a1f commit 6396f80
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package com.fasterxml.jackson.core;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.json.*;
import com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer;
import com.fasterxml.jackson.core.testsupport.TestSupport;

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

/**
* Tests to verify functioning of {@link Version} class.
*/
public class TestVersions extends com.fasterxml.jackson.core.BaseTest
public class ComponentVersionsTest
extends JUnit5TestBase
{
@Test
public void testCoreVersions() throws Exception
{
final JsonFactory f = new JsonFactory();
assertVersion(f.version());
try (ReaderBasedJsonParser p = new ReaderBasedJsonParser(testIOContext(), 0, null, null,
try (ReaderBasedJsonParser p = new ReaderBasedJsonParser(TestSupport.testIOContext(), 0, null, null,
CharsToNameCanonicalizer.createRoot(f))) {
assertVersion(p.version());
}
try (JsonGenerator g = new WriterBasedJsonGenerator(testIOContext(), 0, null, null, '"')) {
try (JsonGenerator g = new WriterBasedJsonGenerator(TestSupport.testIOContext(), 0, null, null, '"')) {
assertVersion(g.version());
}
}

@Test
public void testEquality() {
Version unk = Version.unknownVersion();
assertEquals("0.0.0", unk.toString());
Expand All @@ -37,6 +46,7 @@ public void testEquality() {
assertEquals(unk, unk2);
}

@Test
public void testMisc() {
Version unk = Version.unknownVersion();
int hash = unk.hashCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.fasterxml.jackson.core;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.io.ContentReference;

import static org.assertj.core.api.Assertions.assertThat;

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

import org.junit.jupiter.api.Test;

/**
* Unit tests for class {@link ErrorReportConfiguration}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import java.io.StringWriter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.core.io.JsonEOFException;

public class TestExceptions extends BaseTest
import static org.junit.jupiter.api.Assertions.*;

public class ExceptionsTest
extends JUnit5TestBase
{
private final JsonFactory JSON_F = newStreamFactory();

// For [core#10]
@Test
public void testOriginalMesssage()
{
JsonProcessingException exc = new JsonParseException(null, "Foobar", JsonLocation.NA);
Expand All @@ -34,6 +40,7 @@ public void testOriginalMesssage()
}

// [core#198]
@Test
public void testAccessToParser() throws Exception
{
JsonParser p = JSON_F.createParser("{}");
Expand All @@ -49,6 +56,7 @@ public void testAccessToParser() throws Exception
}

// [core#198]
@Test
public void testAccessToGenerator() throws Exception
{
StringWriter w = new StringWriter();
Expand All @@ -61,18 +69,20 @@ public void testAccessToGenerator() throws Exception
}

// [core#281]: new eof exception
@Test
public void testEofExceptionsBytes() throws Exception {
_testEofExceptions(MODE_INPUT_STREAM);
}

// [core#281]: new eof exception
@Test
public void testEofExceptionsChars() throws Exception {
_testEofExceptions(MODE_READER);
}

private void _testEofExceptions(int mode) throws Exception
{
JsonParser p = createParser(mode, "[ ");
JsonParser p = createParser(JSON_F, mode, "[ ");
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
Expand All @@ -82,7 +92,7 @@ private void _testEofExceptions(int mode) throws Exception
}
p.close();

p = createParser(mode, "{ \"foo\" : [ ] ");
p = createParser(JSON_F, mode, "{ \"foo\" : [ ] ");
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertToken(JsonToken.START_ARRAY, p.nextToken());
Expand All @@ -95,7 +105,7 @@ private void _testEofExceptions(int mode) throws Exception
}
p.close();

p = createParser(mode, "{ \"fo");
p = createParser(JSON_F, mode, "{ \"fo");
assertToken(JsonToken.START_OBJECT, p.nextToken());
try {
p.nextToken();
Expand All @@ -107,7 +117,7 @@ private void _testEofExceptions(int mode) throws Exception
}
p.close();

p = createParser(mode, "{ \"field\" : ");
p = createParser(JSON_F, mode, "{ \"field\" : ");
assertToken(JsonToken.START_OBJECT, p.nextToken());
try {
p.nextToken();
Expand All @@ -121,6 +131,7 @@ private void _testEofExceptions(int mode) throws Exception
// any other cases we'd like to test?
}

@Test
public void testContentSnippetWithOffset() throws Exception
{
final JsonFactory jsonF = streamFactoryBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.util.RecyclerPool;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.JsonRecyclerPools;

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

/**
* Unit tests for [core#31] (https://github.com/FasterXML/jackson-core/issues/31)
*/
public class JDKSerializabilityTest extends BaseTest
public class JDKSerializabilityTest
extends JUnit5TestBase
{
/*
/**********************************************************************
/* Main factory type(s)
/**********************************************************************
*/

@Test
public void testJsonFactorySerializable() throws Exception
{
JsonFactory f = new JsonFactory();
Expand All @@ -40,6 +46,7 @@ public void testJsonFactorySerializable() throws Exception
/**********************************************************************
*/

@Test
public void testBase64Variant() throws Exception
{
{
Expand Down Expand Up @@ -71,6 +78,7 @@ public void testBase64Variant() throws Exception
}
}

@Test
public void testPrettyPrinter() throws Exception
{
PrettyPrinter p = new DefaultPrettyPrinter();
Expand All @@ -80,6 +88,7 @@ public void testPrettyPrinter() throws Exception
assertNotNull(back);
}

@Test
public void testLocation() throws Exception
{
JsonFactory jf = new JsonFactory();
Expand All @@ -96,6 +105,7 @@ public void testLocation() throws Exception
jp.close();
}

@Test
public void testSourceReference() throws Exception
{
ContentReference ref = ContentReference.construct(true, "text",
Expand All @@ -113,6 +123,7 @@ public void testSourceReference() throws Exception
/**********************************************************************
*/

@Test
public void testRecyclerPools() throws Exception
{
// First: shared/global pools that will always remain/become globally
Expand Down Expand Up @@ -156,6 +167,7 @@ private <T extends RecyclerPool<?>> T _testRecyclerPoolNonShared(T pool) throws
/**********************************************************************
*/

@Test
public void testParseException() throws Exception
{
JsonFactory jf = new JsonFactory();
Expand All @@ -174,6 +186,7 @@ public void testParseException() throws Exception
assertNotNull(result);
}

@Test
public void testGenerationException() throws Exception
{
JsonFactory jf = new JsonFactory();
Expand All @@ -198,6 +211,7 @@ public void testGenerationException() throws Exception
/**********************************************************************
*/

@Test
public void testPointerSerializationNonEmpty() throws Exception
{
// First, see that we can write and read a general JsonPointer
Expand Down Expand Up @@ -228,14 +242,15 @@ public void testPointerSerializationNonEmpty() throws Exception
assertEquals(leaf.hashCode(), copy.hashCode());
}

@Test
public void testPointerSerializationEmpty() throws Exception
{
// and then verify that "empty" instance gets canonicalized
final JsonPointer emptyP = JsonPointer.empty();
byte[] ser = jdkSerialize(emptyP);
JsonPointer result = jdkDeserialize(ser);
assertSame("Should get same 'empty' instance when JDK serialize+deserialize",
emptyP, result);
assertSame(emptyP, result,
"Should get same 'empty' instance when JDK serialize+deserialize");
}

/*
Expand Down
Loading

0 comments on commit 6396f80

Please sign in to comment.