Skip to content

Commit

Permalink
Migrate paranamer module to JUnit 5 (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Jan 19, 2025
1 parent f587964 commit fef36bb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
10 changes: 8 additions & 2 deletions paranamer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ to introspect names of constructor (and factory method) parameters.
<version>2.8</version>
</dependency>

<!-- Test dependencies: -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.util.Arrays;

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

public abstract class ModuleTestBase
extends TestCase
{
protected void verifyException(Throwable e, String... matches)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.fasterxml.jackson.module.paranamer;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.fasterxml.jackson.databind.json.JsonMapper;

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

public class SimpleTest extends ModuleTestBase
{
static class CreatorBean
Expand All @@ -27,6 +31,7 @@ public CreatorBean(int age, String name)
/**********************************************************
*/

@Test
public void testSimple() throws Exception
{
final String JSON = "{\"name\":\"Bob\", \"age\":40}";
Expand Down Expand Up @@ -60,6 +65,7 @@ public void testSimple() throws Exception

// Let's test handling of case where parameter names are not found; for example when
// trying to access things for JDK types
@Test
public void testWrapper() throws Exception
{
ObjectMapper mapper = JsonMapper.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.fasterxml.jackson.module.paranamer;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;

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

public class TestCreatorWithNamingStrategy
extends ModuleTestBase
{
Expand All @@ -24,6 +28,7 @@ public CreatorBean(int myAge, String myName)
.registerModule(new ParanamerModule())
.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);

@Test
public void testSimpleConstructor() throws Exception
{
CreatorBean bean = MAPPER.readValue("{ \"MyAge\" : 42, \"MyName\" : \"NotMyRealName\" }", CreatorBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

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

public class TestJDKSerializability extends ModuleTestBase
{
static class Point {
public int x, y;
}

@Test
public void testMapper() throws Exception
{
ObjectMapper mapper = new ObjectMapper().registerModule(new ParanamerModule());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.fasterxml.jackson.module.paranamer.failing;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.module.paranamer.ParanamerModule;
import com.fasterxml.jackson.module.paranamer.ModuleTestBase;

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

public class TestCreatorWithNamingStrategy
extends ModuleTestBase
{
Expand Down Expand Up @@ -36,6 +40,7 @@ public static StaticStringCreatorBean parse(String delimited)
.registerModule(new ParanamerModule())
.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);

@Test
public void testStaticStringCreator() throws Exception
{
StaticStringCreatorBean bean = MAPPER.readValue("\"42|NotMyRealName\"", StaticStringCreatorBean.class);
Expand Down

0 comments on commit fef36bb

Please sign in to comment.