Skip to content

Commit 2161d24

Browse files
authored
Migrate tests under /ser and /ser/filter (#4447)
1 parent 407f500 commit 2161d24

File tree

55 files changed

+672
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+672
-86
lines changed

src/test/java/com/fasterxml/jackson/databind/ser/AnyGetterTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import java.io.IOException;
44
import java.util.*;
55

6+
import org.junit.jupiter.api.Test;
7+
68
import com.fasterxml.jackson.annotation.*;
79
import com.fasterxml.jackson.core.JsonGenerator;
810
import com.fasterxml.jackson.databind.*;
911
import com.fasterxml.jackson.databind.ser.impl.*;
1012
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1113
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
1214
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
15+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
16+
17+
import static org.junit.jupiter.api.Assertions.*;
1318

14-
public class AnyGetterTest extends BaseMapTest
19+
public class AnyGetterTest extends DatabindTestUtil
1520
{
1621
static class Bean
1722
{
@@ -181,6 +186,7 @@ public void set(String name, String value) {
181186
}
182187

183188
// [databind#1458]: Allow `@JsonAnyGetter` on fields too
189+
@Test
184190
public void testDynaFieldBean() throws Exception
185191
{
186192
DynaFieldBean b = new DynaFieldBean();
@@ -201,6 +207,7 @@ public void testDynaFieldBean() throws Exception
201207

202208
private final ObjectMapper MAPPER = newJsonMapper();
203209

210+
@Test
204211
public void testSimpleAnyBean() throws Exception
205212
{
206213
String json = MAPPER.writeValueAsString(new Bean());
@@ -210,6 +217,7 @@ public void testSimpleAnyBean() throws Exception
210217
assertEquals(Boolean.TRUE, map.get("a"));
211218
}
212219

220+
@Test
213221
public void testAnyOnly() throws Exception
214222
{
215223
ObjectMapper m;
@@ -227,13 +235,15 @@ public void testAnyOnly() throws Exception
227235
assertEquals("{\"a\":3}", json);
228236
}
229237

238+
@Test
230239
public void testAnyDisabling() throws Exception
231240
{
232241
String json = MAPPER.writeValueAsString(new NotEvenAnyBean());
233242
assertEquals(a2q("{'value':42}"), json);
234243
}
235244

236245
// Trying to repro [databind#577]
246+
@Test
237247
public void testAnyWithNull() throws Exception
238248
{
239249
MapAsAny input = new MapAsAny();
@@ -242,6 +252,7 @@ public void testAnyWithNull() throws Exception
242252
MAPPER.writeValueAsString(input));
243253
}
244254

255+
@Test
245256
public void testIssue705() throws Exception
246257
{
247258
Issue705Bean input = new Issue705Bean("key", "value");
@@ -250,6 +261,7 @@ public void testIssue705() throws Exception
250261
}
251262

252263
// [databind#1124]
264+
@Test
253265
public void testAnyGetterWithValueSerializer() throws Exception
254266
{
255267
ObjectMapper mapper = new ObjectMapper();
@@ -260,6 +272,7 @@ public void testAnyGetterWithValueSerializer() throws Exception
260272
}
261273

262274
// [databind#2592]
275+
@Test
263276
public void testAnyGetterWithMapperDefaultIncludeNonEmpty() throws Exception
264277
{
265278
ObjectMapper mapper = new ObjectMapper()
@@ -273,6 +286,7 @@ public void testAnyGetterWithMapperDefaultIncludeNonEmpty() throws Exception
273286
}
274287

275288
// [databind#2592]
289+
@Test
276290
public void testAnyGetterWithMapperDefaultIncludeNonEmptyAndFilterOnBean() throws Exception
277291
{
278292
FilterProvider filters = new SimpleFilterProvider()
@@ -290,6 +304,7 @@ public void testAnyGetterWithMapperDefaultIncludeNonEmptyAndFilterOnBean() throw
290304
}
291305

292306
// [databind#2592]
307+
@Test
293308
public void testAnyGetterWithPropertyIncludeNonEmpty() throws Exception
294309
{
295310
ObjectMapper mapper = new ObjectMapper();
@@ -302,6 +317,7 @@ public void testAnyGetterWithPropertyIncludeNonEmpty() throws Exception
302317
}
303318

304319
// [databind#2592]
320+
@Test
305321
public void testAnyGetterConfigIncludeNonEmpty() throws Exception
306322
{
307323
final ObjectMapper mapper = jsonMapperBuilder()

src/test/java/com/fasterxml/jackson/databind/ser/BeanSerializerModifier1612Test.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
import java.util.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
68

79
import com.fasterxml.jackson.databind.*;
810
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
911
import com.fasterxml.jackson.databind.module.SimpleModule;
12+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
13+
14+
import static org.junit.jupiter.api.Assertions.*;
1015

11-
public class BeanSerializerModifier1612Test extends BaseMapTest
16+
public class BeanSerializerModifier1612Test extends DatabindTestUtil
1217
{
1318
@JsonPropertyOrder({ "a", "b", "c" })
1419
static class Bean1612 {
@@ -48,6 +53,7 @@ public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescr
4853
/**********************************************************
4954
*/
5055

56+
@Test
5157
public void testIssue1612() throws Exception
5258
{
5359
SimpleModule mod = new SimpleModule();

src/test/java/com/fasterxml/jackson/databind/ser/BeanSerializerModifierTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.IOException;
44
import java.util.*;
55

6+
import org.junit.jupiter.api.Test;
7+
68
import com.fasterxml.jackson.annotation.*;
79

810
import com.fasterxml.jackson.core.*;
@@ -12,16 +14,19 @@
1214
import com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder;
1315
import com.fasterxml.jackson.databind.module.SimpleModule;
1416
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
17+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
1518
import com.fasterxml.jackson.databind.type.ArrayType;
1619
import com.fasterxml.jackson.databind.type.CollectionType;
1720
import com.fasterxml.jackson.databind.type.MapType;
1821

22+
import static org.junit.jupiter.api.Assertions.*;
23+
1924
/**
2025
* Unit tests for verifying that it is possible to configure
2126
* construction of {@link BeanSerializer} instances.
2227
*/
2328
@SuppressWarnings("serial")
24-
public class BeanSerializerModifierTest extends BaseMapTest
29+
public class BeanSerializerModifierTest extends DatabindTestUtil
2530
{
2631
static class SerializerModifierModule extends SimpleModule
2732
{
@@ -252,6 +257,7 @@ public JsonSerializer<?> modifyKeySerializer(SerializationConfig config,
252257
/********************************************************
253258
*/
254259

260+
@Test
255261
public void testPropertyRemoval() throws Exception
256262
{
257263
ObjectMapper mapper = new ObjectMapper();
@@ -260,6 +266,7 @@ public void testPropertyRemoval() throws Exception
260266
assertEquals("{\"b\":\"b\"}", mapper.writeValueAsString(bean));
261267
}
262268

269+
@Test
263270
public void testPropertyReorder() throws Exception
264271
{
265272
ObjectMapper mapper = new ObjectMapper();
@@ -268,13 +275,15 @@ public void testPropertyReorder() throws Exception
268275
assertEquals("{\"a\":\"a\",\"b\":\"b\"}", mapper.writeValueAsString(bean));
269276
}
270277

278+
@Test
271279
public void testBuilderReplacement() throws Exception
272280
{
273281
ObjectMapper mapper = new ObjectMapper();
274282
mapper.registerModule(new SerializerModifierModule(new BuilderModifier(new BogusBeanSerializer(17))));
275283
Bean bean = new Bean();
276284
assertEquals("17", mapper.writeValueAsString(bean));
277285
}
286+
@Test
278287
public void testSerializerReplacement() throws Exception
279288
{
280289
ObjectMapper mapper = new ObjectMapper();
@@ -284,6 +293,7 @@ public void testSerializerReplacement() throws Exception
284293
}
285294

286295
// for [JACKSON-670]
296+
@Test
287297
public void testEmptyBean() throws Exception
288298
{
289299
ObjectMapper mapper = new ObjectMapper();
@@ -299,6 +309,7 @@ public void setupModule(SetupContext context)
299309
assertEquals("{\"bogus\":\"foo\"}", json);
300310
}
301311

312+
@Test
302313
public void testEmptyBean539() throws Exception
303314
{
304315
ObjectMapper mapper = new ObjectMapper();
@@ -316,6 +327,7 @@ public void setupModule(SetupContext context)
316327

317328
// [databind#121]
318329

330+
@Test
319331
public void testModifyArraySerializer() throws Exception
320332
{
321333
ObjectMapper mapper = new ObjectMapper();
@@ -324,6 +336,7 @@ public void testModifyArraySerializer() throws Exception
324336
assertEquals("123", mapper.writeValueAsString(new Integer[] { 1, 2 }));
325337
}
326338

339+
@Test
327340
public void testModifyCollectionSerializer() throws Exception
328341
{
329342
ObjectMapper mapper = new ObjectMapper();
@@ -332,6 +345,7 @@ public void testModifyCollectionSerializer() throws Exception
332345
assertEquals("123", mapper.writeValueAsString(new ArrayList<Integer>()));
333346
}
334347

348+
@Test
335349
public void testModifyMapSerializer() throws Exception
336350
{
337351
ObjectMapper mapper = new ObjectMapper();
@@ -340,6 +354,7 @@ public void testModifyMapSerializer() throws Exception
340354
assertEquals("123", mapper.writeValueAsString(new HashMap<String,String>()));
341355
}
342356

357+
@Test
343358
public void testModifyEnumSerializer() throws Exception
344359
{
345360
ObjectMapper mapper = new ObjectMapper();
@@ -348,6 +363,7 @@ public void testModifyEnumSerializer() throws Exception
348363
assertEquals("123", mapper.writeValueAsString(ABC.C));
349364
}
350365

366+
@Test
351367
public void testModifyKeySerializer() throws Exception
352368
{
353369
ObjectMapper mapper = new ObjectMapper();

src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import java.util.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonFormat;
68
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
79

810
import com.fasterxml.jackson.databind.*;
911
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
12+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
13+
14+
import static org.junit.jupiter.api.Assertions.*;
1015

1116
/**
1217
* Simple unit tests to verify that it is possible to handle
@@ -15,7 +20,7 @@
1520
* trees and DAGs.
1621
*/
1722
public class CyclicTypeSerTest
18-
extends BaseMapTest
23+
extends DatabindTestUtil
1924
{
2025
static class Bean
2126
{
@@ -55,6 +60,7 @@ static class Selfie2501AsArray extends Selfie2501 {
5560

5661
private final ObjectMapper MAPPER = newJsonMapper();
5762

63+
@Test
5864
public void testLinkedButNotCyclic() throws Exception
5965
{
6066
Bean last = new Bean(null, "last");
@@ -72,6 +78,7 @@ public void testLinkedButNotCyclic() throws Exception
7278
assertNull(map2.get("next"));
7379
}
7480

81+
@Test
7582
public void testSimpleDirectSelfReference() throws Exception
7683
{
7784
Bean selfRef = new Bean(null, "self-refs");
@@ -86,6 +93,7 @@ public void testSimpleDirectSelfReference() throws Exception
8693
}
8794

8895
// [databind#2501]: Should be possible to replace null cyclic ref
96+
@Test
8997
public void testReplacedCycle() throws Exception
9098
{
9199
Selfie2501 self1 = new Selfie2501(1);

src/test/java/com/fasterxml/jackson/databind/ser/EnumAsMapKeyTest.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import java.io.IOException;
44
import java.util.*;
55

6+
import org.junit.jupiter.api.Test;
7+
68
import com.fasterxml.jackson.annotation.JsonAnyGetter;
79
import com.fasterxml.jackson.annotation.JsonValue;
810

911
import com.fasterxml.jackson.core.JsonGenerator;
1012

1113
import com.fasterxml.jackson.databind.*;
1214
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
15+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
16+
17+
import static org.junit.jupiter.api.Assertions.*;
1318

14-
public class EnumAsMapKeyTest extends BaseMapTest
19+
public class EnumAsMapKeyTest extends DatabindTestUtil
1520
{
1621
static class MapBean {
1722
public Map<ABCEnum,Integer> map = new HashMap<>();
@@ -95,6 +100,7 @@ public TypeContainer(Type type, int value) {
95100

96101
private final ObjectMapper MAPPER = newJsonMapper();
97102

103+
@Test
98104
public void testMapWithEnumKeys() throws Exception
99105
{
100106
MapBean bean = new MapBean();
@@ -121,18 +127,21 @@ public void testMapWithEnumKeys() throws Exception
121127
assertEquals(a2q("{'map':{'B':3}}"), json);
122128
}
123129

130+
@Test
124131
public void testCustomEnumMapKeySerializer() throws Exception {
125132
String json = MAPPER.writeValueAsString(new MyBean661("abc"));
126133
assertEquals(a2q("{'X-FOO':'abc'}"), json);
127134
}
128135

129136
// [databind#594]
137+
@Test
130138
public void testJsonValueForEnumMapKey() throws Exception {
131139
assertEquals(a2q("{'stuff':{'longValue':'foo'}}"),
132140
MAPPER.writeValueAsString(new MyStuff594("foo")));
133141
}
134142

135143
// [databind#2129]
144+
@Test
136145
public void testEnumAsIndexForRootMap() throws Exception
137146
{
138147
final Map<Type, Integer> input = Collections.singletonMap(Type.FIRST, 3);
@@ -155,6 +164,7 @@ public void testEnumAsIndexForRootMap() throws Exception
155164
}
156165

157166
// [databind#2129]
167+
@Test
158168
public void testEnumAsIndexForValueMap() throws Exception
159169
{
160170
final TypeContainer input = new TypeContainer(Type.SECOND, 72);

0 commit comments

Comments
 (0)