Skip to content

Commit f60d992

Browse files
committed
Merge branch '2.19'
2 parents 6f15723 + 0f590b9 commit f60d992

File tree

9 files changed

+91
-36
lines changed

9 files changed

+91
-36
lines changed

android-record/pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@
4242
<artifactId>jackson-databind</artifactId>
4343
</dependency>
4444

45-
<!-- 20-Apr-2024, tatu: JUnit4 no longer from jackson-base -->
45+
<!-- Test dependencies: JUnit 5 -->
4646
<dependency>
47-
<groupId>junit</groupId>
48-
<artifactId>junit</artifactId>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-api</artifactId>
4954
<scope>test</scope>
5055
</dependency>
5156
</dependencies>

android-record/src/test/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
// Additional test lib/framework dependencies
1212

13-
requires junit; // JUnit4 To Be Removed in future
13+
requires org.junit.jupiter.api;
14+
requires org.junit.jupiter.params;
1415

1516
// Further, need to open up some packages for JUnit et al
1617

android-record/src/test/java/tools/jackson/module/androidrecord/AbstractRecordMemberTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package tools.jackson.module.androidrecord;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.android.tools.r8.RecordTag;
46

5-
import com.fasterxml.jackson.annotation.JsonCreator;
6-
import com.fasterxml.jackson.annotation.JsonProperty;
7-
import com.fasterxml.jackson.annotation.JsonSubTypes;
8-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
7+
import com.fasterxml.jackson.annotation.*;
98

109
import tools.jackson.databind.ObjectMapper;
1110

12-
public class AbstractRecordMemberTest extends BaseMapTest {
13-
14-
static final class RootRecord extends RecordTag {
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1513

14+
public class AbstractRecordMemberTest extends BaseMapTest
15+
{
16+
static final class RootRecord extends RecordTag
17+
{
1618
private final AbstractMember member;
1719

1820
public RootRecord(AbstractMember member) {
@@ -67,6 +69,8 @@ public int getVal() {
6769
/* https://github.com/FasterXML/jackson-modules-base/issues/248
6870
/**********************************************************************
6971
*/
72+
73+
@Test
7074
public void testDeserializeRecordWithAbstractMember() throws Exception {
7175
RootRecord value = MAPPER.readValue("{\"member\":{\"@class\":\"string\",\"val\":\"Hello, abstract member!\"}}",
7276
RootRecord.class);

android-record/src/test/java/tools/jackson/module/androidrecord/AndroidRecordTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package tools.jackson.module.androidrecord;
22

3-
import java.util.Arrays;
4-
import java.util.List;
5-
import java.util.Objects;
3+
import java.util.*;
64
import java.util.concurrent.atomic.AtomicInteger;
75

6+
import org.junit.jupiter.api.Test;
7+
88
import com.android.tools.r8.RecordTag;
99

1010
import com.fasterxml.jackson.annotation.JsonAutoDetect;
@@ -13,16 +13,18 @@
1313
import tools.jackson.databind.ObjectMapper;
1414
import tools.jackson.databind.exc.InvalidDefinitionException;
1515
import tools.jackson.databind.json.JsonMapper;
16-
import junit.framework.TestCase;
1716

18-
import org.junit.Assert;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
1919

2020
/**
2121
* Inner test classes simulate Android-desugared records.
2222
*
2323
* @author Eran Leshem
2424
**/
25-
public class AndroidRecordTest extends TestCase {
25+
public class AndroidRecordTest
26+
extends BaseMapTest
27+
{
2628
static final class Simple extends RecordTag {
2729
static int si = 7;
2830
private final int i;
@@ -129,17 +131,18 @@ public String s() {
129131
}
130132
}
131133

132-
133134
private final ObjectMapper _objectMapper = JsonMapper.builder()
134135
.addModule(new AndroidRecordModule())
135136
.changeDefaultVisibility(vc -> vc.withVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY))
136137
.build();
137138

139+
@Test
138140
public void testSimple() throws Exception {
139141
Simple simple = new Simple(9, 3, "foo", Arrays.asList("bar", "baz"), new AtomicInteger(8));
140142
assertEquals(simple, _objectMapper.readValue(_objectMapper.writeValueAsString(simple), Simple.class));
141143
}
142144

145+
@Test
143146
public void testMultipleConstructors() throws Exception {
144147
List<String> l = Arrays.asList("bar", "baz");
145148
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(new MultipleConstructors(9, l)),
@@ -152,8 +155,9 @@ public void testMultipleConstructors() throws Exception {
152155
new MultipleConstructors(Arrays.asList(1, 2), 9)), MultipleConstructors.class).i());
153156
}
154157

158+
@Test
155159
public void testConflictingConstructors() {
156-
Assert.assertThrows(InvalidDefinitionException.class,
160+
assertThrows(InvalidDefinitionException.class,
157161
() -> _objectMapper.readValue(_objectMapper.writeValueAsString(
158162
new ConflictingConstructors(9, "foo")), ConflictingConstructors.class));
159163
}

android-record/src/test/java/tools/jackson/module/androidrecord/BaseTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package tools.jackson.module.androidrecord;
22

3-
import junit.framework.TestCase;
4-
53
import java.util.Arrays;
64

5+
import static org.junit.jupiter.api.Assertions.fail;
6+
77
public abstract class BaseTest
8-
extends TestCase
98
{
109
/**
1110
* @param e Exception to check

android-record/src/test/java/tools/jackson/module/androidrecord/RecordBasicsTest.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package tools.jackson.module.androidrecord;
22

3-
import java.util.Collections;
4-
import java.util.LinkedHashMap;
5-
import java.util.Map;
6-
import java.util.Objects;
3+
import java.util.*;
74

8-
import com.android.tools.r8.RecordTag;
5+
import org.junit.jupiter.api.Test;
96

10-
import org.junit.Assert;
7+
import com.android.tools.r8.RecordTag;
118

129
import com.fasterxml.jackson.annotation.JacksonInject;
1310
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -20,6 +17,8 @@
2017
import tools.jackson.databind.type.TypeFactory;
2118
import tools.jackson.databind.util.Converter;
2219

20+
import static org.junit.jupiter.api.Assertions.*;
21+
2322
public class RecordBasicsTest extends BaseMapTest
2423
{
2524
static final class EmptyRecord extends RecordTag {
@@ -332,13 +331,15 @@ public String toString() {
332331
/**********************************************************************
333332
*/
334333

334+
@Test
335335
public void testClassUtil() {
336336
assertFalse(AndroidRecordModule.isDesugaredRecordClass(getClass()));
337337
assertTrue(AndroidRecordModule.isDesugaredRecordClass(SimpleRecord.class));
338338
assertTrue(AndroidRecordModule.isDesugaredRecordClass(RecordOfRecord.class));
339339
assertTrue(AndroidRecordModule.isDesugaredRecordClass(RecordWithRename.class));
340340
}
341341

342+
@Test
342343
public void testRecordJavaType() {
343344
assertFalse(AndroidRecordModule.isDesugaredRecordClass(MAPPER.constructType(getClass()).getRawClass()));
344345
assertTrue(AndroidRecordModule.isDesugaredRecordClass(MAPPER.constructType(SimpleRecord.class).getRawClass()));
@@ -352,26 +353,31 @@ public void testRecordJavaType() {
352353
/**********************************************************************
353354
*/
354355

356+
@Test
355357
public void testSerializeSimpleRecord() throws Exception {
356358
String json = MAPPER.writeValueAsString(new SimpleRecord(123, "Bob"));
357359
final Object EXP = map("id", Integer.valueOf(123), "name", "Bob");
358360
assertEquals(EXP, MAPPER.readValue(json, Object.class));
359361
}
360362

363+
@Test
361364
public void testDeserializeSimpleRecord() throws Exception {
362365
assertEquals(new SimpleRecord(123, "Bob"),
363366
MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class));
364367
}
365368

369+
@Test
366370
public void testSerializeEmptyRecord() throws Exception {
367371
assertEquals("{}", MAPPER.writeValueAsString(new EmptyRecord()));
368372
}
369373

374+
@Test
370375
public void testDeserializeEmptyRecord() throws Exception {
371376
assertEquals(new EmptyRecord(),
372377
MAPPER.readValue("{}", EmptyRecord.class));
373378
}
374379

380+
@Test
375381
public void testSerializeRecordOfRecord() throws Exception {
376382
RecordOfRecord record = new RecordOfRecord(new SimpleRecord(123, "Bob"));
377383
String json = MAPPER.writeValueAsString(record);
@@ -380,6 +386,7 @@ public void testSerializeRecordOfRecord() throws Exception {
380386
assertEquals(EXP, MAPPER.readValue(json, Object.class));
381387
}
382388

389+
@Test
383390
public void testDeserializeRecordOfRecord() throws Exception {
384391
assertEquals(new RecordOfRecord(new SimpleRecord(123, "Bob")),
385392
MAPPER.readValue("{\"record\":{\"id\":123,\"name\":\"Bob\"}}",
@@ -392,6 +399,7 @@ public void testDeserializeRecordOfRecord() throws Exception {
392399
/**********************************************************************
393400
*/
394401

402+
@Test
395403
public void testSerializeSimpleRecord_DisableAnnotationIntrospector() throws Exception {
396404
SimpleRecord record = new SimpleRecord(123, "Bob");
397405

@@ -403,12 +411,14 @@ public void testSerializeSimpleRecord_DisableAnnotationIntrospector() throws Exc
403411
assertEquals("{\"id\":123,\"name\":\"Bob\"}", json);
404412
}
405413

414+
@Test
406415
public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws Exception {
407416
JsonMapper mapper = JsonMapper.builder().addModule(new AndroidRecordModule())
408417
.configure(MapperFeature.USE_ANNOTATIONS, false)
409418
.build();
410419

411-
Assert.assertThrows(InvalidDefinitionException.class, () -> mapper.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class));
420+
assertThrows(InvalidDefinitionException.class,
421+
() -> mapper.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class));
412422
}
413423

414424
/*
@@ -417,18 +427,21 @@ public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws E
417427
/**********************************************************************
418428
*/
419429

430+
@Test
420431
public void testSerializeJsonRename() throws Exception {
421432
String json = MAPPER.writeValueAsString(new RecordWithRename(123, "Bob"));
422433
final Object EXP = map("id", Integer.valueOf(123), "rename", "Bob");
423434
assertEquals(EXP, MAPPER.readValue(json, Object.class));
424435
}
425436

437+
@Test
426438
public void testDeserializeJsonRename() throws Exception {
427439
RecordWithRename value = MAPPER.readValue("{\"id\":123,\"rename\":\"Bob\"}",
428440
RecordWithRename.class);
429441
assertEquals(new RecordWithRename(123, "Bob"), value);
430442
}
431443

444+
@Test
432445
public void testDeserializeConstructorInjectRecord() throws Exception {
433446
ObjectReader r = MAPPER.readerFor(RecordWithConstructorInject.class)
434447
.with(new InjectableValues.Std().addValue(String.class, "Bob"));
@@ -444,6 +457,7 @@ public void testDeserializeConstructorInjectRecord() throws Exception {
444457
*/
445458

446459
// [databind#2992]
460+
@Test
447461
public void testNamingStrategy() throws Exception {
448462
SnakeRecord input = new SnakeRecord("123", "value");
449463

@@ -460,25 +474,29 @@ public void testNamingStrategy() throws Exception {
460474
/**********************************************************************
461475
*/
462476

477+
@Test
463478
public void testSerialize_SingleWriteOnlyParameter() throws Exception {
464479
String json = MAPPER.writeValueAsString(new RecordSingleWriteOnly(123));
465480

466481
assertEquals("{}", json);
467482
}
468483

469484
// [databind#3897]
485+
@Test
470486
public void testDeserialize_SingleWriteOnlyParameter() throws Exception {
471487
RecordSingleWriteOnly value = MAPPER.readValue("{\"id\":123}", RecordSingleWriteOnly.class);
472488

473489
assertEquals(new RecordSingleWriteOnly(123), value);
474490
}
475491

492+
@Test
476493
public void testSerialize_SomeWriteOnlyParameter() throws Exception {
477494
String json = MAPPER.writeValueAsString(new RecordSomeWriteOnly(123, "Bob", "[email protected]"));
478495

479496
assertEquals("{\"email\":\"[email protected]\"}", json);
480497
}
481498

499+
@Test
482500
public void testDeserialize_SomeWriteOnlyParameter() throws Exception {
483501
RecordSomeWriteOnly value = MAPPER.readValue(
484502
"{\"id\":123,\"name\":\"Bob\",\"email\":\"[email protected]\"}",
@@ -487,12 +505,14 @@ public void testDeserialize_SomeWriteOnlyParameter() throws Exception {
487505
assertEquals(new RecordSomeWriteOnly(123, "Bob", "[email protected]"), value);
488506
}
489507

508+
@Test
490509
public void testSerialize_AllWriteOnlyParameter() throws Exception {
491510
String json = MAPPER.writeValueAsString(new RecordAllWriteOnly(123, "Bob", "[email protected]"));
492511

493512
assertEquals("{}", json);
494513
}
495514

515+
@Test
496516
public void testDeserialize_AllWriteOnlyParameter() throws Exception {
497517
RecordAllWriteOnly value = MAPPER.readValue(
498518
"{\"id\":123,\"name\":\"Bob\",\"email\":\"[email protected]\"}",
@@ -508,6 +528,7 @@ public void testDeserialize_AllWriteOnlyParameter() throws Exception {
508528
*/
509529

510530
// Fails: converter not applied
531+
@Test
511532
public void testDeserializeJsonDeserializeRecord() throws Exception {
512533
RecordWithJsonDeserialize value = MAPPER.readValue("{\"id\":123,\"name\":\" Bob \"}",
513534
RecordWithJsonDeserialize.class);

android-record/src/test/java/tools/jackson/module/androidrecord/RecordCreatorsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package tools.jackson.module.androidrecord;
22

3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonValue;
3+
import org.junit.jupiter.api.Test;
54

65
import com.android.tools.r8.RecordTag;
76

7+
import com.fasterxml.jackson.annotation.JsonCreator;
8+
import com.fasterxml.jackson.annotation.JsonValue;
9+
810
import tools.jackson.databind.ObjectMapper;
911

12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
1014
public class RecordCreatorsTest extends BaseMapTest
1115
{
1216
static final class RecordWithCanonicalCtorOverride extends RecordTag {
@@ -58,6 +62,7 @@ public String accessValueForTest() {
5862
/**********************************************************************
5963
*/
6064

65+
@Test
6166
public void testDeserializeWithCanonicalCtorOverride() throws Exception {
6267
RecordWithCanonicalCtorOverride value = MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}",
6368
RecordWithCanonicalCtorOverride.class);
@@ -66,6 +71,7 @@ public void testDeserializeWithCanonicalCtorOverride() throws Exception {
6671
}
6772

6873
// [databind#2980]
74+
@Test
6975
public void testDeserializeWithDelegatingCtor() throws Exception {
7076
RecordWithDelegation value = MAPPER.readValue(q("foobar"),
7177
RecordWithDelegation.class);

0 commit comments

Comments
 (0)