From 81632e0567a0e662118004acf4f403041cf51a9e Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 24 Jun 2024 17:26:17 -0700 Subject: [PATCH] Minor changes to test, move to misc tests package --- ...omAnnotationIntrospectorNoWrapperTest.java | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) rename src/test/java/com/fasterxml/jackson/dataformat/xml/{ => misc}/CustomAnnotationIntrospectorNoWrapperTest.java (58%) diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/CustomAnnotationIntrospectorNoWrapperTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/misc/CustomAnnotationIntrospectorNoWrapperTest.java similarity index 58% rename from src/test/java/com/fasterxml/jackson/dataformat/xml/CustomAnnotationIntrospectorNoWrapperTest.java rename to src/test/java/com/fasterxml/jackson/dataformat/xml/misc/CustomAnnotationIntrospectorNoWrapperTest.java index f27aa3573..a81177c6c 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/CustomAnnotationIntrospectorNoWrapperTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/misc/CustomAnnotationIntrospectorNoWrapperTest.java @@ -1,41 +1,22 @@ -package com.fasterxml.jackson.dataformat.xml; - -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.AnnotationIntrospector; -import com.fasterxml.jackson.databind.PropertyName; -import com.fasterxml.jackson.databind.introspect.Annotated; -import com.fasterxml.jackson.databind.module.SimpleModule; +package com.fasterxml.jackson.dataformat.xml.misc; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; import java.util.List; +import com.fasterxml.jackson.databind.PropertyName; +import com.fasterxml.jackson.databind.introspect.Annotated; +import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; + /** * A regression test for https://github.com/FasterXML/jackson-databind/issues/4595 */ -public class CustomAnnotationIntrospectorNoWrapperTest extends XmlTestBase { - private final XmlMapper MAPPER = newMapper(); - - public void testNoWrapper() throws Exception { - Foo foo = new Foo(Arrays.asList("Value1", "Value2")); - - assertEquals("Value1Value2", MAPPER.writeValueAsString(foo)); - - MAPPER - .registerModule(new SimpleModule("NoWrapperModule") { - @Override - public void setupModule(SetupContext context) { - context.insertAnnotationIntrospector(new NoWrapperIntrospector()); - super.setupModule(context); - } - }); - - // TODO: update after fixing https://github.com/FasterXML/jackson-databind/issues/4595 - // Should be assertEquals("Value1Value2", MAPPER.writeValueAsString(foo)); - assertEquals("Value1Value2", MAPPER.writeValueAsString(foo)); - } - +public class CustomAnnotationIntrospectorNoWrapperTest extends XmlTestBase +{ public static class Foo { private final List bar; @@ -49,11 +30,8 @@ public List getBar() { } } - public static class NoWrapperIntrospector extends AnnotationIntrospector { - @Override - public Version version() { - return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION; - } + public static class NoWrapperIntrospector extends NopAnnotationIntrospector { + private static final long serialVersionUID = 1L; @Override public PropertyName findWrapperName(Annotated ann) { @@ -67,4 +45,30 @@ public PropertyName findWrapperName(Annotated ann) { @Retention(RetentionPolicy.RUNTIME) public @interface NoWrapper { } + + private final XmlMapper VANILLA_MAPPER = newMapper(); + + public void testNoWrapper() throws Exception { + Foo foo = new Foo(Arrays.asList("Value1", "Value2")); + + assertEquals("Value1Value2", + VANILLA_MAPPER.writeValueAsString(foo)); + + XmlMapper customMapper = mapperBuilder() + .addModule(new SimpleModule("NoWrapperModule") { + private static final long serialVersionUID = 1L; + + @Override + public void setupModule(SetupContext context) { + context.insertAnnotationIntrospector(new NoWrapperIntrospector()); + super.setupModule(context); + } + }).build(); + + // After fixing https://github.com/FasterXML/jackson-databind/issues/4595 + assertEquals("Value1Value2", customMapper.writeValueAsString(foo)); + + // before fix had: + //assertEquals("Value1Value2", customMapper.writeValueAsString(foo)); + } }