Skip to content

Commit 3bd2338

Browse files
authored
Update to JUnit 5 and fix tests (#72)
* Update to JUnit 5 and fix tests - Updated dependency. The version is still managed by the parent. - Tests no longer extend TestCase - Annotated test methods with `@Test`. - Made classes and test methods package-private, as it is recommended. * Add GitHub Action to run tests automatically - This excludes master, since the maven_release.yaml workflow already tests master.
1 parent 79a8cad commit 3bd2338

15 files changed

+262
-164
lines changed

.github/workflows/maven_test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- master
7+
8+
jobs:
9+
test:
10+
name: Test
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- name: Set up JDK 8
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: 8
20+
distribution: 'temurin'
21+
- name: Cache Maven packages
22+
uses: actions/cache@v3
23+
with:
24+
path: ~/.m2
25+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
26+
restore-keys: ${{ runner.os }}-m2
27+
- name: Build and Test
28+
run: mvn clean verify

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
<scope>test</scope>
6060
</dependency>
6161
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
62+
<groupId>org.junit.jupiter</groupId>
63+
<artifactId>junit-jupiter-api</artifactId>
6464
<scope>test</scope>
6565
</dependency>
6666
</dependencies>

src/test/java/org/openapitools/jackson/nullable/ContextualJsonNullableTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import com.fasterxml.jackson.annotation.JsonFormat;
44
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import org.junit.jupiter.api.Test;
67

78
import java.text.SimpleDateFormat;
89
import java.util.Date;
910
import java.util.TimeZone;
1011

11-
public class ContextualJsonNullableTest extends ModuleTestBase
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
class ContextualJsonNullableTest extends ModuleTestBase
1215
{
1316
// [datatypes-java8#17]
1417
@JsonPropertyOrder({ "date", "date1", "date2" })
@@ -29,7 +32,8 @@ static class ContextualJsonNullables
2932
/**********************************************************
3033
*/
3134

32-
public void testContextualJsonNullables() throws Exception
35+
@Test
36+
void testContextualJsonNullables() throws Exception
3337
{
3438
final ObjectMapper mapper = mapperWithModule();
3539
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");

src/test/java/org/openapitools/jackson/nullable/CreatorTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import org.junit.Ignore;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
710

811
// TODO: fix JsonNullable in constructor annotated by JsonCreator
9-
@Ignore("JsonNullable in a constructor is dederialized to JsonNullable[null] instead of JsonNullable.undefined")
10-
public class CreatorTest extends ModuleTestBase
12+
@Disabled("JsonNullable in a constructor is dederialized to JsonNullable[null] instead of JsonNullable.undefined")
13+
class CreatorTest extends ModuleTestBase
1114
{
1215
static class CreatorWithJsonNullableStrings
1316
{
@@ -35,7 +38,8 @@ public CreatorWithJsonNullableStrings(@JsonProperty("a") JsonNullable<String> a,
3538
* Test to ensure that creator parameters use defaulting
3639
* (introduced in Jackson 2.6)
3740
*/
38-
public void testCreatorWithJsonNullable() throws Exception
41+
@Test
42+
void testCreatorWithJsonNullable() throws Exception
3943
{
4044
CreatorWithJsonNullableStrings bean = MAPPER.readValue(
4145
aposToQuotes("{'a':'foo'}"), CreatorWithJsonNullableStrings.class);

src/test/java/org/openapitools/jackson/nullable/JsonNullJacksonServiceLoadingTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44

5-
import junit.framework.TestCase;
5+
import org.junit.jupiter.api.Test;
66

7-
public class JsonNullJacksonServiceLoadingTest extends TestCase {
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
88

9-
public void testJacksonJsonNullableModuleServiceLoading() {
9+
class JsonNullJacksonServiceLoadingTest {
10+
11+
@Test
12+
void testJacksonJsonNullableModuleServiceLoading() {
1013
String foundModuleName = ObjectMapper.findModules().get(0).getModuleName();
1114
assertEquals(new JsonNullableModule().getModuleName(), foundModuleName);
1215
}

src/test/java/org/openapitools/jackson/nullable/JsonNullWithEmptyTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.jupiter.api.Test;
56

6-
public class JsonNullWithEmptyTest extends ModuleTestBase
7+
import static org.junit.jupiter.api.Assertions.assertFalse;
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
10+
class JsonNullWithEmptyTest extends ModuleTestBase
711
{
812
private final ObjectMapper MAPPER = mapperWithModule();
913

@@ -16,14 +20,15 @@ public BooleanBean(Boolean b) {
1620
}
1721
}
1822

19-
public void testJsonNullableFromEmpty() throws Exception {
23+
@Test
24+
void testJsonNullableFromEmpty() throws Exception {
2025
JsonNullable<?> value = MAPPER.readValue(quote(""), new TypeReference<JsonNullable<Integer>>() {});
2126
assertFalse(value.isPresent());
2227
}
2328

2429
// for [datatype-jdk8#23]
25-
public void testBooleanWithEmpty() throws Exception
26-
{
30+
@Test
31+
void testBooleanWithEmpty() throws Exception {
2732
// and looks like a special, somewhat non-conforming case is what a user had
2833
// issues with
2934
BooleanBean b = MAPPER.readValue(aposToQuotes("{'value':''}"), BooleanBean.class);

src/test/java/org/openapitools/jackson/nullable/JsonNullableBasicTest.java

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import com.fasterxml.jackson.core.type.TypeReference;
55
import com.fasterxml.jackson.databind.JavaType;
66
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import org.junit.jupiter.api.Test;
78

89
import java.util.ArrayList;
910
import java.util.List;
1011

11-
public class JsonNullableBasicTest extends ModuleTestBase {
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
class JsonNullableBasicTest extends ModuleTestBase {
1215

1316
public static final class JsonNullableData {
1417
public JsonNullable<String> myString;
@@ -58,37 +61,42 @@ public static class ContainedImpl implements Contained { }
5861

5962
private final ObjectMapper MAPPER = mapperWithModule();
6063

61-
public void testJsonNullableTypeResolution() throws Exception {
64+
@Test
65+
void testJsonNullableTypeResolution() {
6266
// With 2.6, we need to recognize it as ReferenceType
6367
JavaType t = MAPPER.constructType(JsonNullable.class);
6468
assertNotNull(t);
6569
assertEquals(JsonNullable.class, t.getRawClass());
6670
assertTrue(t.isReferenceType());
6771
}
6872

69-
public void testDeserAbsent() throws Exception {
73+
@Test
74+
void testDeserAbsent() throws Exception {
7075
JsonNullable<?> value = MAPPER.readValue("null",
7176
new TypeReference<JsonNullable<String>>() {
7277
});
7378
assertNull(value.get());
7479
}
7580

76-
public void testDeserSimpleString() throws Exception {
81+
@Test
82+
void testDeserSimpleString() throws Exception {
7783
JsonNullable<?> value = MAPPER.readValue("\"simpleString\"",
7884
new TypeReference<JsonNullable<String>>() {
7985
});
8086
assertTrue(value.isPresent());
8187
assertEquals("simpleString", value.get());
8288
}
8389

84-
public void testDeserInsideObject() throws Exception {
90+
@Test
91+
void testDeserInsideObject() throws Exception {
8592
JsonNullableData data = MAPPER.readValue("{\"myString\":\"simpleString\"}",
8693
JsonNullableData.class);
8794
assertTrue(data.myString.isPresent());
8895
assertEquals("simpleString", data.myString.get());
8996
}
9097

91-
public void testDeserComplexObject() throws Exception {
98+
@Test
99+
void testDeserComplexObject() throws Exception {
92100
TypeReference<JsonNullable<JsonNullableData>> type = new TypeReference<JsonNullable<JsonNullableData>>() {
93101
};
94102
JsonNullable<JsonNullableData> data = MAPPER.readValue(
@@ -98,7 +106,8 @@ public void testDeserComplexObject() throws Exception {
98106
assertEquals("simpleString", data.get().myString.get());
99107
}
100108

101-
public void testDeserGeneric() throws Exception {
109+
@Test
110+
void testDeserGeneric() throws Exception {
102111
TypeReference<JsonNullable<JsonNullableGenericData<String>>> type = new TypeReference<JsonNullable<JsonNullableGenericData<String>>>() {
103112
};
104113
JsonNullable<JsonNullableGenericData<String>> data = MAPPER.readValue(
@@ -108,62 +117,71 @@ public void testDeserGeneric() throws Exception {
108117
assertEquals("simpleString", data.get().myData.get());
109118
}
110119

111-
public void testSerAbsent() throws Exception {
120+
@Test
121+
void testSerAbsent() throws Exception {
112122
String value = MAPPER.writeValueAsString(JsonNullable.undefined());
113123
assertEquals("null", value);
114124
}
115125

116-
public void testSerSimpleString() throws Exception {
126+
@Test
127+
void testSerSimpleString() throws Exception {
117128
String value = MAPPER.writeValueAsString(JsonNullable.of("simpleString"));
118129
assertEquals("\"simpleString\"", value);
119130
}
120131

121-
public void testSerInsideObject() throws Exception {
132+
@Test
133+
void testSerInsideObject() throws Exception {
122134
JsonNullableData data = new JsonNullableData();
123135
data.myString = JsonNullable.of("simpleString");
124136
String value = MAPPER.writeValueAsString(data);
125137
assertEquals("{\"myString\":\"simpleString\"}", value);
126138
}
127139

128-
public void testSerComplexObject() throws Exception {
140+
@Test
141+
void testSerComplexObject() throws Exception {
129142
JsonNullableData data = new JsonNullableData();
130143
data.myString = JsonNullable.of("simpleString");
131144
String value = MAPPER.writeValueAsString(JsonNullable.of(data));
132145
assertEquals("{\"myString\":\"simpleString\"}", value);
133146
}
134147

135-
public void testSerGeneric() throws Exception {
148+
@Test
149+
void testSerGeneric() throws Exception {
136150
JsonNullableGenericData<String> data = new JsonNullableGenericData<String>();
137151
data.myData = JsonNullable.of("simpleString");
138152
String value = MAPPER.writeValueAsString(JsonNullable.of(data));
139153
assertEquals("{\"myData\":\"simpleString\"}", value);
140154
}
141155

142-
public void testSerOptDefault() throws Exception {
156+
@Test
157+
void testSerOptDefault() throws Exception {
143158
JsonNullableData data = new JsonNullableData();
144159
data.myString = JsonNullable.undefined();
145160
String value = mapperWithModule().setSerializationInclusion(
146161
JsonInclude.Include.ALWAYS).writeValueAsString(data);
147162
assertEquals("{}", value);
148163
}
149164

150-
public void testSerOptNull() throws Exception {
165+
@Test
166+
void testSerOptNull() throws Exception {
151167
JsonNullableData data = new JsonNullableData();
152168
data.myString = null;
153169
String value = mapperWithModule().setSerializationInclusion(
154170
JsonInclude.Include.NON_NULL).writeValueAsString(data);
155171
assertEquals("{}", value);
156172
}
157173

158-
public void testSerOptNullNulled() throws Exception {
174+
@Test
175+
void testSerOptNullNulled() throws Exception {
159176
JsonNullableData data = new JsonNullableData();
160177
data.myString = JsonNullable.of(null);
161178
String value = mapperWithModule().setSerializationInclusion(
162179
JsonInclude.Include.NON_NULL).writeValueAsString(data);
163180
assertEquals("{\"myString\":null}", value);
164181
}
165182

166-
public void testSerOptAbsent() throws Exception {
183+
@Test
184+
void testSerOptAbsent() throws Exception {
167185
final JsonNullableData data = new JsonNullableData();
168186
data.myString = JsonNullable.undefined();
169187

@@ -183,23 +201,26 @@ public void testSerOptAbsent() throws Exception {
183201
assertEquals("{}", mapper.writeValueAsString(data));
184202
}
185203

186-
public void testSerOptAbsentNull() throws Exception {
204+
@Test
205+
void testSerOptAbsentNull() throws Exception {
187206
JsonNullableData data = new JsonNullableData();
188207
data.myString = JsonNullable.of(null);
189208
String value = mapperWithModule().setSerializationInclusion(
190209
JsonInclude.Include.NON_ABSENT).writeValueAsString(data);
191210
assertEquals("{\"myString\":null}", value);
192211
}
193212

194-
public void testSerOptNonEmpty() throws Exception {
213+
@Test
214+
void testSerOptNonEmpty() throws Exception {
195215
JsonNullableData data = new JsonNullableData();
196216
data.myString = null;
197217
String value = mapperWithModule().setSerializationInclusion(
198218
JsonInclude.Include.NON_EMPTY).writeValueAsString(data);
199219
assertEquals("{}", value);
200220
}
201221

202-
public void testWithTypingEnabled() throws Exception {
222+
@Test
223+
void testWithTypingEnabled() throws Exception {
203224
final ObjectMapper objectMapper = mapperWithModule();
204225
// ENABLE TYPING
205226
objectMapper
@@ -214,7 +235,8 @@ public void testWithTypingEnabled() throws Exception {
214235
assertEquals(myData.myString, deserializedMyData.myString);
215236
}
216237

217-
public void testObjectId() throws Exception {
238+
@Test
239+
void testObjectId() throws Exception {
218240
final Unit input = new Unit();
219241
input.link(input);
220242
String json = MAPPER.writeValueAsString(input);
@@ -226,7 +248,8 @@ public void testObjectId() throws Exception {
226248
assertSame(result, base);
227249
}
228250

229-
public void testJsonNullableCollection() throws Exception {
251+
@Test
252+
void testJsonNullableCollection() throws Exception {
230253

231254
TypeReference<List<JsonNullable<String>>> typeReference = new TypeReference<List<JsonNullable<String>>>() {
232255
};
@@ -242,17 +265,18 @@ public void testJsonNullableCollection() throws Exception {
242265
List<JsonNullable<String>> result = MAPPER.readValue(str, typeReference);
243266
assertEquals(list.size(), result.size());
244267
for (int i = 0; i < list.size(); ++i) {
245-
assertEquals("Entry #" + i, list.get(i), result.get(i));
268+
assertEquals(list.get(i), result.get(i),"Entry #" + i);
246269
}
247270
}
248271

249-
public void testDeserNull() throws Exception {
272+
@Test
273+
void testDeserNull() throws Exception {
250274
JsonNullable<?> value = MAPPER.readValue("\"\"", new TypeReference<JsonNullable<Integer>>() {});
251275
assertFalse(value.isPresent());
252276
}
253277

254-
public void testPolymorphic() throws Exception
255-
{
278+
@Test
279+
void testPolymorphic() throws Exception {
256280
final Container dto = new Container();
257281
dto.contained = JsonNullable.of((Contained) new ContainedImpl());
258282

0 commit comments

Comments
 (0)