Skip to content

Commit f587964

Browse files
authored
[JSTEP-10] Migrate /OSGi and no-ctor-deser module to JUnit 5 (#276)
1 parent dbb5df4 commit f587964

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

no-ctor-deser/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@
4343
</dependency>
4444

4545
<dependency>
46-
<groupId>junit</groupId>
47-
<artifactId>junit</artifactId>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter-api</artifactId>
4853
<scope>test</scope>
4954
</dependency>
5055
</dependencies>

no-ctor-deser/src/test/java/com/fasterxml/jackson/module/noctordeser/BasicNoConstructorTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.fasterxml.jackson.module.noctordeser;
22

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

6-
import junit.framework.TestCase;
7-
88
import java.util.Arrays;
99

10-
public class BasicNoConstructorTest extends TestCase
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
public class BasicNoConstructorTest
1113
{
1214
static class BeanWithoutDefaultConstructor {
1315
public String value;
@@ -40,6 +42,7 @@ protected static ObjectMapper newObjectMapper() {
4042

4143
private final ObjectMapper MAPPER = newObjectMapper();
4244

45+
@Test
4346
public void testReadValueWithoutDefaultConstructor() throws Exception
4447
{
4548
String json = MAPPER.writeValueAsString(new BeanWithoutDefaultConstructor("test"));
@@ -66,6 +69,7 @@ public void testReadValueWithoutDefaultConstructor() throws Exception
6669
assertEquals(7, result2.y);
6770
}
6871

72+
@Test
6973
public void testReadValueWithDefaultConstructor() throws Exception {
7074
BeanWithDefaultConstructor bean = new BeanWithDefaultConstructor();
7175
bean.value = "test";

osgi/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@
4646
<artifactId>org.osgi.core</artifactId>
4747
<version>${version.osgi.core}</version>
4848
</dependency>
49+
<!-- Test dependencies: -->
4950
<dependency>
50-
<groupId>junit</groupId>
51-
<artifactId>junit</artifactId>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-api</artifactId>
5258
<scope>test</scope>
5359
</dependency>
5460
<dependency>

osgi/src/test/java/com/fasterxml/jackson/module/osgi/InjectOsgiServiceTest.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.fasterxml.jackson.module.osgi;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
5-
import static org.junit.Assert.assertNull;
6-
import static org.junit.Assert.fail;
73
import static org.mockito.Matchers.any;
84
import static org.mockito.Matchers.anyString;
95
import static org.mockito.Matchers.eq;
@@ -13,15 +9,11 @@
139
import static org.mockito.Mockito.times;
1410
import static org.mockito.Mockito.when;
1511

16-
import java.util.Arrays;
17-
import java.util.Collection;
12+
import java.util.stream.Stream;
1813

19-
import org.junit.Before;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
22-
import org.junit.runners.Parameterized;
23-
import org.junit.runners.Parameterized.Parameter;
24-
import org.junit.runners.Parameterized.Parameters;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.junit.jupiter.params.ParameterizedTest;
16+
import org.junit.jupiter.params.provider.MethodSource;
2517
import org.mockito.Mockito;
2618
import org.osgi.framework.BundleContext;
2719
import org.osgi.framework.Filter;
@@ -32,29 +24,26 @@
3224
import com.fasterxml.jackson.databind.ObjectMapper;
3325
import com.fasterxml.jackson.databind.json.JsonMapper;
3426

35-
@RunWith(value = Parameterized.class)
27+
import static org.junit.jupiter.api.Assertions.*;
28+
3629
public class InjectOsgiServiceTest
3730
{
3831
private static final String OSGI_FILTER = "osgi.filter";
3932

4033
private BundleContext bundleContext;
4134

4235
private ObjectMapper mapper;
43-
44-
@Parameter
45-
public Class<?> beanClass;
46-
47-
@Parameters
48-
public static Collection<Class<? extends VerifyableBean>> data() {
49-
return Arrays.asList(
36+
37+
public static Stream<Class<? extends VerifyableBean>> data() {
38+
return Stream.of(
5039
BeanWithServiceInConstructor.class,
5140
BeanWithFilter.class,
5241
BeanWithServiceInField.class,
5342
BeanWithNotFoundService.class);
5443
}
5544

5645
@SuppressWarnings("unchecked")
57-
@Before
46+
@BeforeEach
5847
public void setUp() throws Exception
5948
{
6049
bundleContext = mock(BundleContext.class);
@@ -69,9 +58,11 @@ public void setUp() throws Exception
6958
.addModule(new OsgiJacksonModule(bundleContext))
7059
.build();
7160
}
72-
73-
@Test
74-
public void testServiceIsInjected() throws Exception
61+
62+
@MethodSource("data")
63+
@ParameterizedTest
64+
public void testServiceIsInjected(Class<?> beanClass)
65+
throws Exception
7566
{
7667
// ACTION
7768
VerifyableBean result = mapper.reader().forType(beanClass)

0 commit comments

Comments
 (0)