Skip to content

Commit 279f69c

Browse files
committed
Test refactoring
1 parent de844c5 commit 279f69c

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/test/java/com/fasterxml/jackson/databind/introspect/CanonicalCreator4584Test.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ public String toString() {
5555
}
5656
}
5757

58-
static class DelegatingCanonicalFindingIntrospector extends ImplicitNameIntrospector
58+
static class PrimaryCreatorFindingIntrospector extends ImplicitNameIntrospector
5959
{
6060
private static final long serialVersionUID = 1L;
6161

62-
private final Class<?> _argType;
62+
private final Class<?>[] _argTypes;
6363

64-
public DelegatingCanonicalFindingIntrospector(Class<?> argType) {
65-
_argType = argType;
64+
private JsonCreator.Mode _mode;
65+
66+
public PrimaryCreatorFindingIntrospector(JsonCreator.Mode mode,
67+
Class<?>... argTypes) {
68+
_mode = mode;
69+
_argTypes = argTypes;
6670
}
6771

6872
@Override
@@ -78,12 +82,20 @@ public PotentialCreator findPrimaryCreator(MapperConfig<?> config,
7882
System.err.println("findCanonicalCreator DONE for: "+valueClass.getRawType());
7983
List<PotentialCreator> combo = new ArrayList<>(declaredConstructors);
8084
combo.addAll(declaredFactories);
85+
final int argCount = _argTypes.length;
8186
for (PotentialCreator ctor : combo) {
82-
if (ctor.paramCount() == 1
83-
&& _argType == ctor.param(0).getRawType()) {
87+
if (ctor.paramCount() == argCount) {
88+
int i = 0;
89+
for (; i < argCount; ++i) {
90+
if (_argTypes[i] != ctor.param(i).getRawType()) {
91+
break;
92+
}
93+
}
94+
if (i == argCount) {
8495
System.err.println("MATCH! "+ctor);
85-
ctor.overrideMode(JsonCreator.Mode.DELEGATING);
86-
return ctor;
96+
ctor.overrideMode(_mode);
97+
return ctor;
98+
}
8799
}
88100
}
89101
System.err.println("No MATCH! ");
@@ -102,7 +114,8 @@ public PotentialCreator findPrimaryCreator(MapperConfig<?> config,
102114
public void testCanonicalConstructorPropertiesCreator() throws Exception
103115
{
104116
assertEquals(POJO4584.factoryString("List[0]"),
105-
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
117+
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.PROPERTIES,
118+
List.class))
106119
.readValue(a2q("{'x':[ ]}")));
107120
}
108121
*/
@@ -116,24 +129,27 @@ public void testCanonicalConstructorPropertiesCreator() throws Exception
116129
@Test
117130
public void testCanonicalConstructorDelegatingIntCreator() throws Exception
118131
{
119-
assertEquals(POJO4584.factoryString("List[3]"),
120-
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
121-
.readValue(a2q("[1, 2, 3]")));
132+
assertEquals(POJO4584.factoryString("int[42]"),
133+
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
134+
Integer.TYPE))
135+
.readValue(a2q("42")));
122136
}
123137

124138
@Test
125139
public void testCanonicalConstructorDelegatingListCreator() throws Exception
126140
{
127141
assertEquals(POJO4584.factoryString("List[3]"),
128-
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
142+
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
143+
List.class))
129144
.readValue(a2q("[1, 2, 3]")));
130145
}
131146

132147
@Test
133148
public void testCanonicalConstructorDelegatingArrayCreator() throws Exception
134149
{
135150
assertEquals(POJO4584.factoryString("Array[1]"),
136-
readerWith(new DelegatingCanonicalFindingIntrospector(Object[].class))
151+
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
152+
Object[].class))
137153
.readValue(a2q("[true]")));
138154
}
139155

0 commit comments

Comments
 (0)