Skip to content

Commit 1b7a759

Browse files
authored
Convert Afterburner tests to JUnit5 (part of #268) (#273)
1 parent 0f590b9 commit 1b7a759

File tree

83 files changed

+787
-114
lines changed

Some content is hidden

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

83 files changed

+787
-114
lines changed

afterburner/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ field access and method calls
6464
</dependency>
6565

6666
<dependency>
67-
<groupId>junit</groupId>
68-
<artifactId>junit</artifactId>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.junit.jupiter</groupId>
73+
<artifactId>junit-jupiter-api</artifactId>
6974
<scope>test</scope>
7075
</dependency>
7176
</dependencies>

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/AfterburnerModuleJDKSerializabilityTest.java

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

55
import com.fasterxml.jackson.databind.ObjectMapper;
66

7+
import static org.junit.jupiter.api.Assertions.*;
8+
79
public class AfterburnerModuleJDKSerializabilityTest extends AfterburnerTestBase
810
{
911
static class Point {

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/AfterburnerTestBase.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import com.fasterxml.jackson.databind.ObjectMapper;
99
import com.fasterxml.jackson.databind.json.JsonMapper;
1010

11-
public abstract class AfterburnerTestBase extends junit.framework.TestCase
11+
import static org.junit.jupiter.api.Assertions.fail;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
public abstract class AfterburnerTestBase
1215
{
1316
// // // First some "shared" classes from databind's `BaseMapTest`
1417

@@ -195,12 +198,6 @@ protected static JsonMapper newVanillaJSONMapper() {
195198
return new JsonMapper();
196199
}
197200

198-
@Deprecated
199-
protected ObjectMapper mapperWithModule()
200-
{
201-
return newObjectMapper();
202-
}
203-
204201
/*
205202
/**********************************************************
206203
/* Helper methods; assertions
@@ -236,7 +233,7 @@ protected void assertType(Object ob, Class<?> expType)
236233
* returning them
237234
*/
238235
protected String getAndVerifyText(JsonParser jp)
239-
throws IOException, JsonParseException
236+
throws IOException
240237
{
241238
// Ok, let's verify other accessors
242239
int actLen = jp.getTextLength();

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/TestAccessFallback.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.fasterxml.jackson.module.afterburner;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.databind.ObjectMapper;
46

7+
import static org.junit.jupiter.api.Assertions.*;
8+
59
public class TestAccessFallback extends AfterburnerTestBase
610
{
711
@SuppressWarnings("serial")
@@ -50,6 +54,7 @@ public String getE()
5054

5155
private static final String BEAN_JSON = "{\"e\":\"a\"}";
5256

57+
@Test
5358
public void testSerializeAccess() throws Exception
5459
{
5560
ObjectMapper abMapper = newObjectMapper();
@@ -59,6 +64,7 @@ public void testSerializeAccess() throws Exception
5964
assertEquals(BEAN_JSON, abMapper.writeValueAsString(new MyBean("a")));
6065
}
6166

67+
@Test
6268
public void testDeserializeAccess() throws Exception
6369
{
6470
ObjectMapper abMapper = newObjectMapper();

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/TestSealedPackages.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package com.fasterxml.jackson.module.afterburner;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.databind.ObjectMapper;
46

7+
import static org.junit.jupiter.api.Assertions.assertNotNull;
8+
59
/**
610
* Tests for [Issue#21]
711
*/
812
public class TestSealedPackages extends AfterburnerTestBase
913
{
1014
private final ObjectMapper MAPPER = newObjectMapper();
1115

16+
@Test
1217
public void testJavaStdDeserialization() throws Exception
1318
{
1419
String json = "{}";
1520
Exception e = MAPPER.readValue(json, Exception.class);
1621
assertNotNull(e);
1722
}
1823

24+
@Test
1925
public void testJavaStdSerialization() throws Exception
2026
{
2127
String json = MAPPER.writeValueAsString(Thread.currentThread().getThreadGroup());

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/TestUnwrapped.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.fasterxml.jackson.module.afterburner;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
46
import com.fasterxml.jackson.annotation.JsonUnwrapped;
7+
58
import com.fasterxml.jackson.databind.ObjectMapper;
69

10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
12+
713
public class TestUnwrapped extends AfterburnerTestBase
814
{
915
@JsonPropertyOrder({ "a", "b" })
@@ -34,6 +40,7 @@ public Unwrapped() { }
3440
/**********************************************************
3541
*/
3642

43+
@Test
3744
public void testSimpleSerialize() throws Exception
3845
{
3946
final ObjectMapper VANILLA = new ObjectMapper();
@@ -43,6 +50,7 @@ public void testSimpleSerialize() throws Exception
4350
assertEquals(json, BURNER.writeValueAsString(input));
4451
}
4552

53+
@Test
4654
public void testUnwrappedDeserialize() throws Exception
4755
{
4856
final ObjectMapper VANILLA = new ObjectMapper();
@@ -53,5 +61,4 @@ public void testUnwrappedDeserialize() throws Exception
5361
assertNotNull(out.b);
5462
assertEquals(9, out.b.value);
5563
}
56-
5764
}

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/TestVersions.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22

33
import java.io.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.core.Version;
68
import com.fasterxml.jackson.core.Versioned;
79

10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertFalse;
12+
813
/**
914
* Tests to verify that version information is properly accessible
1015
*/
1116
public class TestVersions extends AfterburnerTestBase
1217
{
18+
@Test
1319
public void testMapperVersions() throws IOException
1420
{
1521
AfterburnerModule module = new AfterburnerModule();
1622
assertVersion(module);
1723
}
1824

19-
/*
20-
/**********************************************************
21-
/* Helper methods
22-
/**********************************************************
23-
*/
24-
2525
private void assertVersion(Versioned vers)
2626
{
2727
Version v = vers.version();
28-
assertFalse("Should find version information (got "+v+")", v.isUnknownVersion());
28+
assertFalse(v.isUnknownVersion(),
29+
"Should find version information (got "+v+")");
2930
Version exp = PackageVersion.VERSION;
3031
assertEquals(exp.toFullString(), v.toFullString());
3132
assertEquals(exp, v);

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/codegen/GenerateWithMixinsTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.fasterxml.jackson.module.afterburner.codegen;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.annotation.JsonIgnore;
4-
import com.fasterxml.jackson.core.JsonProcessingException;
56
import com.fasterxml.jackson.databind.ObjectMapper;
67
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
78

@@ -45,12 +46,13 @@ public void setField3(byte[] field3) {
4546
}
4647
}
4748

48-
public abstract class IgnoreField3MixIn {
49-
@JsonIgnore
50-
public abstract byte[] getField3();
49+
public abstract static class IgnoreField3MixIn {
50+
@JsonIgnore
51+
public abstract byte[] getField3();
5152
}
5253

53-
public void testIssue51() throws JsonProcessingException
54+
@Test
55+
public void testIssue51() throws Exception
5456
{
5557
SampleObject sampleObject = new SampleObject("field1", 2, "field3".getBytes());
5658

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/deser/BasicDeserializeTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import java.util.List;
44

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

810
import com.fasterxml.jackson.databind.ObjectMapper;
911

1012
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
1113

14+
import static org.junit.jupiter.api.Assertions.*;
15+
1216
public class BasicDeserializeTest extends AfterburnerTestBase
1317
{
1418
public enum MyEnum {
@@ -169,12 +173,14 @@ public Model123 setValue(int value) {
169173
*/
170174

171175
private final ObjectMapper MAPPER = newObjectMapper();
172-
176+
177+
@Test
173178
public void testIntMethod() throws Exception {
174179
IntBean bean = MAPPER.readValue("{\"x\":13}", IntBean.class);
175180
assertEquals(13, bean._x);
176181
}
177182

183+
@Test
178184
public void testMultiIntMethod() throws Exception {
179185
IntsBean bean = MAPPER.readValue("{\"c\":3,\"a\":9,\"b\":111,\"e\":-9999,\"d\":1}", IntsBean.class);
180186
assertEquals(9, bean._a);
@@ -184,16 +190,19 @@ public void testMultiIntMethod() throws Exception {
184190
assertEquals(-9999, bean._e);
185191
}
186192

193+
@Test
187194
public void testLongMethod() throws Exception {
188195
LongBean bean = MAPPER.readValue("{\"x\":-1}", LongBean.class);
189196
assertEquals(-1, bean._x);
190197
}
191198

199+
@Test
192200
public void testStringMethod() throws Exception {
193201
StringBean bean = MAPPER.readValue("{\"x\":\"zoobar\"}", StringBean.class);
194202
assertEquals("zoobar", bean._x);
195203
}
196204

205+
@Test
197206
public void testObjectMethod() throws Exception {
198207
EnumBean bean = MAPPER.readValue("{\"x\":\"A\"}", EnumBean.class);
199208
assertEquals(MyEnum.A, bean._x);
@@ -205,16 +214,19 @@ public void testObjectMethod() throws Exception {
205214
/**********************************************************************
206215
*/
207216

217+
@Test
208218
public void testIntField() throws Exception {
209219
IntFieldBean bean = MAPPER.readValue("{\"value\":-92}", IntFieldBean.class);
210220
assertEquals(-92, bean.x);
211221
}
212222

223+
@Test
213224
public void testLongField() throws Exception {
214225
LongFieldBean bean = MAPPER.readValue("{\"value\":-92}", LongFieldBean.class);
215226
assertEquals(-92, bean.value);
216227
}
217228

229+
@Test
218230
public void testStringField() throws Exception {
219231
StringFieldBean bean = MAPPER.readValue("{\"x\":\"\"}", StringFieldBean.class);
220232
assertEquals("", bean.x);
@@ -224,12 +236,14 @@ public void testStringField() throws Exception {
224236
assertNull(bean.x);
225237
}
226238

239+
@Test
227240
public void testEnumField() throws Exception {
228241
EnumFieldBean bean = MAPPER.readValue("{\"x\":\"C\"}", EnumFieldBean.class);
229242
assertEquals(MyEnum.C, bean.x);
230243
}
231244

232245
// Verify [Issue#10], so that nulls do not get coerced to String "null"
246+
@Test
233247
public void testStringAsObjectField() throws Exception {
234248
StringAsObject bean = MAPPER.readValue("{\"value\":null}", StringAsObject.class);
235249
assertNotNull(bean);
@@ -242,6 +256,7 @@ public void testStringAsObjectField() throws Exception {
242256
/**********************************************************************
243257
*/
244258

259+
@Test
245260
public void testFiveMinuteDoc() throws Exception
246261
{
247262
FiveMinuteUser input = new FiveMinuteUser("First", "Name", true,
@@ -254,6 +269,7 @@ public void testFiveMinuteDoc() throws Exception
254269
}
255270
}
256271

272+
@Test
257273
public void testMixed() throws Exception
258274
{
259275
MixedBean bean = MAPPER.readValue("{"
@@ -278,6 +294,7 @@ public void testMixed() throws Exception
278294
}
279295

280296
// Test for [Issue-5]
297+
@Test
281298
public void testNonVoidProperty() throws Exception
282299
{
283300
final String json = "{ \"stringField\" : \"zoobar\", \"stringField2\" : \"barzoo\" }";
@@ -293,6 +310,7 @@ public void testNonVoidProperty() throws Exception
293310
}
294311

295312
// Test for [module-afterburner#16]
313+
@Test
296314
public void testBigNonVoidProperty() throws Exception
297315
{
298316
final String json = "{ \"stringField\" : \"zoobar\" }";
@@ -307,12 +325,14 @@ public void testBigNonVoidProperty() throws Exception
307325
}
308326

309327
// NOTE: failed with databind-2.5.0; fixed for 2.5.1
328+
@Test
310329
public void testStringBuilder() throws Exception
311330
{
312331
StringBuilder sb = MAPPER.readValue(quote("foobar"), StringBuilder.class);
313332
assertEquals("foobar", sb.toString());
314333
}
315334

335+
@Test
316336
public void testBooleans() throws Exception
317337
{
318338
BooleansBean bean = MAPPER.readValue(aposToQuotes("{'a':true, 'b':true}"),
@@ -323,6 +343,7 @@ public void testBooleans() throws Exception
323343
}
324344

325345
// for [module-afterburner#60] (caused by a bug in jackson-core up to 2.6.2, fixed in 2.6.3)
346+
@Test
326347
public void testProblemWithIndentation() throws Exception {
327348
final String JSON = "{\n"
328349
+" \"foos\" :\n"
@@ -345,6 +366,7 @@ public void testProblemWithIndentation() throws Exception {
345366
}
346367

347368
// [modules-base#123]
369+
@Test
348370
public void testFluentMethod() throws Exception
349371
{
350372
String json = MAPPER.writeValueAsString(new Model123(28));

afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/deser/GenericPropertyDeserializationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.fasterxml.jackson.module.afterburner.deser;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.databind.ObjectMapper;
46
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
57

8+
import static org.junit.jupiter.api.Assertions.*;
9+
610
public class GenericPropertyDeserializationTest extends AfterburnerTestBase
711
{
812
static abstract class AbstractMyClass<ID> {
@@ -31,6 +35,7 @@ public MyClass() { }
3135

3236
final private ObjectMapper MAPPER = newObjectMapper();
3337

38+
@Test
3439
public void testGenericIssue4() throws Exception
3540
{
3641
MyClass result = MAPPER.readValue("{\"id\":\"foo\"}", MyClass.class);

0 commit comments

Comments
 (0)