Skip to content

Commit dbb5df4

Browse files
committed
Convert guice/guice7 modules to junit5
1 parent 1b7a759 commit dbb5df4

File tree

12 files changed

+123
-105
lines changed

12 files changed

+123
-105
lines changed

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/CreatorOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected OptimizedValueInstantiator createSubclass(Constructor<?> ctor, Method
9393
impl = loader.loadAndResolve(baseName, bytecode);
9494
}
9595
try {
96-
return (OptimizedValueInstantiator) impl.newInstance();
96+
return (OptimizedValueInstantiator) impl.getConstructor().newInstance();
9797
} catch (Exception e) {
9898
throw new IllegalStateException("Failed to generate accessor class '"+baseName+"': "+e.getMessage(), e);
9999
}

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/PropertyMutatorCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public BeanPropertyMutator buildMutator(MyClassLoader classLoader)
101101
final ClassName baseName = ClassName.constructFor(beanClass, "$Access4JacksonDeserializer");
102102
Class<?> accessorClass = generateMutatorClass(classLoader, baseName);
103103
try {
104-
return (BeanPropertyMutator) accessorClass.newInstance();
104+
return (BeanPropertyMutator) accessorClass.getConstructor().newInstance();
105105
} catch (Exception e) {
106106
throw new IllegalStateException("Failed to generate accessor class '"+accessorClass.getName()+"': "+e.getMessage(), e);
107107
}

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/ser/PropertyAccessorCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public BeanPropertyAccessor findAccessor(MyClassLoader classLoader)
9696
final ClassName baseName = ClassName.constructFor(beanClass, "$Access4JacksonSerializer");
9797
Class<?> accessorClass = generateAccessorClass(classLoader, baseName);
9898
try {
99-
return (BeanPropertyAccessor) accessorClass.newInstance();
99+
return (BeanPropertyAccessor) accessorClass.getConstructor().newInstance();
100100
} catch (Exception e) {
101101
throw new IllegalStateException("Failed to generate accessor class '"+accessorClass.getName()+"': "+e.getMessage(), e);
102102
}

afterburner/src/test/java/perftest/TestJvmDeserPerf.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.fasterxml.jackson.core.JsonParser;
55
import com.fasterxml.jackson.databind.JavaType;
66
import com.fasterxml.jackson.databind.ObjectMapper;
7-
import com.fasterxml.jackson.databind.type.TypeFactory;
87

98
/**
109
* Micro-benchmark for comparing performance of bean deserialization

android-record/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<artifactId>jackson-databind</artifactId>
4343
</dependency>
4444

45-
<!-- Test dependencies: -->
45+
<!-- Test dependencies -->
4646
<dependency>
4747
<groupId>org.junit.jupiter</groupId>
4848
<artifactId>junit-jupiter</artifactId>

guice/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@
5151
<version>${version.guice}</version>
5252
</dependency>
5353

54+
<!-- Test dependencies -->
5455
<dependency>
55-
<groupId>junit</groupId>
56-
<artifactId>junit</artifactId>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.junit.jupiter</groupId>
62+
<artifactId>junit-jupiter-api</artifactId>
5763
<scope>test</scope>
5864
</dependency>
5965
</dependencies>

guice/src/test/java/com/fasterxml/jackson/module/guice/ExtendInjectableTest.java

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

3-
import com.fasterxml.jackson.annotation.JacksonInject;
4-
import com.fasterxml.jackson.annotation.JsonCreator;
5-
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import javax.inject.Inject;
4+
5+
import org.junit.jupiter.api.Test;
6+
77
import com.google.inject.Binder;
88
import com.google.inject.Guice;
99
import com.google.inject.Injector;
1010
import com.google.inject.Module;
1111
import com.google.inject.name.Names;
12-
import org.junit.Assert;
13-
import org.junit.Test;
1412

15-
import javax.inject.Inject;
13+
import com.fasterxml.jackson.annotation.*;
14+
15+
import com.fasterxml.jackson.databind.ObjectMapper;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertSame;
1619

1720
/**
1821
*/
@@ -62,30 +65,30 @@ public void configure(Binder binder)
6265

6366
final ReadableBean bean = mapper.readValue("{\"constructor_value\":\"myConstructor\",\"field_value\":\"myField\",\"method_value\":\"myMethod\"}", ReadableBean.class);
6467

65-
Assert.assertEquals("myConstructor", bean.constructorValue);
66-
Assert.assertEquals("myMethod", bean.methodValue);
67-
Assert.assertEquals("myField", bean.fieldValue);
68+
assertEquals("myConstructor", bean.constructorValue);
69+
assertEquals("myMethod", bean.methodValue);
70+
assertEquals("myField", bean.fieldValue);
6871

6972
verifyInjections("From Jackson's ObjectMapper", bean);
7073

7174
}
7275

7376
private void verifyInjections(String message, InjectableBean injected)
7477
{
75-
Assert.assertSame(message, constructorInjected, injected.constructorInjected);
76-
Assert.assertSame(message, constructorInjectedWithJavaAnnotation, injected.constructorInjectedWithJavaAnnotation);
77-
Assert.assertSame(message, constructorInjectedWithGuiceAnnotation, injected.constructorInjectedWithGuiceAnnotation);
78-
Assert.assertSame(message, constructorInjectedWithCustomAnnotation, injected.constructorInjectedWithCustomAnnotation);
79-
80-
Assert.assertSame(message, methodInjected, injected.methodInjected);
81-
Assert.assertSame(message, methodInjectedWithJavaAnnotation, injected.methodInjectedWithJavaAnnotation);
82-
Assert.assertSame(message, methodInjectedWithGuiceAnnotation, injected.methodInjectedWithGuiceAnnotation);
83-
Assert.assertSame(message, methodInjectedWithCustomAnnotation, injected.methodInjectedWithCustomAnnotation);
84-
85-
Assert.assertSame(message, fieldInjected, injected.fieldInjected);
86-
Assert.assertSame(message, fieldInjectedWithJavaAnnotation, injected.fieldInjectedWithJavaAnnotation);
87-
Assert.assertSame(message, fieldInjectedWithGuiceAnnotation, injected.fieldInjectedWithGuiceAnnotation);
88-
Assert.assertSame(message, fieldInjectedWithCustomAnnotation, injected.fieldInjectedWithCustomAnnotation);
78+
assertSame(constructorInjected, injected.constructorInjected);
79+
assertSame(constructorInjectedWithJavaAnnotation, injected.constructorInjectedWithJavaAnnotation);
80+
assertSame(constructorInjectedWithGuiceAnnotation, injected.constructorInjectedWithGuiceAnnotation);
81+
assertSame(constructorInjectedWithCustomAnnotation, injected.constructorInjectedWithCustomAnnotation);
82+
83+
assertSame(methodInjected, injected.methodInjected);
84+
assertSame(methodInjectedWithJavaAnnotation, injected.methodInjectedWithJavaAnnotation);
85+
assertSame(methodInjectedWithGuiceAnnotation, injected.methodInjectedWithGuiceAnnotation);
86+
assertSame(methodInjectedWithCustomAnnotation, injected.methodInjectedWithCustomAnnotation);
87+
88+
assertSame(fieldInjected, injected.fieldInjected);
89+
assertSame(fieldInjectedWithJavaAnnotation, injected.fieldInjectedWithJavaAnnotation);
90+
assertSame(fieldInjectedWithGuiceAnnotation, injected.fieldInjectedWithGuiceAnnotation);
91+
assertSame(fieldInjectedWithCustomAnnotation, injected.fieldInjectedWithCustomAnnotation);
8992
}
9093

9194
/* ===================================================================== */

guice/src/test/java/com/fasterxml/jackson/module/guice/ObjectMapperModuleTest.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
import java.io.IOException;
44
import java.math.BigInteger;
55

6+
import org.junit.jupiter.api.Test;
7+
8+
import com.google.inject.Binder;
9+
import com.google.inject.Guice;
10+
import com.google.inject.Injector;
11+
import com.google.inject.Key;
12+
import com.google.inject.Module;
13+
import com.google.inject.name.Names;
14+
615
import com.fasterxml.jackson.annotation.JacksonInject;
716
import com.fasterxml.jackson.annotation.JsonProperty;
817

@@ -14,15 +23,7 @@
1423
import com.fasterxml.jackson.databind.SerializerProvider;
1524
import com.fasterxml.jackson.databind.module.SimpleModule;
1625

17-
import com.google.inject.Binder;
18-
import com.google.inject.Guice;
19-
import com.google.inject.Injector;
20-
import com.google.inject.Key;
21-
import com.google.inject.Module;
22-
import com.google.inject.name.Names;
23-
24-
import org.junit.Assert;
25-
import org.junit.Test;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2627

2728
public class ObjectMapperModuleTest
2829
{
@@ -67,7 +68,7 @@ public void testModulesRegisteredThroughNormalInstantiation() throws Exception
6768

6869
final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
6970

70-
Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
71+
assertEquals(mapper.writeValueAsString(10), "\"A\"");
7172
}
7273

7374
@Test
@@ -79,7 +80,7 @@ public void testModulesRegisteredThroughInjection() throws Exception
7980

8081
final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
8182

82-
Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
83+
assertEquals(mapper.writeValueAsString(10), "\"A\"");
8384
}
8485

8586
@Test
@@ -99,7 +100,7 @@ public void configure(Binder binder)
99100

100101
final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
101102

102-
Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
103+
assertEquals(mapper.writeValueAsString(10), "\"A\"");
103104
}
104105

105106
@Test
@@ -121,7 +122,7 @@ public void configure(Binder binder)
121122

122123
final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
123124

124-
Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
125+
assertEquals(mapper.writeValueAsString(10), "\"A\"");
125126
}
126127

127128
@Test
@@ -133,7 +134,7 @@ public void testModulesRegisteredThroughInjectionWithKey() throws Exception
133134

134135
final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
135136

136-
Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
137+
assertEquals(mapper.writeValueAsString(10), "\"A\"");
137138
}
138139

139140
private static class SomeBean
@@ -188,15 +189,15 @@ private void injectNine(long n)
188189

189190
public boolean verify()
190191
{
191-
Assert.assertEquals(1, one);
192-
Assert.assertEquals(2, two);
193-
Assert.assertEquals(3, three);
194-
Assert.assertEquals(4, four);
195-
Assert.assertEquals(5, five);
196-
Assert.assertEquals(6, six);
197-
Assert.assertEquals(7, seven);
198-
Assert.assertEquals(8, eight);
199-
Assert.assertEquals(9, nine);
192+
assertEquals(1, one);
193+
assertEquals(2, two);
194+
assertEquals(3, three);
195+
assertEquals(4, four);
196+
assertEquals(5, five);
197+
assertEquals(6, six);
198+
assertEquals(7, seven);
199+
assertEquals(8, eight);
200+
assertEquals(9, nine);
200201
return true;
201202
}
202203

guice7/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@
5151
<version>${version.guice}</version>
5252
</dependency>
5353

54+
<!-- Test dependencies -->
5455
<dependency>
55-
<groupId>junit</groupId>
56-
<artifactId>junit</artifactId>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.junit.jupiter</groupId>
62+
<artifactId>junit-jupiter-api</artifactId>
5763
<scope>test</scope>
5864
</dependency>
5965
</dependencies>

guice7/src/test/java/com/fasterxml/jackson/module/guice7/ExtendInjectableTest.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.fasterxml.jackson.module.guice7;
22

3-
import com.fasterxml.jackson.annotation.JacksonInject;
4-
import com.fasterxml.jackson.annotation.JsonCreator;
5-
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import jakarta.inject.Inject;
4+
5+
import org.junit.jupiter.api.Test;
6+
77
import com.google.inject.Binder;
88
import com.google.inject.Guice;
99
import com.google.inject.Injector;
1010
import com.google.inject.Module;
1111
import com.google.inject.name.Names;
12-
import org.junit.Assert;
13-
import org.junit.Test;
1412

15-
import jakarta.inject.Inject;
13+
import com.fasterxml.jackson.annotation.*;
14+
import com.fasterxml.jackson.databind.ObjectMapper;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertSame;
1618

1719
/**
1820
*/
@@ -62,30 +64,30 @@ public void configure(Binder binder)
6264

6365
final ReadableBean bean = mapper.readValue("{\"constructor_value\":\"myConstructor\",\"field_value\":\"myField\",\"method_value\":\"myMethod\"}", ReadableBean.class);
6466

65-
Assert.assertEquals("myConstructor", bean.constructorValue);
66-
Assert.assertEquals("myMethod", bean.methodValue);
67-
Assert.assertEquals("myField", bean.fieldValue);
67+
assertEquals("myConstructor", bean.constructorValue);
68+
assertEquals("myMethod", bean.methodValue);
69+
assertEquals("myField", bean.fieldValue);
6870

6971
verifyInjections("From Jackson's ObjectMapper", bean);
7072

7173
}
7274

7375
private void verifyInjections(String message, InjectableBean injected)
7476
{
75-
Assert.assertSame(message, constructorInjected, injected.constructorInjected);
76-
Assert.assertSame(message, constructorInjectedWithJavaAnnotation, injected.constructorInjectedWithJavaAnnotation);
77-
Assert.assertSame(message, constructorInjectedWithGuiceAnnotation, injected.constructorInjectedWithGuiceAnnotation);
78-
Assert.assertSame(message, constructorInjectedWithCustomAnnotation, injected.constructorInjectedWithCustomAnnotation);
79-
80-
Assert.assertSame(message, methodInjected, injected.methodInjected);
81-
Assert.assertSame(message, methodInjectedWithJavaAnnotation, injected.methodInjectedWithJavaAnnotation);
82-
Assert.assertSame(message, methodInjectedWithGuiceAnnotation, injected.methodInjectedWithGuiceAnnotation);
83-
Assert.assertSame(message, methodInjectedWithCustomAnnotation, injected.methodInjectedWithCustomAnnotation);
84-
85-
Assert.assertSame(message, fieldInjected, injected.fieldInjected);
86-
Assert.assertSame(message, fieldInjectedWithJavaAnnotation, injected.fieldInjectedWithJavaAnnotation);
87-
Assert.assertSame(message, fieldInjectedWithGuiceAnnotation, injected.fieldInjectedWithGuiceAnnotation);
88-
Assert.assertSame(message, fieldInjectedWithCustomAnnotation, injected.fieldInjectedWithCustomAnnotation);
77+
assertSame(constructorInjected, injected.constructorInjected);
78+
assertSame(constructorInjectedWithJavaAnnotation, injected.constructorInjectedWithJavaAnnotation);
79+
assertSame(constructorInjectedWithGuiceAnnotation, injected.constructorInjectedWithGuiceAnnotation);
80+
assertSame(constructorInjectedWithCustomAnnotation, injected.constructorInjectedWithCustomAnnotation);
81+
82+
assertSame(methodInjected, injected.methodInjected);
83+
assertSame(methodInjectedWithJavaAnnotation, injected.methodInjectedWithJavaAnnotation);
84+
assertSame(methodInjectedWithGuiceAnnotation, injected.methodInjectedWithGuiceAnnotation);
85+
assertSame(methodInjectedWithCustomAnnotation, injected.methodInjectedWithCustomAnnotation);
86+
87+
assertSame(fieldInjected, injected.fieldInjected);
88+
assertSame(fieldInjectedWithJavaAnnotation, injected.fieldInjectedWithJavaAnnotation);
89+
assertSame(fieldInjectedWithGuiceAnnotation, injected.fieldInjectedWithGuiceAnnotation);
90+
assertSame(fieldInjectedWithCustomAnnotation, injected.fieldInjectedWithCustomAnnotation);
8991
}
9092

9193
/* ===================================================================== */

0 commit comments

Comments
 (0)