Skip to content

Commit 26f2669

Browse files
committed
test refactoring
1 parent 83d7139 commit 26f2669

File tree

2 files changed

+41
-47
lines changed

2 files changed

+41
-47
lines changed

src/test/java/com/fasterxml/jackson/databind/creators/EnumCreatorTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.fasterxml.jackson.annotation.JsonCreator;
77
import com.fasterxml.jackson.annotation.JsonGetter;
88
import com.fasterxml.jackson.annotation.JsonProperty;
9+
910
import com.fasterxml.jackson.core.type.TypeReference;
11+
1012
import com.fasterxml.jackson.databind.*;
1113
import com.fasterxml.jackson.databind.deser.Deserializers;
1214
import com.fasterxml.jackson.databind.deser.std.EnumDeserializer;
@@ -140,6 +142,36 @@ static class MyEnum960Wrapper {
140142
public MyEnum960 value;
141143
}
142144

145+
static enum Enum1291 {
146+
147+
V1("val1"),
148+
V2("val2"),
149+
V3("val3"),
150+
V4("val4"),
151+
V5("val5"),
152+
V6("val6");
153+
154+
private final String name;
155+
156+
Enum1291(String name) {
157+
this.name = name;
158+
}
159+
160+
public static Enum1291 fromString(String name) {
161+
for (Enum1291 type : Enum1291.values()) {
162+
if (type.name.equals(name)) {
163+
return type;
164+
}
165+
}
166+
return Enum1291.valueOf(name.toUpperCase());
167+
}
168+
169+
@Override
170+
public String toString() {
171+
return name;
172+
}
173+
}
174+
143175
/*
144176
/**********************************************************
145177
/* Test methods
@@ -231,4 +263,13 @@ public void testNoArgEnumCreator() throws Exception
231263
MyEnum960 v = MAPPER.readValue("{\"value\":\"bogus\"}", MyEnum960.class);
232264
assertEquals(MyEnum960.VALUE, v);
233265
}
266+
267+
// for [databind#1291]
268+
public void testEnumCreators1291() throws Exception
269+
{
270+
ObjectMapper mapper = new ObjectMapper();
271+
String json = mapper.writeValueAsString(Enum1291.V2);
272+
Enum1291 result = mapper.readValue(json, Enum1291.class);
273+
assertSame(Enum1291.V2, result);
274+
}
234275
}

src/test/java/com/fasterxml/jackson/failing/EnumCreator1291Test.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)