Skip to content

Commit 6fc831f

Browse files
committed
Convert from JUnit 4 to JUnit 5
1 parent 5800a58 commit 6fc831f

45 files changed

Lines changed: 373 additions & 135 deletions

Some content is hidden

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

‎VERSION.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Java ClassMate project: licensed under Apache License 2.0
33

44
Release notes:
55

6+
1.8.1 (not yet released)
7+
8+
- Upgrade to JUnit 5
9+
610
1.8.0 (10-Oct-2026)
711

812
#125: Generic array types compare equal and collide in the resolver cache

‎pom.xml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ com.fasterxml.classmate.*;version=${project.version}
5656
</organization>
5757

5858
<dependencies>
59-
<!-- and for testing, JUnit is needed -->
59+
<!-- and for testing, JUnit 5 is needed -->
6060
<dependency>
61-
<groupId>junit</groupId>
62-
<artifactId>junit</artifactId>
63-
<version>${version.junit}</version>
61+
<groupId>org.junit.jupiter</groupId>
62+
<artifactId>junit-jupiter</artifactId>
63+
<version>${version.junit5}</version>
6464
<scope>test</scope>
6565
</dependency>
6666
</dependencies>

‎src/test/java/com/fasterxml/classmate/AnnotationInclusionTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.fasterxml.classmate;
22

3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
36
public class AnnotationInclusionTest
47
extends BaseTest
58
{
9+
@Test
610
public void testValues() { // stupid test for code coverage (being pedantic here)
711
includesEnum(AnnotationInclusion.DONT_INCLUDE);
812
includesEnum(AnnotationInclusion.INCLUDE_AND_INHERIT);

‎src/test/java/com/fasterxml/classmate/AnnotationsTest.java‎

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
package com.fasterxml.classmate;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.lang.annotation.Annotation;
66
import java.lang.annotation.Retention;
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.reflect.Method;
99

10-
import static org.junit.Assert.*;
10+
import static org.junit.jupiter.api.Assertions.*;
1111

1212
public class AnnotationsTest
1313
{
1414
@Retention(RetentionPolicy.RUNTIME)
1515
private static @interface Marker { }
1616

17-
@Test @Marker
17+
// Annotation with a property, to verify `toString()` output
18+
@Retention(RetentionPolicy.RUNTIME)
19+
private static @interface Configured {
20+
int timeout() default 0;
21+
}
22+
23+
@Test @Marker @Configured
1824
public void addAsDefault() throws Exception {
1925
Annotations annotations = new Annotations();
2026
Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault");
2127

22-
assertNull(annotations.get(Test.class));
28+
assertNull(annotations.get(Configured.class));
2329
assertNull(annotations.get(Marker.class));
2430

25-
Annotation testAnnotation = thisMethod.getAnnotation(Test.class);
31+
Annotation testAnnotation = thisMethod.getAnnotation(Configured.class);
2632
annotations.addAsDefault(testAnnotation);
2733

2834
Annotation markerAnnotation = thisMethod.getAnnotation(Marker.class);
2935
annotations.addAsDefault(markerAnnotation);
3036

31-
assertNotNull(annotations.get(Test.class));
37+
assertNotNull(annotations.get(Configured.class));
3238
assertNotNull(annotations.get(Marker.class));
3339

3440
assertEquals(2, annotations.size());
@@ -43,7 +49,7 @@ public void size() throws Exception {
4349

4450
assertEquals(0, annotations.size());
4551

46-
Annotation testAnnotation = thisMethod.getAnnotation(Test.class);
52+
Annotation testAnnotation = thisMethod.getAnnotation(Configured.class);
4753
annotations.addAsDefault(testAnnotation);
4854

4955
assertEquals(1, annotations.size());
@@ -61,20 +67,14 @@ public void annotationsToSize() throws Exception {
6167

6268
assertEquals("[null]", annotations.toString());
6369

64-
Annotation testAnnotation = thisMethod.getAnnotation(Test.class);
70+
Annotation testAnnotation = thisMethod.getAnnotation(Configured.class);
6571
annotations.addAsDefault(testAnnotation);
6672

6773
// order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present
6874
String asString = _normalize(annotations.toString());
69-
assertTrue(asString.contains("{interface org.junit.Test=@org.junit.Test("));
70-
assertTrue(asString.contains("timeout=0"));
71-
72-
// 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
73-
// 05-Dec-2025, tatu: Java 21 adds further variation
74-
if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8
75-
|| asString.contains("expected=org.junit.Test.None"))) {
76-
fail("No 'expected' in: "+asString);
77-
}
75+
assertTrue(asString.contains("{interface com.fasterxml.classmate.AnnotationsTest.Configured=@com.fasterxml.classmate.AnnotationsTest.Configured("),
76+
asString);
77+
assertTrue(asString.contains("timeout=0"), asString);
7878

7979
Annotation markerAnnotation = thisMethod.getAnnotation(Marker.class);
8080
annotations.addAsDefault(markerAnnotation);
@@ -85,18 +85,13 @@ public void annotationsToSize() throws Exception {
8585
if (!asString.contains(exp)) {
8686
fail("Expected: ["+exp+"]\nin ["+asString+"]");
8787
}
88-
assertTrue(asString.contains("interface org.junit.Test=@org.junit.Test"));
89-
assertTrue(asString.contains("timeout=0"));
90-
// 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
91-
// 05-Dec-2025, tatu: Java 21 adds further variation
92-
if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8
93-
|| asString.contains("expected=org.junit.Test.None"))) {
94-
fail("No 'expected' in: "+asString);
95-
}
88+
assertTrue(asString.contains("interface com.fasterxml.classmate.AnnotationsTest.Configured=@com.fasterxml.classmate.AnnotationsTest.Configured("),
89+
asString);
90+
assertTrue(asString.contains("timeout=0"), asString);
9691
}
9792

9893
private static String _normalize(String str) {
99-
// 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None"
94+
// Nested type names use '$' on some JDKs and '.' on others
10095
String str2;
10196
while ((str2 = str.replace('$', '.')) != str) {
10297
str = str2;

‎src/test/java/com/fasterxml/classmate/BaseTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.classmate;
22

3+
import static org.junit.jupiter.api.Assertions.*;
4+
35
import java.util.Arrays;
46
import java.util.HashSet;
57
import java.util.List;
@@ -8,9 +10,8 @@
810
import com.fasterxml.classmate.members.RawMember;
911
import com.fasterxml.classmate.members.ResolvedMember;
1012

11-
import junit.framework.TestCase;
1213

13-
public abstract class BaseTest extends TestCase
14+
public abstract class BaseTest
1415
{
1516
protected void verifyException(Throwable e, String... matches)
1617
{

‎src/test/java/com/fasterxml/classmate/MemberResolver132Test.java‎

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

3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
36
import java.util.*;
47

58
import com.fasterxml.classmate.members.ResolvedMethod;
@@ -45,6 +48,7 @@ static abstract class GSub<T> implements GMid<T> { }
4548
private final TypeResolver _typeResolver = new TypeResolver();
4649
private final MemberResolver _memberResolver = new MemberResolver(_typeResolver);
4750

51+
@Test
4852
public void testInterfaceViaTypeParameter()
4953
{
5054
ResolvedType outer = _verifyViaContext(_typeResolver.resolve(MidI.class, String.class),
@@ -55,13 +59,15 @@ public void testInterfaceViaTypeParameter()
5559
assertEquals(OuterI.class, _findMethod(outer, "get").getReturnType().getErasedType());
5660
}
5761

62+
@Test
5863
public void testClassViaTypeParameter()
5964
{
6065
_verifyViaContext(_typeResolver.resolve(MidC.class, String.class), OuterC.class, "get", "top");
6166
_verifyViaContext(_typeResolver.resolve(MidI2.class, String.class), OuterC2.class, "get", "top");
6267
}
6368

6469
// Self-reference itself as the type to resolve members of
70+
@Test
6571
public void testSelfReferenceAsMainType()
6672
{
6773
ResolvedType selfRef = _typeResolver.resolve(OuterI.class)
@@ -72,6 +78,7 @@ public void testSelfReferenceAsMainType()
7278

7379
// Self-referential supertypes only valid within their resolution context must
7480
// be replaced with stand-alone types
81+
@Test
7582
public void testIncompleteSupertypes()
7683
{
7784
ResolvedType midJ = _param(_typeResolver.resolve(OutJ.class));
@@ -85,6 +92,7 @@ public void testIncompleteSupertypes()
8592
_verifyRef(outerK, OutK.class);
8693
}
8794

95+
@Test
8896
public void testSubtypeOfIncompleteType()
8997
{
9098
ResolvedType midJ = _param(_typeResolver.resolve(OutJ.class));

‎src/test/java/com/fasterxml/classmate/MemberResolver133Test.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.fasterxml.classmate;
22

3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
36
import com.fasterxml.classmate.members.ResolvedField;
47
import com.fasterxml.classmate.members.ResolvedMethod;
58
import com.fasterxml.classmate.types.ResolvedRecursiveType;
@@ -32,16 +35,19 @@ public static class RawSelf<T extends RawSelf> extends Base<T> { }
3235
private final TypeResolver _typeResolver = new TypeResolver();
3336
private final MemberResolver _memberResolver = new MemberResolver(_typeResolver);
3437

38+
@Test
3539
public void testGenericSelfReference()
3640
{
3741
_verify(Sym.class, Sym.class, Base.class);
3842
}
3943

44+
@Test
4045
public void testRawSelfReferenceInTypeParameter()
4146
{
4247
_verify(RB.class, RA.class, Object.class);
4348
}
4449

50+
@Test
4551
public void testBareRawSelfReference()
4652
{
4753
// sanity check: type parameter is a raw self-reference
@@ -53,6 +59,7 @@ public void testBareRawSelfReference()
5359
}
5460

5561
// Self-reference passed directly to public `resolve()` methods
62+
@Test
5663
public void testResolveSelfReference()
5764
{
5865
ResolvedType rawEnum = _typeResolver.resolve(Enum.class);
@@ -84,7 +91,7 @@ private void _verify(Class<?> type, Class<?> expValueType, Class<?> expParent)
8491
_verifyStandalone(value, expValueType, expParent);
8592

8693
ResolvedType elem = arr.getArrayElementType();
87-
assertFalse("Should not be self-reference: "+elem, elem instanceof ResolvedRecursiveType);
94+
assertFalse(elem instanceof ResolvedRecursiveType, "Should not be self-reference: "+elem);
8895
assertEquals(elem, value);
8996
assertEquals(elem.hashCode(), value.hashCode());
9097
assertEquals(elem.getFullDescription(), value.getFullDescription());
@@ -101,7 +108,7 @@ private void _verify(Class<?> type, Class<?> expValueType, Class<?> expParent)
101108

102109
private void _verifyStandalone(ResolvedType type, Class<?> expType, Class<?> expParent)
103110
{
104-
assertFalse("Should not be self-reference: "+type, type instanceof ResolvedRecursiveType);
111+
assertFalse(type instanceof ResolvedRecursiveType, "Should not be self-reference: "+type);
105112
assertEquals(expType, type.getErasedType());
106113
assertNotNull(type.getParentClass());
107114
assertEquals(expParent, type.getParentClass().getErasedType());

‎src/test/java/com/fasterxml/classmate/MemberResolverTest.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.fasterxml.classmate;
22

3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
37
import java.lang.reflect.Method;
48
import java.util.*;
59

@@ -81,8 +85,8 @@ static class SimpleClass
8185

8286
protected TypeResolver typeResolver;
8387

84-
@Override
85-
protected void setUp()
88+
@BeforeEach
89+
public void setUp()
8690
{
8791
// Let's use a single instance for all tests, to increase chance of seeing failures
8892
typeResolver = new TypeResolver();
@@ -97,6 +101,7 @@ protected void setUp()
97101
/**
98102
* Test for most basic thing; type hierarchy resolution
99103
*/
104+
@Test
100105
public void testSimpleHierarchy()
101106
{
102107
MemberResolver mr = new MemberResolver(typeResolver);
@@ -112,6 +117,7 @@ public void testSimpleHierarchy()
112117
assertSame(BaseClass.class, types.get(1).getErasedType());
113118
}
114119

120+
@Test
115121
public void testSimpleHierarchyWithMixins()
116122
{
117123
MemberResolver mr = new MemberResolver(typeResolver);
@@ -151,6 +157,7 @@ public void testSimpleHierarchyWithMixins()
151157
/**
152158
* Test for checking basic member detection for super type.
153159
*/
160+
@Test
154161
public void testMembersForSupertype()
155162
{
156163
MemberResolver mr = new MemberResolver(typeResolver);
@@ -177,6 +184,7 @@ public void testMembersForSupertype()
177184
* Test for checking basic aggregation with two types (subtype that
178185
* extends supertype)
179186
*/
187+
@Test
180188
public void testAggregationForSubtype()
181189
{
182190
MemberResolver mr = new MemberResolver(typeResolver);
@@ -186,6 +194,7 @@ public void testAggregationForSubtype()
186194
verifySubtypeAggregate(bean);
187195
}
188196

197+
@Test
189198
public void testAggregationForSubtypeAndDummyMixin()
190199
{
191200
MemberResolver mr = new MemberResolver(typeResolver);
@@ -199,6 +208,7 @@ public void testAggregationForSubtypeAndDummyMixin()
199208
verifySubtypeAggregate(bean);
200209
}
201210

211+
@Test
202212
public void testIncludeObject()
203213
{
204214
ResolvedType simpleResolvedType = typeResolver.resolve(SimpleClass.class);
@@ -221,6 +231,7 @@ public void testIncludeObject()
221231
assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length);
222232
}
223233

234+
@Test
224235
public void testFilters()
225236
{
226237
ResolvedType simpleResolvedType = typeResolver.resolve(SimpleClass.class);
@@ -293,6 +304,7 @@ public void testFilters()
293304
// like this. And since this breaks with JDK 17 (probably due to additional
294305
// interfaces in JDK types), will comment out.
295306
/*
307+
@Test
296308
public void testAddOverridesFromInterfaces() throws IllegalAccessException, InvocationTargetException
297309
{
298310
ResolvedType resolvedType = typeResolver.resolve(MemberResolver.class);
@@ -340,6 +352,7 @@ public void testAddOverridesFromInterfaces() throws IllegalAccessException, Invo
340352
}
341353
*/
342354

355+
@Test
343356
public void testGatherTypesWithInterfaces() throws Exception
344357
{
345358
ResolvedType resolvedType = typeResolver.resolve(MemberResolver.class);
@@ -374,6 +387,7 @@ public void testGatherTypesWithInterfaces() throws Exception
374387
assertEquals(2, types.size());
375388
}
376389

390+
@Test
377391
public void testJavaLangObject30() throws Exception
378392
{
379393
MemberResolver memberResolver = new MemberResolver(typeResolver);

‎src/test/java/com/fasterxml/classmate/OddJDKTypesTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.fasterxml.classmate;
22

3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
36
import java.util.*;
47

58
public class OddJDKTypesTest extends BaseTest
69
{
710
// Simple test, based on issues Jackson's type resolver had with inner
811
// classes of JDK (Hash)Map
12+
@Test
913
public void testJDKMaps()
1014
{
1115
TypeResolver resolver = new TypeResolver();

‎src/test/java/com/fasterxml/classmate/ResolvedTypeTest.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.fasterxml.classmate;
22

3+
import static org.junit.jupiter.api.Assertions.*;
4+
35
import java.io.Serializable;
46
import java.nio.CharBuffer;
57
import java.util.List;
68

7-
import org.junit.Test;
9+
import org.junit.jupiter.api.Test;
810

911
import com.fasterxml.classmate.types.ResolvedArrayType;
1012
import com.fasterxml.classmate.types.ResolvedInterfaceType;

0 commit comments

Comments
 (0)