Skip to content

Commit

Permalink
Migrate jakarata-xmlbind module tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim committed Jan 18, 2025
1 parent dbb5df4 commit 446d792
Show file tree
Hide file tree
Showing 40 changed files with 252 additions and 16 deletions.
9 changes: 7 additions & 2 deletions jakarta-xmlbind/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@
</dependency>

<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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;

public abstract class ModuleTestBase
extends junit.framework.TestCase
{
public static class NoCheckSubTypeValidator
extends PolymorphicTypeValidator.Base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

import com.fasterxml.jackson.databind.type.TypeFactory;

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

public class TestVersions extends ModuleTestBase
{
@Test
public void testVersions()
{
assertVersion(new JakartaXmlBindAnnotationIntrospector(TypeFactory.defaultInstance()));
Expand All @@ -21,7 +25,7 @@ public void testVersions()
private void assertVersion(Versioned vers)
{
Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUnknownVersion());
assertFalse(v.isUnknownVersion(), "Should find version information (got "+v+")");
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fasterxml.jackson.module.jakarta.xmlbind.adapters;

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

public class EntryType<K, V>
{
private K key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

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

public class MapAdapter<K, V> extends XmlAdapter<MapType<K, V>, Map<K, V>>
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;

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

public class MapType<K,V>
{
public List<EntryType<K, V>> entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import java.io.*;
import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

/**
* Tests for verifying JAXB adapter handling for {@link java.util.Map}
* types.
Expand Down Expand Up @@ -64,6 +68,7 @@ public Map<String, String> unmarshal(Map<String, String> input)
/**********************************************************
*/

@Test
public void testJacksonAdaptedMapType() throws IOException
{
ObjectContainingAMap obj = new ObjectContainingAMap();
Expand All @@ -83,6 +88,7 @@ public void testJacksonAdaptedMapType() throws IOException
assertEquals("here", map.get("how"));
}

@Test
public void testStringMaps() throws IOException
{
ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

/**
* Unit tests for checking that JAXB type adapters work (to some
* degree, anyway).
Expand Down Expand Up @@ -163,12 +167,14 @@ public IdentityAdapterPropertyBean() { }
/**********************************************************
*/

@Test
public void testSimpleAdapterSerialization() throws Exception
{
Bean bean = new Bean(123L);
assertEquals("{\"value\":\"XXX\"}", getJaxbMapper().writeValueAsString(bean));
}

@Test
public void testSimpleAdapterDeserialization() throws Exception
{
Bean bean = getJaxbMapper().readValue("{\"value\":\"abc\"}", Bean.class);
Expand All @@ -177,6 +183,7 @@ public void testSimpleAdapterDeserialization() throws Exception
}

// [JACKSON-288]
@Test
public void testDateAdapter() throws Exception
{
Bean288 input = new Bean288("test");
Expand All @@ -188,6 +195,7 @@ public void testDateAdapter() throws Exception

// [JACKSON-656]

@Test
public void testJackson656() throws Exception
{
Bean656 bean = new Bean656();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import jakarta.xml.bind.annotation.*;
import jakarta.xml.bind.annotation.adapters.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;
import com.fasterxml.jackson.module.jakarta.xmlbind.introspect.JakartaXmlBindAnnotationIntrospectorTest.KeyValuePair;

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

/**
* Unit tests to check that {@link XmlAdapter}s also work with
* container types (Lists, Maps)
Expand Down Expand Up @@ -113,12 +117,14 @@ public void setValues(List<Date> values) {
/**********************************************************
*/

@Test
public void testAdapterForList() throws Exception
{
Wrapper w = new Wrapper(123L);
assertEquals("{\"values\":[\"XXX\"]}", getJaxbMapper().writeValueAsString(w));
}

@Test
public void testSimpleAdapterDeserialization() throws Exception
{
Wrapper w = getJaxbMapper().readValue("{\"values\":[\"abc\"]}", Wrapper.class);
Expand All @@ -128,12 +134,14 @@ public void testSimpleAdapterDeserialization() throws Exception
assertEquals(29L, w.values.get(0).getTime());
}

@Test
public void testAdapterOnGetterSerialization() throws Exception
{
WrapperWithGetterAndSetter w = new WrapperWithGetterAndSetter(123L);
assertEquals("{\"values\":[\"XXX\"]}", getJaxbMapper().writeValueAsString(w));
}

@Test
public void testAdapterOnGetterDeserialization() throws Exception
{
WrapperWithGetterAndSetter w = getJaxbMapper().readValue("{\"values\":[\"abc\"]}",
Expand All @@ -150,6 +158,7 @@ public void testAdapterOnGetterDeserialization() throws Exception
/**********************************************************
*/

@Test
public void testAdapterForBeanWithMap() throws Exception
{
ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

/**
* Failing unit tests related to Adapter handling.
*/
Expand Down Expand Up @@ -61,6 +65,7 @@ public IdentityAdapterPropertyBean() { }
*/

// [Issue-10]
@Test
public void testIdentityAdapterForClass() throws Exception
{
IdentityAdapterBean input = new IdentityAdapterBean("A");
Expand All @@ -74,6 +79,7 @@ public void testIdentityAdapterForClass() throws Exception
}

// [Issue-10]
@Test
public void testIdentityAdapterForProperty() throws Exception
{
IdentityAdapterPropertyBean input = new IdentityAdapterPropertyBean("B");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
Expand All @@ -11,6 +13,8 @@

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

public class TestUnwrapping extends ModuleTestBase
{
@XmlRootElement
Expand Down Expand Up @@ -53,6 +57,7 @@ public B(String type) {
*/

// not asserting anything
@Test
public void testXmlElementAndXmlElementRefs() throws Exception
{
Bean<A> bean = new Bean<A>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlID;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

// for [modules-base#46]: XmlId semantics can not be supported by Jackson/JAXB-annotation-mapper
public class TestXmlID3 extends ModuleTestBase
{
Expand Down Expand Up @@ -46,6 +50,7 @@ static class HasIDList
public HasID getParent() { return parent; }
}

@Test
public void testIssue46() throws Exception
{
ObjectMapper mapper = getJaxbAndJacksonMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import jakarta.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

/**
* Simple testing to verify that XmlID and XMLIDREF handling works
* to degree we can make it work.
Expand Down Expand Up @@ -56,6 +60,7 @@ public Employee() {
/**********************************************************
*/

@Test
public void testSimpleRefs() throws Exception
{
final ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import jakarta.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.type.TypeReference;

Expand All @@ -14,6 +16,8 @@

import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase;

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

public class TestXmlID2 extends ModuleTestBase
{
@XmlRootElement(name = "department")
Expand Down Expand Up @@ -114,6 +118,7 @@ private List<User> getUserList()
return resultList;
}

@Test
public void testIdWithJacksonRules() throws Exception
{
String expected = "[{\"id\":11,\"username\":\"11\",\"email\":\"[email protected]\","
Expand All @@ -138,6 +143,7 @@ public void testIdWithJacksonRules() throws Exception
assertEquals(Long.valueOf(33), result.get(2).id);
}

@Test
public void testIdWithJaxbRules() throws Exception
{
ObjectMapper mapper = JsonMapper.builder()
Expand Down
Loading

0 comments on commit 446d792

Please sign in to comment.