Test refactoring
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators1853.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators1853.java
deleted file mode 100644
index d124ea9..0000000
--- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators1853.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.fasterxml.jackson.databind.deser.creators;
-
-import com.fasterxml.jackson.annotation.*;
-
-import com.fasterxml.jackson.databind.*;
-
-// Reproduction for [databind#1853], problem with delegating creator,
-// but only explicit case
-public class TestCreators1853 extends BaseMapTest
-{
- public static class Product {
- String name;
-
- public Object other, errors;
-
- @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public Product(@JsonProperty("name") String name) {
- this.name = "PROP:" + name;
- }
-
- @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
- public static Product from(String name){
- return new Product(false, "DELEG:"+name);
- }
-
- private Product(boolean bogus, String name) {
- this.name = name;
- }
-
- @JsonValue
- public String getName(){
- return name;
- }
- }
-
- private static final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}";
-
- private final ObjectMapper MAPPER = newObjectMapper();
-
- public void testSerialization() throws Exception {
- assertEquals(quote("testProduct"),
- MAPPER.writeValueAsString(new Product(false, "testProduct")));
- }
-
- public void testDeserializationFromObject() throws Exception {
- assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product.class).getName());
- }
-
- public void testDeserializationFromString() throws Exception {
- assertEquals("DELEG:testProduct",
- MAPPER.readValue(quote("testProduct"), Product.class).getName());
- }
-}
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java
new file mode 100644
index 0000000..ca1257d
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java
@@ -0,0 +1,209 @@
+package com.fasterxml.jackson.databind.deser.creators;
+
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.*;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
+import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
+import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
+
+// Misc Creator tests, part 3
+public class TestCreators3 extends BaseMapTest
+{
+ static final class Foo {
+
+ @JsonProperty("foo")
+ protected Map<Integer, Bar> foo;
+ @JsonProperty("anumber")
+ protected long anumber;
+
+ public Foo() {
+ anumber = 0;
+ }
+
+ public Map<Integer, Bar> getFoo() {
+ return foo;
+ }
+
+ public long getAnumber() {
+ return anumber;
+ }
+ }
+
+ static final class Bar {
+
+ private final long p;
+ private final List<String> stuff;
+
+ @JsonCreator
+ public Bar(@JsonProperty("p") long p, @JsonProperty("stuff") List<String> stuff) {
+ this.p = p;
+ this.stuff = stuff;
+ }
+
+ @JsonProperty("s")
+ public List<String> getStuff() {
+ return stuff;
+ }
+
+ @JsonProperty("stuff")
+ private List<String> getStuffDeprecated() {
+ return stuff;
+ }
+
+ public long getP() {
+ return p;
+ }
+ }
+
+ // [databind#421]
+
+ static class MultiCtor
+ {
+ protected String _a, _b;
+
+ private MultiCtor() { }
+ private MultiCtor(String a, String b, Boolean c) {
+ if (c == null) {
+ throw new RuntimeException("Wrong factory!");
+ }
+ _a = a;
+ _b = b;
+ }
+
+ @JsonCreator
+ static MultiCtor factory(@JsonProperty("a") String a, @JsonProperty("b") String b) {
+ return new MultiCtor(a, b, Boolean.TRUE);
+ }
+ }
+
+ @SuppressWarnings("serial")
+ static class MyParamIntrospector extends JacksonAnnotationIntrospector
+ {
+ @Override
+ public String findImplicitPropertyName(AnnotatedMember param) {
+ if (param instanceof AnnotatedParameter) {
+ AnnotatedParameter ap = (AnnotatedParameter) param;
+ switch (ap.getIndex()) {
+ case 0: return "a";
+ case 1: return "b";
+ case 2: return "c";
+ default:
+ return "param"+ap.getIndex();
+ }
+ }
+ return super.findImplicitPropertyName(param);
+ }
+ }
+
+ // [databind#1853]
+ public static class Product {
+ String name;
+
+ public Object other, errors;
+
+ @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
+ public Product(@JsonProperty("name") String name) {
+ this.name = "PROP:" + name;
+ }
+
+ @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
+ public static Product from(String name){
+ return new Product(false, "DELEG:"+name);
+ }
+
+ private Product(boolean bogus, String name) {
+ this.name = name;
+ }
+
+ @JsonValue
+ public String getName(){
+ return name;
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Test methods
+ /**********************************************************
+ */
+
+ private final ObjectMapper MAPPER = newObjectMapper();
+
+ public void testCreator541() throws Exception
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.disable(
+ MapperFeature.AUTO_DETECT_CREATORS,
+ MapperFeature.AUTO_DETECT_FIELDS,
+ MapperFeature.AUTO_DETECT_GETTERS,
+ MapperFeature.AUTO_DETECT_IS_GETTERS,
+ MapperFeature.AUTO_DETECT_SETTERS,
+ MapperFeature.USE_GETTERS_AS_SETTERS
+ );
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+
+ final String JSON = "{\n"
+ + " \"foo\": {\n"
+ + " \"0\": {\n"
+ + " \"p\": 0,\n"
+ + " \"stuff\": [\n"
+ + " \"a\", \"b\" \n"
+ + " ] \n"
+ + " },\n"
+ + " \"1\": {\n"
+ + " \"p\": 1000,\n"
+ + " \"stuff\": [\n"
+ + " \"c\", \"d\" \n"
+ + " ] \n"
+ + " },\n"
+ + " \"2\": {\n"
+ + " \"p\": 2000,\n"
+ + " \"stuff\": [\n"
+ + " ] \n"
+ + " }\n"
+ + " },\n"
+ + " \"anumber\": 25385874\n"
+ + "}";
+
+ Foo obj = mapper.readValue(JSON, Foo.class);
+ assertNotNull(obj);
+ assertNotNull(obj.foo);
+ assertEquals(3, obj.foo.size());
+ assertEquals(25385874L, obj.getAnumber());
+ }
+
+ // [databind#421]
+ public void testMultiCtor421() throws Exception
+ {
+ final ObjectMapper mapper = newObjectMapper();
+ mapper.setAnnotationIntrospector(new MyParamIntrospector());
+
+ MultiCtor bean = mapper.readValue(aposToQuotes("{'a':'123','b':'foo'}"), MultiCtor.class);
+ assertNotNull(bean);
+ assertEquals("123", bean._a);
+ assertEquals("foo", bean._b);
+ }
+
+ // [databind#1853]
+ public void testSerialization() throws Exception {
+ assertEquals(quote("testProduct"),
+ MAPPER.writeValueAsString(new Product(false, "testProduct")));
+ }
+
+ public void testDeserializationFromObject() throws Exception {
+ final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}";
+ assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product.class).getName());
+ }
+
+ public void testDeserializationFromString() throws Exception {
+ assertEquals("DELEG:testProduct",
+ MAPPER.readValue(quote("testProduct"), Product.class).getName());
+ }
+}
+
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators421.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators421.java
deleted file mode 100644
index 24616c6..0000000
--- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators421.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.fasterxml.jackson.databind.deser.creators;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
-import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
-import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
-
-public class TestCreators421 extends BaseMapTest
-{
- static class MultiCtor
- {
- protected String _a, _b;
-
- private MultiCtor() { }
- private MultiCtor(String a, String b, Boolean c) {
- if (c == null) {
- throw new RuntimeException("Wrong factory!");
- }
- _a = a;
- _b = b;
- }
-
- @JsonCreator
- static MultiCtor factory(@JsonProperty("a") String a, @JsonProperty("b") String b) {
- return new MultiCtor(a, b, Boolean.TRUE);
- }
- }
-
- @SuppressWarnings("serial")
- static class MyParamIntrospector extends JacksonAnnotationIntrospector
- {
- @Override
- public String findImplicitPropertyName(AnnotatedMember param) {
- if (param instanceof AnnotatedParameter) {
- AnnotatedParameter ap = (AnnotatedParameter) param;
- switch (ap.getIndex()) {
- case 0: return "a";
- case 1: return "b";
- case 2: return "c";
- default:
- return "param"+ap.getIndex();
- }
- }
- return super.findImplicitPropertyName(param);
- }
- }
-
- /*
- /**********************************************************
- /* Test methods
- /**********************************************************
- */
-
- // [Issue#421]
- public void testMultiCtor421() throws Exception
- {
- final ObjectMapper mapper = new ObjectMapper();
- mapper.setAnnotationIntrospector(new MyParamIntrospector());
-
- MultiCtor bean = mapper.readValue(aposToQuotes("{'a':'123','b':'foo'}"), MultiCtor.class);
- assertNotNull(bean);
- assertEquals("123", bean._a);
- assertEquals("foo", bean._b);
- }
-}
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators541.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators541.java
deleted file mode 100644
index 1e19c7d..0000000
--- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators541.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.fasterxml.jackson.databind.deser.creators;
-
-import java.util.*;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import com.fasterxml.jackson.databind.*;
-
-public class TestCreators541 extends BaseMapTest
-{
- static final class Foo {
-
- @JsonProperty("foo")
- protected Map<Integer, Bar> foo;
- @JsonProperty("anumber")
- protected long anumber;
-
- public Foo() {
- anumber = 0;
- }
-
- public Map<Integer, Bar> getFoo() {
- return foo;
- }
-
- public long getAnumber() {
- return anumber;
- }
- }
-
- static final class Bar {
-
- private final long p;
- private final List<String> stuff;
-
- @JsonCreator
- public Bar(@JsonProperty("p") long p, @JsonProperty("stuff") List<String> stuff) {
- this.p = p;
- this.stuff = stuff;
- }
-
- @JsonProperty("s")
- public List<String> getStuff() {
- return stuff;
- }
-
- @JsonProperty("stuff")
- private List<String> getStuffDeprecated() {
- return stuff;
- }
-
- public long getP() {
- return p;
- }
- }
- /*
- /**********************************************************
- /* Test methods
- /**********************************************************
- */
-
- public void testCreator541() throws Exception
- {
- ObjectMapper mapper = new ObjectMapper();
-
- mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- mapper.disable(
- MapperFeature.AUTO_DETECT_CREATORS,
- MapperFeature.AUTO_DETECT_FIELDS,
- MapperFeature.AUTO_DETECT_GETTERS,
- MapperFeature.AUTO_DETECT_IS_GETTERS,
- MapperFeature.AUTO_DETECT_SETTERS,
- MapperFeature.USE_GETTERS_AS_SETTERS
- );
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
- final String JSON = "{\n"
- + " \"foo\": {\n"
- + " \"0\": {\n"
- + " \"p\": 0,\n"
- + " \"stuff\": [\n"
- + " \"a\", \"b\" \n"
- + " ] \n"
- + " },\n"
- + " \"1\": {\n"
- + " \"p\": 1000,\n"
- + " \"stuff\": [\n"
- + " \"c\", \"d\" \n"
- + " ] \n"
- + " },\n"
- + " \"2\": {\n"
- + " \"p\": 2000,\n"
- + " \"stuff\": [\n"
- + " ] \n"
- + " }\n"
- + " },\n"
- + " \"anumber\": 25385874\n"
- + "}";
-
- Foo obj = mapper.readValue(JSON, Foo.class);
- assertNotNull(obj);
- assertNotNull(obj.foo);
- assertEquals(3, obj.foo.size());
- assertEquals(25385874L, obj.getAnumber());
- }
-}