Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 19, 2025
2 parents 274c59e + 4ff30d6 commit bf07124
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import java.io.*;
import java.util.Arrays;

import junit.framework.TestCase;

import tools.jackson.core.*;
import tools.jackson.core.json.JsonFactory;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

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

public abstract class BaseTest
extends TestCase
{
/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package tools.jackson.module.mrbean;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.*;

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

public class RoundTripTest extends BaseTest
{
public interface Bean {
Expand All @@ -14,6 +18,7 @@ public interface ReadOnlyBean {
}

// [mrbean#20]: naming convention caused under-score prefixed duplicates
@Test
public void testSimple() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -24,6 +29,7 @@ public void testSimple() throws Exception
assertEquals(input, output);
}

@Test
public void testSimpleWithoutSetter() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package tools.jackson.module.mrbean;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;

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

public class TestAbstractClasses
extends BaseTest
{
Expand Down Expand Up @@ -34,6 +38,7 @@ protected Bean() { }
*/

@SuppressWarnings("synthetic-access")
@Test
public void testSimpleInteface() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package tools.jackson.module.mrbean;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.exc.InvalidDefinitionException;
import tools.jackson.databind.json.JsonMapper;

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

public class TestAbstractClassesWithOverrides
extends BaseTest
{
Expand Down Expand Up @@ -75,6 +79,7 @@ public abstract static class CoffeeBeanLackingPublicMethod extends CoffeeBean
/**********************************************************
*/

@Test
public void testOverrides() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -86,6 +91,7 @@ public void testOverrides() throws Exception
}

@SuppressWarnings("synthetic-access")
@Test
public void testReAbstractedMethods() throws Exception
{
AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
Expand Down Expand Up @@ -133,6 +139,7 @@ private void verifyReAbstractedProperty(ObjectMapper mapper) throws Exception {
assertEquals("Another Foo!", beanWithOtherFoo.getFoo());
}

@Test
public void testEagerFailureOnReAbstractedMethods() throws Exception
{
AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
Expand All @@ -22,6 +23,8 @@
import tools.jackson.databind.ObjectMapper;
import tools.jackson.module.mrbean.AbstractTypeMaterializer.MyClassLoader;

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

// [modules-base#110]: avoid synthetic bridge method generation
public class TestBridgeMethods extends BaseTest
{
Expand Down Expand Up @@ -52,6 +55,7 @@ public interface SpecificCoffeeHolder extends GenericHolder<Coffee> {
Coffee getObject();
}

@Test
public void testSimpleCovariantProperty() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -64,6 +68,7 @@ public void testSimpleCovariantProperty() throws Exception
assertEquals("pumpkin spice", result.getDrink().getFlavor());
}

@Test
public void testGenericCovariantProperty() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import tools.jackson.databind.*;

import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;

// test for [modules-base#52]
public class TestDefaultMethods
Expand All @@ -19,7 +19,7 @@ default long id() {
}
}

public void testMaterializedDefaultMethod() throws IOException {
public void testMaterializedDefaultMethod() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

// Main thing is that we should not get an exception for missing method,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package tools.jackson.module.mrbean;

import java.util.List;

import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.List;

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

public class TestEqualsAndHashCode extends BaseTest {

Expand Down Expand Up @@ -42,7 +41,7 @@ public static interface GenericBean<T> {
}


public void testReadOnlyBeanSameNonNullInput() throws IOException {
public void testReadOnlyBeanSameNonNullInput() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

final String input = "{\"field\":\"testing\"}";
Expand All @@ -53,7 +52,7 @@ public void testReadOnlyBeanSameNonNullInput() throws IOException {
assertEqualsAndHashCode(bean1, bean2);
}

public void testReadOnlyBeanSameNullInput() throws IOException {
public void testReadOnlyBeanSameNullInput() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

final String input = "{\"field\":null}";
Expand All @@ -64,7 +63,7 @@ public void testReadOnlyBeanSameNullInput() throws IOException {
assertEqualsAndHashCode(bean1, bean2);
}

public void testReadOnlyBeanDifferentInput() throws IOException {
public void testReadOnlyBeanDifferentInput() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

final String input1 = "{\"field\":\"testing\"}";
Expand All @@ -76,7 +75,7 @@ public void testReadOnlyBeanDifferentInput() throws IOException {
assertNeitherEqualsNorHashCode(bean1, bean2);
}

public void testGenericBeanSameInput() throws IOException {
public void testGenericBeanSameInput() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

final String input = "{\"someData\":[{\"leaves\":[{\"value\":\"foo\"}] },{\"leaves\":[{\"value\":\"foo\"}] }]}";
Expand All @@ -87,7 +86,7 @@ public void testGenericBeanSameInput() throws IOException {
assertEqualsAndHashCode(bean1, bean2);
}

public void testGenericBeanDifferentInput() throws IOException {
public void testGenericBeanDifferentInput() throws Exception {
final ObjectMapper mapper = newMrBeanMapper();

final String input1 = "{\"someData\":[{\"leaves\":[{\"value\":\"foo\"}] },{\"leaves\":[{\"value\":\"foo\"}] }]}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package tools.jackson.module.mrbean;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.jupiter.api.Test;

import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.*;

public class TestGenericTypes
extends BaseTest
Expand Down Expand Up @@ -37,6 +41,7 @@ public interface InterfaceWithReference8 {
/**
* Test simple leaf-level bean with 2 implied _beanProperties
*/
@Test
public void testSimpleInterface() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -50,6 +55,7 @@ public void testSimpleInterface() throws Exception
assertEquals("foo", leaves.get(0).value);
}

@Test
public void testGenericInterface() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -67,6 +73,7 @@ public void testGenericInterface() throws Exception
}
}

@Test
public void testGenericClass() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -85,6 +92,7 @@ public void testGenericClass() throws Exception
}

// for [mrbean#8]
@Test
public void testWithGenericReferenceType() throws Exception
{
ObjectMapper mapper = newMrBeanMapper();
Expand Down
11 changes: 11 additions & 0 deletions mrbean/src/test/java/tools/jackson/module/mrbean/TestJDKTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import java.io.Serializable;
import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonFormat;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.annotation.JsonSerialize;
import tools.jackson.databind.ser.std.ToStringSerializer;

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

/**
* Tests stemming from [#12], where `Calendar` fails; however, bit more general
* problem.
Expand All @@ -27,6 +31,7 @@ static class Bean117UsingJsonSerialize {
private final ObjectMapper MAPPER = newMrBeanMapper();
private final ObjectMapper VANILLA_MAPPER = newPlainJsonMapper();

@Test
public void testDateTimeTypes() throws Exception
{
Calendar cal = MAPPER.readValue("0", Calendar.class);
Expand All @@ -38,6 +43,7 @@ public void testDateTimeTypes() throws Exception
assertEquals(0L, dt.getTime());
}

@Test
public void testNumbers() throws Exception
{
Number nr = MAPPER.readValue("0", Number.class);
Expand All @@ -49,6 +55,7 @@ public void testNumbers() throws Exception
assertSame(Double.class, nr.getClass());
}

@Test
public void testIterable() throws Exception
{
Object ob = MAPPER.readValue("[ ]", Iterable.class);
Expand All @@ -63,13 +70,15 @@ public void testIterable() throws Exception
assertEquals(Integer.valueOf(123), l.get(0));
}

@Test
public void testStringLike() throws Exception
{
CharSequence seq = MAPPER.readValue(q("abc"), CharSequence.class);
assertEquals("abc", (String) seq);
}

// [modules-base#74]: more types to skip
@Test
public void testSerializable() throws Exception
{
// Serializable value = MAPPER.readValue(quote("abc"), Serializable.class);
Expand All @@ -78,6 +87,7 @@ public void testSerializable() throws Exception
}

// Extra test inspired by Afterburner report
@Test
public void testIntAsString() throws Exception
{
final String EXP_JSON = "{\"value\":\"42\"}";
Expand All @@ -92,6 +102,7 @@ public void testIntAsString() throws Exception
}

// [modules-base#132]: Don't block "java.util.TimeZone"
@Test
public void testUtilTimeZone() throws Exception
{
final String json = q("PST");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

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

public class TestMapStringObjectDeserialization
extends BaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.util.List;

import org.junit.jupiter.api.Test;

import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.*;

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

/**
* Tests to verify whether generic declarations are properly handled by Mr Bean.
*/
Expand All @@ -29,6 +33,7 @@ public interface Dog {
/**********************************************************
*/

@Test
public void testTypeReferenceNestedGeneric() throws Exception
{
final ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -40,6 +45,7 @@ public void testTypeReferenceNestedGeneric() throws Exception
assertTrue(ob instanceof Dog);
}

@Test
public void testTypeReferenceNestedGenericList() throws Exception
{
final ObjectMapper mapper = newMrBeanMapper();
Expand All @@ -50,6 +56,6 @@ public void testTypeReferenceNestedGenericList() throws Exception
List<?> records = result.getRecords();
assertEquals(1, records.size());
Object ob = records.get(0);
assertTrue("Actual type: "+ob.getClass(), ob instanceof Dog);
assertTrue(ob instanceof Dog, "Actual type: "+ob.getClass());
}
}
Loading

0 comments on commit bf07124

Please sign in to comment.