Skip to content

Commit 6756db5

Browse files
authored
Migrate /deser/jdk tests to JUnit 5 (#4362)
1 parent 368e18d commit 6756db5

33 files changed

+579
-109
lines changed

src/test/java/com/fasterxml/jackson/databind/BaseMapTest.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ public String getSchemaType() {
3232
}
3333
}
3434

35-
/**
36-
* Simple wrapper around boolean types, usually to test value
37-
* conversions or wrapping
38-
*/
39-
protected static class BooleanWrapper {
40-
public Boolean b;
41-
42-
public BooleanWrapper() { }
43-
public BooleanWrapper(Boolean value) { b = value; }
44-
}
45-
4635
protected static class IntWrapper {
4736
public int i;
4837

@@ -84,18 +73,6 @@ public StringWrapper(String value) {
8473
}
8574
}
8675

87-
protected static class ObjectWrapper {
88-
final Object object;
89-
protected ObjectWrapper(final Object object) {
90-
this.object = object;
91-
}
92-
public Object getObject() { return object; }
93-
@JsonCreator
94-
static ObjectWrapper jsonValue(final Object object) {
95-
return new ObjectWrapper(object);
96-
}
97-
}
98-
9976
protected static class ListWrapper<T>
10077
{
10178
public List<T> list;
@@ -176,18 +153,6 @@ public void serialize(String value, JsonGenerator gen,
176153
}
177154
}
178155

179-
@SuppressWarnings("serial")
180-
public static class LowerCasingDeserializer extends StdScalarDeserializer<String>
181-
{
182-
public LowerCasingDeserializer() { super(String.class); }
183-
184-
@Override
185-
public String deserialize(JsonParser p, DeserializationContext ctxt)
186-
throws IOException {
187-
return p.getText().toLowerCase();
188-
}
189-
}
190-
191156
/*
192157
/**********************************************************
193158
/* Construction
@@ -336,10 +301,6 @@ protected <T> T readAndMapFromString(ObjectMapper m, String input, Class<T> cls)
336301
/**********************************************************
337302
*/
338303

339-
protected TimeZone getUTCTimeZone() {
340-
return TimeZone.getTimeZone("GMT");
341-
}
342-
343304
protected byte[] utf8Bytes(String str) {
344305
try {
345306
return str.getBytes("UTF-8");

src/test/java/com/fasterxml/jackson/databind/deser/jdk/ArrayDeserializationTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.*;
44
import java.util.*;
55

6-
import static org.junit.Assert.*;
6+
import org.junit.jupiter.api.Test;
77

88
import com.fasterxml.jackson.core.*;
99
import com.fasterxml.jackson.core.type.TypeReference;
@@ -12,12 +12,17 @@
1212
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
1313
import com.fasterxml.jackson.databind.module.SimpleModule;
1414

15+
import static org.junit.jupiter.api.Assertions.*;
16+
17+
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.a2q;
18+
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.q;
19+
20+
1521
/**
1622
* This unit test suite tries to verify that the "Native" java type
1723
* mapper can properly re-construct Java array objects from Json arrays.
1824
*/
1925
public class ArrayDeserializationTest
20-
extends BaseMapTest
2126
{
2227
public final static class Bean1
2328
{
@@ -142,6 +147,7 @@ static class HiddenBinaryBean890 {
142147

143148
private final ObjectMapper MAPPER = new ObjectMapper();
144149

150+
@Test
145151
public void testUntypedArray() throws Exception
146152
{
147153

@@ -160,6 +166,7 @@ public void testUntypedArray() throws Exception
160166
assertEquals(Double.valueOf(2.0), result[4]);
161167
}
162168

169+
@Test
163170
public void testIntegerArray() throws Exception
164171
{
165172
final int LEN = 90000;
@@ -186,6 +193,7 @@ public void testIntegerArray() throws Exception
186193
}
187194

188195
// [JACKSON-620]: allow "" to mean 'null' for Arrays, List and Maps
196+
@Test
189197
public void testFromEmptyString() throws Exception
190198
{
191199
ObjectReader r = MAPPER.reader()
@@ -196,6 +204,7 @@ public void testFromEmptyString() throws Exception
196204
}
197205

198206
// [JACKSON-620]: allow "" to mean 'null' for Arrays, List and Maps
207+
@Test
199208
public void testFromEmptyString2() throws Exception
200209
{
201210
ObjectReader r = MAPPER.readerFor(Product.class)
@@ -212,6 +221,7 @@ public void testFromEmptyString2() throws Exception
212221
/**********************************************************
213222
*/
214223

224+
@Test
215225
public void testUntypedArrayOfArrays() throws Exception
216226
{
217227
// to get "untyped" default map-to-map, pass Object[].class
@@ -244,6 +254,7 @@ public void testUntypedArrayOfArrays() throws Exception
244254
/**********************************************************
245255
*/
246256

257+
@Test
247258
public void testStringArray() throws Exception
248259
{
249260
final String[] STRS = new String[] {
@@ -273,6 +284,7 @@ public void testStringArray() throws Exception
273284
assertNull(result[0]);
274285
}
275286

287+
@Test
276288
public void testCharArray() throws Exception
277289
{
278290
final String TEST_STR = "Let's just test it? Ok!";
@@ -290,6 +302,7 @@ public void testCharArray() throws Exception
290302
/**********************************************************
291303
*/
292304

305+
@Test
293306
public void testBooleanArray() throws Exception
294307
{
295308
boolean[] result = MAPPER.readValue("[ true, false, false ]", boolean[].class);
@@ -300,6 +313,7 @@ public void testBooleanArray() throws Exception
300313
assertFalse(result[2]);
301314
}
302315

316+
@Test
303317
public void testByteArrayAsNumbers() throws Exception
304318
{
305319
final int LEN = 37000;
@@ -325,6 +339,7 @@ public void testByteArrayAsNumbers() throws Exception
325339
assertEquals(0, result[LEN]);
326340
}
327341

342+
@Test
328343
public void testByteArrayAsBase64() throws Exception
329344
{
330345
/* Hmmh... let's use JsonGenerator here, to hopefully ensure we
@@ -354,6 +369,7 @@ public void testByteArrayAsBase64() throws Exception
354369
* And then bit more challenging case; let's try decoding
355370
* multiple byte arrays from an array...
356371
*/
372+
@Test
357373
public void testByteArraysAsBase64() throws Exception
358374
{
359375
JsonFactory jf = new JsonFactory();
@@ -384,11 +400,12 @@ public void testByteArraysAsBase64() throws Exception
384400
assertEquals(entryCount, result.length);
385401
for (int i = 0; i < entryCount; ++i) {
386402
byte[] b = result[i];
387-
assertArrayEquals("Comparing entry #"+i+"/"+entryCount,entries[i], b);
403+
assertArrayEquals(entries[i], b, "Comparing entry #"+i+"/"+entryCount);
388404
}
389405
}
390406

391407
// [JACKSON-763]
408+
@Test
392409
public void testByteArraysWith763() throws Exception
393410
{
394411
String[] input = new String[] { "YQ==", "Yg==", "Yw==" };
@@ -398,6 +415,7 @@ public void testByteArraysWith763() throws Exception
398415
assertEquals("c", new String(data[2], "US-ASCII"));
399416
}
400417

418+
@Test
401419
public void testShortArray() throws Exception
402420
{
403421
final int LEN = 31001; // fits in signed 16-bit
@@ -421,6 +439,7 @@ public void testShortArray() throws Exception
421439
}
422440
}
423441

442+
@Test
424443
public void testIntArray() throws Exception
425444
{
426445
final int LEN = 70000;
@@ -446,6 +465,7 @@ public void testIntArray() throws Exception
446465
}
447466
}
448467

468+
@Test
449469
public void testLongArray() throws Exception
450470
{
451471
final int LEN = 12300;
@@ -469,6 +489,7 @@ public void testLongArray() throws Exception
469489
}
470490
}
471491

492+
@Test
472493
public void testDoubleArray() throws Exception
473494
{
474495
final int LEN = 7000;
@@ -496,6 +517,7 @@ public void testDoubleArray() throws Exception
496517
}
497518
}
498519

520+
@Test
499521
public void testFloatArray() throws Exception
500522
{
501523
final int LEN = 7000;
@@ -526,6 +548,7 @@ public void testFloatArray() throws Exception
526548
/**********************************************************
527549
*/
528550

551+
@Test
529552
public void testBeanArray()
530553
throws Exception
531554
{
@@ -558,6 +581,7 @@ public void testBeanArray()
558581
*/
559582

560583
// for [databind#890]
584+
@Test
561585
public void testByteArrayTypeOverride890() throws Exception
562586
{
563587
HiddenBinaryBean890 result = MAPPER.readValue(
@@ -573,6 +597,7 @@ public void testByteArrayTypeOverride890() throws Exception
573597
/**********************************************************
574598
*/
575599

600+
@Test
576601
public void testCustomDeserializers() throws Exception
577602
{
578603
ObjectMapper mapper = new ObjectMapper();

src/test/java/com/fasterxml/jackson/databind/deser/jdk/Base64DecodingTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
22

33
import java.nio.charset.StandardCharsets;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.databind.*;
68
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
79

10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;
13+
814
// Mostly for [databind#1425]; not in optimal place (as it also has
915
// tree-access tests), but has to do for now
10-
public class Base64DecodingTest extends BaseMapTest
16+
public class Base64DecodingTest
1117
{
12-
private final ObjectMapper MAPPER = objectMapper();
18+
private final ObjectMapper MAPPER = newJsonMapper();
1319

1420
private final byte[] HELLO_BYTES = "hello".getBytes(StandardCharsets.UTF_8);
1521
private final String BASE64_HELLO = "aGVsbG8=";
1622

1723
// for [databind#1425]
24+
@Test
1825
public void testInvalidBase64() throws Exception
1926
{
2027
byte[] b = MAPPER.readValue(q(BASE64_HELLO), byte[].class);
21-
assertEquals(HELLO_BYTES, b);
28+
assertArrayEquals(HELLO_BYTES, b);
2229

2330
_testInvalidBase64(MAPPER, BASE64_HELLO+"!");
2431
_testInvalidBase64(MAPPER, BASE64_HELLO+"!!");

src/test/java/com/fasterxml/jackson/databind/deser/jdk/CharSequenceDeser3305Test.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package com.fasterxml.jackson.databind.deser.jdk;
22

3-
import com.fasterxml.jackson.databind.BaseMapTest;
3+
import org.junit.jupiter.api.Test;
4+
45
import com.fasterxml.jackson.databind.ObjectMapper;
56

7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;
10+
611
// for [databind#3305]
7-
public class CharSequenceDeser3305Test extends BaseMapTest
12+
public class CharSequenceDeser3305Test
813
{
914
static final class AppId implements CharSequence {
1015
private final long value;
@@ -46,6 +51,7 @@ public String toString() {
4651

4752
private final static ObjectMapper MAPPER = newJsonMapper();
4853

54+
@Test
4955
public void testCharSequenceSerialization() throws Exception {
5056
AppId appId = AppId.valueOf(APP_ID);
5157

0 commit comments

Comments
 (0)