Skip to content
New issue

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

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

Already on GitHub? # to your account

Update to JUnit5 [JSTEP-10] #186

Merged
merged 8 commits into from
Feb 1, 2025
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 @@ -4,9 +4,9 @@

import com.fasterxml.jackson.jr.ob.JSON;

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

public abstract class ASTestBase extends TestCase
public abstract class ASTestBase
{
protected static class NameBean {
protected String first, last;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.fasterxml.jackson.jr.annotationsupport;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.jr.ob.JSON;

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

public class BasicAliasTest extends ASTestBase
{
static class AliasedName {
Expand Down Expand Up @@ -39,6 +44,7 @@ public String getMiddle() {
private final JSON JSON_WITH_ANNO = jsonWithAnnotationSupport()
.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY);

@Test
public void testSimpleAliases() throws Exception
{
final String input = a2q("{ 'fn':'Billy', 'middleName':'Bob', 'lastName':'Burger' }");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.fasterxml.jackson.jr.annotationsupport;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.jr.ob.JSON;

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

public class BasicIgnoralTest extends ASTestBase
{
static class XY {
Expand Down Expand Up @@ -54,6 +58,7 @@ public XYZ(int x, int y, int z) {
/**********************************************************************
*/

@Test
public void testPropertyIgnoralOnSerialize() throws Exception
{
final XY input = new XY(1, 2);
Expand All @@ -71,6 +76,7 @@ public void testPropertyIgnoralOnSerialize() throws Exception
assertEquals(a2q("{'DEFAULT':123,'y':2}"), JSON_WITH_ANNO_WITH_STATIC.asString(input));
}

@Test
public void testPropertyIgnoralOnDeserialize() throws Exception
{
final String json = a2q("{'DEFAULT':125,'x':1,'y':2}");
Expand Down Expand Up @@ -102,6 +108,7 @@ public void testPropertyIgnoralOnDeserialize() throws Exception
XY.DEFAULT = XY.DEFAULT_FINAL;
}

@Test
public void testPropertyIgnoreWithUnknown() throws Exception
{
final JSON jsonNoUnknowns = JSON_WITH_ANNO.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY);
Expand All @@ -117,12 +124,14 @@ public void testPropertyIgnoreWithUnknown() throws Exception
/**********************************************************************
*/

@Test
public void testClassIgnoralOnSerialize() throws Exception
{
final XYZ input = new XYZ(1, 2, 3);
assertEquals(a2q("{'x':1,'z':3}"), JSON_WITH_ANNO.asString(input));
}

@Test
public void testClassIgnoralOnDeserialize() throws Exception
{
// First, regular ignoral (with skipped unknowns)
Expand All @@ -132,6 +141,7 @@ public void testClassIgnoralOnDeserialize() throws Exception
assertEquals(3, result.z);
}

@Test
public void testClassIgnoralOnDeserializeWithUnknown() throws Exception
{
final JSON jsonNoUnknowns = JSON_WITH_ANNO.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.fasterxml.jackson.jr.annotationsupport;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.ob.JSONObjectException;

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

public class BasicRenameTest extends ASTestBase
{
static class NameSimple {
Expand Down Expand Up @@ -123,6 +128,7 @@ public static SubclassingEnum from(String id) {
private final JSON JSON_WITH_ANNO = jsonWithAnnotationSupport()
.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY);

@Test
public void testBasicRenameOnSerialize() throws Exception
{
final NameSimple input = new NameSimple("Bob", "Burger");
Expand All @@ -136,6 +142,7 @@ public void testBasicRenameOnSerialize() throws Exception
assertEquals(a2q("{'_first':'Bob','_last':'Burger'}"), JSON.std.asString(input));
}

@Test
public void testBasicRenameOnDeserialize() throws Exception
{
final String json = a2q("{'firstName':'Bob','_last':'Burger'}");
Expand All @@ -153,6 +160,7 @@ public void testBasicRenameOnDeserialize() throws Exception
assertEquals("Burger", result._last);
}

@Test
public void testEnumRenameOnSerialize() throws Exception
{
ABCRename inputA = ABCRename.A;
Expand All @@ -174,6 +182,7 @@ public void testEnumRenameOnSerialize() throws Exception
assertEquals(a2q("\"C\""), JSON_WITH_ANNO.asString(inputC));
}

@Test
public void testEnumRenameOnDeserialize() throws Exception
{
String jsonA = a2q("\"A1\"");
Expand All @@ -189,6 +198,7 @@ public void testEnumRenameOnDeserialize() throws Exception
assertEquals(ABCRename.C, resultC);
}

@Test
public void testJsonValueCreatorEnumRenameOnSerialize() throws Exception
{
ABCJsonValueJsonCreator inputA = ABCJsonValueJsonCreator.A;
Expand All @@ -210,6 +220,7 @@ public void testJsonValueCreatorEnumRenameOnSerialize() throws Exception
assertEquals(a2q("\"C\""), JSON_WITH_ANNO.asString(inputC));
}

@Test
public void testJsonValueCreatorEnumRenameOnDeserialize() throws Exception
{
String jsonA = a2q("\"A1\"");
Expand All @@ -225,6 +236,7 @@ public void testJsonValueCreatorEnumRenameOnDeserialize() throws Exception
assertEquals(ABCJsonValueJsonCreator.C, resultC);
}

@Test
public void testJsonValueCreatorHierarchicalEnumRenameOnSerialize() throws Exception
{
SubclassingEnum inputA = SubclassingEnum.ENUM_A;
Expand All @@ -240,6 +252,7 @@ public void testJsonValueCreatorHierarchicalEnumRenameOnSerialize() throws Excep
assertEquals(a2q("\"B\""), JSON_WITH_ANNO.asString(inputB));
}

@Test
public void testJsonValueCreatorHierarchicalEnumRenameOnDeserialize() throws Exception
{
String jsonA = a2q("\"A\"");
Expand All @@ -251,6 +264,7 @@ public void testJsonValueCreatorHierarchicalEnumRenameOnDeserialize() throws Exc
assertEquals(SubclassingEnum.ENUM_B, resultB);
}

@Test
public void testJsonValueHidingSubclass() throws Exception
{
SubclassingEnum input = SubclassingEnum.ENUM_NO_JSON_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import com.fasterxml.jackson.jr.ob.JSON;
import org.junit.jupiter.api.Test;

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

public class BasicReorderTest extends ASTestBase
{
Expand Down Expand Up @@ -39,6 +42,7 @@ public FullNameBean(String f, String m, String l) {

private final JSON JSON_WITH_ANNO = jsonWithAnnotationSupport();

@Test
public void testSimpleReorder() throws Exception
{
final OrderedNameBean input = new OrderedNameBean("Bob", "Burger");
Expand All @@ -54,6 +58,7 @@ public void testSimpleReorder() throws Exception
assertEquals(EXP_DEFAULT, JSON.std.asString(input));
}

@Test
public void testPartialReorder() throws Exception
{
final FullNameBean input = new FullNameBean("Bob", "DeLorean", "Burger");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.fasterxml.jackson.jr.annotationsupport;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.jr.ob.JSON;

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

public class BasicVisibilityTest extends ASTestBase
{
static class FieldXYZ {
Expand Down Expand Up @@ -120,6 +124,7 @@ public MethodXYEnabledWithAnnotations(int x, int y, boolean enabled) {
/**********************************************************************
*/

@Test
public void testSimpleSerializeFieldVisibility() throws Exception
{
final FieldXYZ input = new FieldXYZ(1, 2, 3);
Expand All @@ -143,6 +148,7 @@ public void testSimpleSerializeFieldVisibility() throws Exception
}

// Test to ensure we will not attempt deserializing transient fields
@Test
public void testSimpleSerializeWrtTransient() throws Exception
{
final FieldXYTransient input = new FieldXYTransient(1, 2);
Expand All @@ -157,6 +163,7 @@ public void testSimpleSerializeWrtTransient() throws Exception
.asString(input));
}

@Test
public void testSimpleDeserializeFieldVisibility() throws Exception
{
final String input = a2q("{'x':1,'y':2,'z':3}");
Expand All @@ -181,6 +188,7 @@ public void testSimpleDeserializeFieldVisibility() throws Exception
}

// Test to ensure we will not attempt deserializing transient fields
@Test
public void testSimpleDeserializeWrtTransient() throws Exception
{
final String input = a2q("{'x':1,'y':2}");
Expand All @@ -203,6 +211,7 @@ public void testSimpleDeserializeWrtTransient() throws Exception
/**********************************************************************
*/

@Test
public void testSimpleGetterVisibility() throws Exception
{
final MethodXYEnabled input = new MethodXYEnabled(1, 2, true);
Expand All @@ -215,6 +224,7 @@ public void testSimpleGetterVisibility() throws Exception
.asString(input));
}

@Test
public void testSimpleGetterWithAnnotationVisibility() throws Exception
{
final MethodXYEnabledWithAnnotations input = new MethodXYEnabledWithAnnotations(1, 2, true);
Expand All @@ -228,6 +238,7 @@ public void testSimpleGetterWithAnnotationVisibility() throws Exception
/**********************************************************************
*/

@Test
public void testSimpleSetterVisibility() throws Exception
{
final String input = a2q("{'enabled':true,'x':1,'y':2}");
Expand All @@ -247,6 +258,7 @@ public void testSimpleSetterVisibility() throws Exception
assertEquals(false, result._enabled);
}

@Test
public void testSimpleSetterWithAnnotationVisibility() throws Exception
{
final String input = a2q("{'enabled':true,'x':1,'y':2}");
Expand Down
3 changes: 1 addition & 2 deletions jr-groovy-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<description>Test Module with Groovy support to test Jackson-Jr</description>
<url>https://github.com/FasterXML/jackson-jr</url>
<properties>
<!-- To Test Latest Java Features Lets use this settings -->
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -42,7 +41,7 @@
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.23</version>
<version>4.0.25</version>
</dependency>
</dependencies>
<configuration>
Expand Down
8 changes: 5 additions & 3 deletions jr-groovy-test/src/test/groovy/GroovyObjectSupportTest.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import com.fasterxml.jackson.jr.ob.JSON
import org.junit.Assert
import org.junit.Test

import org.junit.jupiter.api.Test;

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

/**
* A minor note on running/debugging this test on local, if you are using intellij, please
Expand All @@ -12,7 +14,7 @@ class GroovyObjectSupportTest {
void testSimpleGroovyObject() throws Exception {
def json = JSON.std.asString(new GroovyOb())
def expected = """{"AAAAA_A_Field_Starting_With_Two_Capital_Letters":"XYZ","aDouble":0.0,"aPublicInitializedInteger":56,"aPublicInitializedIntegerObject":1516,"aPublicUninitializedInteger":0,"anInitializedIntegerObject":1112,"anInitializedPublicString":"stringData","anInitializedString":"ABC","anInteger":0,"anIntegerWithValue":12}"""
Assert.assertEquals(json, expected)
assertEquals(json, expected)
}
}

Expand Down
16 changes: 9 additions & 7 deletions jr-groovy-test/src/test/groovy/GroovyRecordsTest.groovy
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import com.fasterxml.jackson.jr.ob.JSON
import org.junit.Assert
import org.junit.Test

import org.junit.jupiter.api.Test;

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

/**
* A minor note on running/debugging this test on local, if you are using intellij, please
* change `<packaging>pom</packaging>` to `<packaging>bundle</packaging>`. this is causing
* some issue with the IDE.
*/
class GroovyRecordsTest {

class GroovyRecordsTest
{
@Test
void testRecord() throws Exception {
/* We need to use this since build (8, ubuntu-20.04), will fail Map.of() was added in Java 9*/
Expand All @@ -17,7 +19,7 @@ class GroovyRecordsTest {

def json = JSON.builder().enable(JSON.Feature.USE_FIELD_MATCHING_GETTERS).build().asString(new Cow("foo", map))
def expected = """{"message":"foo","object":{"foo":"bar"}}"""
Assert.assertEquals(expected, json)
assertEquals(expected, json)
}

@Test
Expand All @@ -29,10 +31,10 @@ class GroovyRecordsTest {
map.put("foo", "bar")

def json = JSON.builder().enable(JSON.Feature.USE_FIELD_MATCHING_GETTERS).build().asString(new SimpleGroovyObject("foo", map))
Assert.assertEquals(expected, json)
assertEquals(expected, json)

def json2 = JSON.builder().enable(JSON.Feature.USE_FIELD_MATCHING_GETTERS).build().asString(new GroovyObjectWithNamedGetters("foo", map))
Assert.assertEquals(expected, json2)
assertEquals(expected, json2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion jr-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ has no other dependencies, and provides additional builder-style content generat
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links combine.children="append">
<link>https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-core/2.17/</link>
<link>https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-core/2.19/</link>
</links>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.ob.TestBase;

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

// for [jackson-jr#21]
public class ReadEnumMap21Test extends TestBase
{
Expand All @@ -24,6 +28,7 @@ public WithEnumMap(DEF key, String value) {
}

// [issue#21]
@Test
public void testMapWithEnumKey() throws Exception
{
WithEnumMap input = new WithEnumMap(DEF.E, "bar");
Expand Down
Loading