Skip to content

Commit 7d73a44

Browse files
authored
[JSTEP-10] Migrate all tests to JUnit 5 (#54)
1 parent e14eb23 commit 7d73a44

37 files changed

+336
-175
lines changed

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/DeserViaCreatorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import jakarta.json.JsonObject;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonCreator;
68
import com.fasterxml.jackson.annotation.JsonProperty;
79
import com.fasterxml.jackson.databind.ObjectMapper;
810

11+
import static org.junit.jupiter.api.Assertions.*;
12+
913
public class DeserViaCreatorTest extends TestBase
1014
{
1115
static class Pojo {
@@ -19,6 +23,7 @@ public Pojo(@JsonProperty("s") String s, @JsonProperty("o") JsonObject o) {
1923
}
2024
}
2125

26+
@Test
2227
public void testCreatorDeser() throws Exception
2328
{
2429
final ObjectMapper mapper = sharedMapper();

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonMergePatchDeserializationTest.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,75 +9,81 @@
99
import jakarta.json.JsonValue;
1010
import java.util.Objects;
1111

12-
import static org.hamcrest.CoreMatchers.instanceOf;
13-
import static org.hamcrest.CoreMatchers.is;
14-
import static org.hamcrest.MatcherAssert.assertThat;
12+
import org.junit.jupiter.api.Test;
13+
14+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
15+
import static org.junit.jupiter.api.Assertions.*;
1516

1617
public class JsonMergePatchDeserializationTest extends TestBase {
1718

1819
private static final ObjectMapper MAPPER = newMapper();
1920

21+
@Test
2022
public void testObjectDeserializationAndPatching() throws Exception {
2123
final String json = "{" +
2224
"\"name\":\"Json\"" +
2325
"}";
2426

2527
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
2628
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
27-
assertThat(jsonPatchAsJsonValue, instanceOf(JsonObject.class));
29+
assertInstanceOf(JsonObject.class, jsonPatchAsJsonValue);
2830

2931
final JsonObject jsonPatchAsJsonObject = jsonPatchAsJsonValue.asJsonObject();
3032
assertTrue(jsonPatchAsJsonObject.containsKey("name"));
31-
assertThat(jsonPatchAsJsonObject.get("name"), instanceOf(JsonString.class));
32-
assertThat(jsonPatchAsJsonObject.getString("name"), is("Json"));
33+
assertInstanceOf(JsonString.class, jsonPatchAsJsonObject.get("name"));
34+
assertEquals("Json", jsonPatchAsJsonObject.getString("name"));
35+
3336

34-
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
37+
assertEquals(json, serializeAsString(jsonPatchAsJsonValue));
3538

3639
final Person person = new Person("John", "Smith");
3740
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
3841
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
3942
final Person patchedPerson = MAPPER.convertValue(patchedPersonJson, Person.class);
40-
assertThat(patchedPerson, is(new Person("Json", "Smith")));
43+
assertEquals(new Person("Json", "Smith"), patchedPerson);
4144
}
4245

46+
@Test
4347
public void testArrayDeserializationAndPatching() throws Exception {
4448
final String json = "[" +
4549
"\"name\",\"Json\"" +
4650
"]";
4751

4852
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
4953
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
50-
assertThat(jsonPatchAsJsonValue, instanceOf(JsonArray.class));
54+
assertThat(jsonPatchAsJsonValue).isInstanceOf(JsonArray.class);
55+
5156

5257
final JsonArray jsonPatchAsJsonArray = jsonPatchAsJsonValue.asJsonArray();
53-
assertThat(jsonPatchAsJsonArray.size(), is(2));
54-
assertThat(jsonPatchAsJsonArray.get(0), instanceOf(JsonString.class));
55-
assertThat(((JsonString)jsonPatchAsJsonArray.get(0)).getString(), is("name"));
56-
assertThat(jsonPatchAsJsonArray.get(1), instanceOf(JsonString.class));
57-
assertThat(((JsonString)jsonPatchAsJsonArray.get(1)).getString(), is("Json"));
58+
assertThat(jsonPatchAsJsonArray.size()).isEqualTo(2);
59+
assertThat(jsonPatchAsJsonArray.get(0)).isInstanceOf(JsonString.class);
60+
assertThat(((JsonString) jsonPatchAsJsonArray.get(0)).getString()).isEqualTo("name");
61+
assertThat(jsonPatchAsJsonArray.get(1)).isInstanceOf(JsonString.class);
62+
assertThat(((JsonString) jsonPatchAsJsonArray.get(1)).getString()).isEqualTo("Json");
5863

59-
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
64+
assertThat(serializeAsString(jsonPatchAsJsonValue)).isEqualTo(json);
6065

6166
final Person person = new Person("John", "Smith");
6267
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
6368
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
64-
assertThat(patchedPersonJson, instanceOf(JsonArray.class));
69+
assertThat(patchedPersonJson).isInstanceOf(JsonArray.class);
6570
}
6671

72+
@Test
6773
public void testScalarDeserializationAndPatching() throws Exception {
6874
final String json = "\"name\"";
6975

7076
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
7177
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
72-
assertThat(jsonPatchAsJsonValue, instanceOf(JsonString.class));
78+
assertThat(jsonPatchAsJsonValue).isInstanceOf(JsonString.class);
7379

74-
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
80+
assertThat(serializeAsString(jsonPatchAsJsonValue)).isEqualTo(json);
7581

7682
final Person person = new Person("John", "Smith");
7783
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
7884
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
79-
assertThat(patchedPersonJson, instanceOf(JsonString.class));
80-
assertThat(((JsonString)patchedPersonJson).getString(), is("name"));
85+
assertThat(patchedPersonJson).isInstanceOf(JsonString.class);
86+
assertThat(((JsonString) patchedPersonJson).getString()).isEqualTo("name");
8187
}
8288

8389
static class Person {

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonMergePatchSerializationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
import jakarta.json.JsonMergePatch;
66

7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
711
public class JsonMergePatchSerializationTest extends TestBase
812
{
913
private static final ObjectMapper MAPPER = newMapper();
1014

15+
@Test
1116
public void testSimpleSerialization() throws Exception
1217
{
1318
// First need a patch so deserialization must work

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonPatchDeserializationTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
import java.util.Objects;
88

9-
import static org.hamcrest.CoreMatchers.instanceOf;
10-
import static org.hamcrest.CoreMatchers.is;
11-
import static org.hamcrest.MatcherAssert.assertThat;
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
12+
import static org.junit.jupiter.api.Assertions.*;
1213

1314
public class JsonPatchDeserializationTest extends TestBase {
1415

1516
private static final ObjectMapper MAPPER = newMapper();
1617

18+
@Test
1719
public void testDeserializationAndPatching() throws Exception {
1820
final String json = "[" +
1921
"{" +
@@ -25,28 +27,28 @@ public void testDeserializationAndPatching() throws Exception {
2527

2628
final JsonPatch jsonPatch = MAPPER.readValue(json, JsonPatch.class);
2729
final JsonArray jsonPatchAsJsonArray = jsonPatch.toJsonArray();
28-
assertThat(jsonPatchAsJsonArray.get(0), instanceOf(JsonObject.class));
30+
assertThat(jsonPatchAsJsonArray.get(0)).isInstanceOf(JsonObject.class);
2931

3032
final JsonObject firstOperation = jsonPatchAsJsonArray.get(0).asJsonObject();
3133
assertTrue(firstOperation.containsKey("op"));
32-
assertThat(firstOperation.get("op"), instanceOf(JsonString.class));
33-
assertThat(firstOperation.getString("op"), is("replace"));
34+
assertThat(firstOperation.get("op")).isInstanceOf(JsonString.class);
35+
assertThat(firstOperation.getString("op")).isEqualTo("replace");
3436

3537
assertTrue(firstOperation.containsKey("path"));
36-
assertThat(firstOperation.get("path"), instanceOf(JsonString.class));
37-
assertThat(firstOperation.getString("path"), is("/name"));
38+
assertThat(firstOperation.get("path")).isInstanceOf(JsonString.class);
39+
assertThat(firstOperation.getString("path")).isEqualTo("/name");
3840

3941
assertTrue(firstOperation.containsKey("value"));
40-
assertThat(firstOperation.get("value"), instanceOf(JsonString.class));
41-
assertThat(firstOperation.getString("value"), is("Json"));
42+
assertThat(firstOperation.get("value")).isInstanceOf(JsonString.class);
43+
assertThat(firstOperation.getString("value")).isEqualTo("Json");
4244

43-
assertThat(serializeAsString(jsonPatchAsJsonArray), is(json));
45+
assertThat(serializeAsString(jsonPatchAsJsonArray)).isEqualTo(json);
4446

4547
final Person person = new Person("John", "Smith");
4648
final JsonStructure personJson = MAPPER.convertValue(person, JsonStructure.class);
4749
final JsonStructure patchedPersonJson = jsonPatch.apply(personJson);
4850
final Person patchedPerson = MAPPER.convertValue(patchedPersonJson, Person.class);
49-
assertThat(patchedPerson, is(new Person("Json", "Smith")));
51+
assertThat(patchedPerson).isEqualTo(new Person("Json", "Smith"));
5052
}
5153

5254
static class Person {

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonPatchSerializationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
import jakarta.json.JsonPatch;
66

7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
711
public class JsonPatchSerializationTest extends TestBase
812
{
913
private static final ObjectMapper MAPPER = newMapper();
1014

15+
@Test
1116
public void testSimpleSerialization() throws Exception
1217
{
1318
// First need a patch so deserialization must work

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonValueDeserializationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import jakarta.json.*;
44
import jakarta.json.JsonValue.ValueType;
55

6+
import org.junit.jupiter.api.Test;
7+
68
import com.fasterxml.jackson.databind.ObjectMapper;
79
import com.fasterxml.jackson.databind.node.ObjectNode;
810

911
import java.beans.ConstructorProperties;
1012
import java.math.BigDecimal;
1113

14+
import static org.junit.jupiter.api.Assertions.*;
15+
1216
public class JsonValueDeserializationTest extends TestBase
1317
{
1418
static class ObjectImpl {
@@ -24,6 +28,7 @@ public ObjectImpl(JsonValue obj1, JsonValue obj2) {
2428

2529
private final ObjectMapper MAPPER = newMapper();
2630

31+
@Test
2732
public void testSimpleArray() throws Exception
2833
{
2934
final String JSON = "[1,true,\"foo\"]";
@@ -43,6 +48,7 @@ public void testSimpleArray() throws Exception
4348
assertEquals(JSON, serializeAsString(v));
4449
}
4550

51+
@Test
4652
public void testNestedArray() throws Exception
4753
{
4854
final String JSON = "[1,[false,45],{\"foo\":13}]";
@@ -58,6 +64,7 @@ public void testNestedArray() throws Exception
5864
assertEquals(JSON, serializeAsString(v));
5965
}
6066

67+
@Test
6168
public void testSimpleObject() throws Exception
6269
{
6370
final String JSON = "{\"a\":12.5,\"b\":\"Text\"}";
@@ -79,6 +86,7 @@ public void testSimpleObject() throws Exception
7986
assertEquals(JSON, serializeAsString(v));
8087
}
8188

89+
@Test
8290
public void testNestedObject() throws Exception
8391
{
8492
final String JSON = "{\"array\":[1,2],\"obj\":{\"first\":true}}";
@@ -101,6 +109,7 @@ public void testNestedObject() throws Exception
101109
}
102110

103111
// for [datatype-jsr353#5]
112+
@Test
104113
public void testBinaryNode() throws Exception
105114
{
106115
ObjectNode root = MAPPER.createObjectNode();
@@ -116,6 +125,7 @@ public void testBinaryNode() throws Exception
116125
}
117126

118127
// for [datatype-jsr353#16]
128+
@Test
119129
public void testNullNode() throws Exception
120130
{
121131
final String serializedNull = MAPPER.writeValueAsString(JsonValue.NULL);
@@ -125,6 +135,7 @@ public void testNullNode() throws Exception
125135
}
126136

127137
// for [datatype-jsr353#19]
138+
@Test
128139
public void testConstructorProperties() throws Exception
129140
{
130141
ObjectImpl ob = MAPPER.readValue("{\"obj1\":{}}", ObjectImpl.class);
@@ -136,6 +147,7 @@ public void testConstructorProperties() throws Exception
136147
assertSame(JsonValue.NULL, ob2.obj2);
137148
}
138149

150+
@Test
139151
public void testBigInteger() throws Exception
140152
{
141153
final String JSON = "[2e308]";

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonValueSerializationTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
import jakarta.json.*;
66

7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
711
public class JsonValueSerializationTest extends TestBase
812
{
13+
@Test
914
public void testSimpleArray() throws Exception
1015
{
1116
JsonArray arr = arrayBuilder()
@@ -17,6 +22,7 @@ public void testSimpleArray() throws Exception
1722
assertEquals("[true,null,123,15.25]", serializeAsString(arr));
1823
}
1924

25+
@Test
2026
public void testNestedArray() throws Exception
2127
{
2228
JsonArray arr = arrayBuilder()
@@ -27,6 +33,7 @@ public void testNestedArray() throws Exception
2733
assertEquals("[1,[false,45],{\"foo\":13}]", serializeAsString(arr));
2834
}
2935

36+
@Test
3037
public void testSimpleObject() throws Exception
3138
{
3239
JsonObject ob = objectBuilder()
@@ -37,6 +44,7 @@ public void testSimpleObject() throws Exception
3744
assertEquals("{\"a\":123,\"b\":\"Text\"}", serializeAsString(ob));
3845
}
3946

47+
@Test
4048
public void testNestedObject() throws Exception
4149
{
4250
JsonObject ob = objectBuilder()

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/PolymorphicTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import jakarta.json.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonTypeInfo;
68
import com.fasterxml.jackson.databind.ObjectMapper;
79

10+
import static org.junit.jupiter.api.Assertions.*;
11+
812
public class PolymorphicTest extends TestBase
913
{
1014
static class Wrapper {
@@ -19,6 +23,7 @@ public Wrapper() { }
1923
.polymorphicTypeValidator(new NoCheckSubTypeValidator())
2024
.build();
2125

26+
@Test
2227
public void testObjectAsTyped() throws Exception
2328
{
2429
final String INPUT = "{\"array\":[1,2],\"obj\":{\"first\":true}}";
@@ -36,6 +41,7 @@ public void testObjectAsTyped() throws Exception
3641
assertEquals(1, arr.getInt(0));
3742
}
3843

44+
@Test
3945
public void testArrayAsTyped() throws Exception
4046
{
4147
final String INPUT = "[1,{\"a\":true}]";

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/TestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.fasterxml.jackson.databind.json.JsonMapper;
1010
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
1111

12-
public abstract class TestBase extends junit.framework.TestCase
12+
public abstract class TestBase
1313
{
1414
static class NoCheckSubTypeValidator
1515
extends PolymorphicTypeValidator.Base

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/TestVersions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
import com.fasterxml.jackson.core.Version;
66
import com.fasterxml.jackson.core.Versioned;
77

8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
812
public class TestVersions extends TestBase
913
{
14+
@Test
1015
public void testModuleVersionAndName() throws IOException
1116
{
1217
JSONPModule module = new JSONPModule();

0 commit comments

Comments
 (0)