Skip to content

Commit 880c64b

Browse files
committed
test refactoring
1 parent 1571c6e commit 880c64b

File tree

4 files changed

+111
-133
lines changed

4 files changed

+111
-133
lines changed

src/test/java/com/fasterxml/jackson/databind/cfg/DeserConfigTest.java renamed to src/test/java/com/fasterxml/jackson/databind/cfg/DeserializationConfigTest.java

+47-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,30 @@
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.core.JsonParser;
77
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
89

9-
public class DeserConfigTest extends BaseMapTest
10+
public class DeserializationConfigTest extends BaseMapTest
1011
{
1112
private final ObjectMapper MAPPER = new ObjectMapper();
1213

14+
public void testFeatureDefaults()
15+
{
16+
ObjectMapper m = new ObjectMapper();
17+
DeserializationConfig cfg = m.getDeserializationConfig();
18+
19+
// Expected defaults:
20+
assertTrue(cfg.isEnabled(MapperFeature.USE_ANNOTATIONS));
21+
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
22+
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_CREATORS));
23+
assertTrue(cfg.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS));
24+
assertTrue(cfg.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS));
25+
26+
assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS));
27+
assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS));
28+
29+
assertTrue(cfg.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
30+
}
31+
1332
public void testBasicFeatures() throws Exception
1433
{
1534
DeserializationConfig config = MAPPER.getDeserializationConfig();
@@ -59,14 +78,39 @@ public void testFormatFeatures() throws Exception
5978
assertNotSame(config, config.withoutFeatures(BogusFormatFeature.FF_DISABLED_BY_DEFAULT,
6079
BogusFormatFeature.FF_ENABLED_BY_DEFAULT));
6180
}
62-
81+
82+
/* Test to verify that we don't overflow number of features; if we
83+
* hit the limit, need to change implementation -- this test just
84+
* gives low-water mark
85+
*/
86+
public void testEnumIndexes()
87+
{
88+
int max = 0;
89+
90+
for (DeserializationFeature f : DeserializationFeature.values()) {
91+
max = Math.max(max, f.ordinal());
92+
}
93+
if (max >= 31) { // 31 is actually ok; 32 not
94+
fail("Max number of DeserializationFeature enums reached: "+max);
95+
}
96+
}
97+
98+
public void testOverrideIntrospectors()
99+
{
100+
ObjectMapper m = new ObjectMapper();
101+
DeserializationConfig cfg = m.getDeserializationConfig();
102+
// and finally, ensure we could override introspectors
103+
cfg = cfg.with((ClassIntrospector) null); // no way to verify tho
104+
cfg = cfg.with((AnnotationIntrospector) null);
105+
assertNull(cfg.getAnnotationIntrospector());
106+
}
107+
63108
public void testMisc() throws Exception
64109
{
65110
DeserializationConfig config = MAPPER.getDeserializationConfig();
66111
assertEquals(JsonInclude.Value.empty(), config.getDefaultPropertyInclusion());
67112
assertEquals(JsonInclude.Value.empty(), config.getDefaultPropertyInclusion(String.class));
68113

69-
70114
assertSame(config, config.withRootName((PropertyName) null)); // defaults to 'none'
71115

72116
DeserializationConfig newConfig = config.withRootName(PropertyName.construct("foobar"));

src/test/java/com/fasterxml/jackson/databind/deser/TestAnnotationIgnore.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/IgnoreWithDeserTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* This unit test suite that tests use of {@link JsonIgnore}
99
* annotation with deserialization.
1010
*/
11-
public class TestAnnotationIgnore
11+
public class IgnoreWithDeserTest
1212
extends BaseMapTest
1313
{
1414
// Class for testing {@link JsonIgnore} annotations with setters

src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java

+63-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.*;
44

55
import com.fasterxml.jackson.annotation.*;
6-
6+
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
77
import com.fasterxml.jackson.core.*;
88
import com.fasterxml.jackson.databind.*;
99
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -18,12 +18,6 @@
1818
public class TestBasicAnnotations
1919
extends BaseMapTest
2020
{
21-
/*
22-
/**********************************************************
23-
/* Annotated helper classes
24-
/**********************************************************
25-
*/
26-
2721
/// Class for testing {@link JsonProperty} annotations
2822
final static class SizeClassSetter
2923
{
@@ -88,6 +82,24 @@ static class BeanWithDeserialize {
8882
@JsonDeserialize protected int a;
8983
}
9084

85+
@JsonAutoDetect(setterVisibility=Visibility.NONE)
86+
final static class Dummy { }
87+
88+
final static class EmptyDummy { }
89+
90+
static class AnnoBean {
91+
int value = 3;
92+
93+
@JsonProperty("y")
94+
public void setX(int v) { value = v; }
95+
}
96+
97+
enum Alpha { A, B, C; }
98+
99+
public static class SimpleBean {
100+
public int x, y;
101+
}
102+
91103
/*
92104
/**********************************************************
93105
/* Other helper classes
@@ -104,10 +116,10 @@ public int[] deserialize(JsonParser jp, DeserializationContext ctxt)
104116
return new int[] { jp.getIntValue() };
105117
}
106118
}
107-
119+
108120
/*
109121
/**********************************************************
110-
/* Test methods
122+
/* Test methods, basic
111123
/**********************************************************
112124
*/
113125

@@ -168,4 +180,46 @@ public void testIssue442PrivateUnwrapped() throws Exception
168180
Issue442Bean bean = MAPPER.readValue("{\"i\":5}", Issue442Bean.class);
169181
assertEquals(5, bean.w.i);
170182
}
183+
184+
/*
185+
/**********************************************************
186+
/* Test methods, annotations disabled
187+
/**********************************************************
188+
*/
189+
190+
public void testAnnotationsDisabled() throws Exception
191+
{
192+
// first: verify that annotation introspection is enabled by default
193+
ObjectMapper m = new ObjectMapper();
194+
assertTrue(m.getDeserializationConfig().isEnabled(MapperFeature.USE_ANNOTATIONS));
195+
// with annotations, property is renamed
196+
AnnoBean bean = m.readValue("{ \"y\" : 0 }", AnnoBean.class);
197+
assertEquals(0, bean.value);
198+
199+
m = new ObjectMapper();
200+
m.configure(MapperFeature.USE_ANNOTATIONS, false);
201+
// without annotations, should default to default bean-based name...
202+
bean = m.readValue("{ \"x\" : 0 }", AnnoBean.class);
203+
assertEquals(0, bean.value);
204+
}
205+
206+
public void testEnumsWhenDisabled() throws Exception
207+
{
208+
ObjectMapper m = new ObjectMapper();
209+
assertEquals(Alpha.B, m.readValue(quote("B"), Alpha.class));
210+
211+
m = new ObjectMapper();
212+
m.configure(MapperFeature.USE_ANNOTATIONS, false);
213+
// should still use the basic name handling here
214+
assertEquals(Alpha.B, m.readValue(quote("B"), Alpha.class));
215+
}
216+
217+
public void testNoAccessOverrides() throws Exception
218+
{
219+
ObjectMapper m = new ObjectMapper();
220+
m.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
221+
SimpleBean bean = m.readValue("{\"x\":1,\"y\":2}", SimpleBean.class);
222+
assertEquals(1, bean.x);
223+
assertEquals(2, bean.y);
224+
}
171225
}

src/test/java/com/fasterxml/jackson/databind/deser/TestConfig.java

-120
This file was deleted.

0 commit comments

Comments
 (0)