Skip to content

Commit

Permalink
[JSTEP-10] Migrate /OSGi and no-ctor-deser module to JUnit 5 (#276
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JooHyukKim authored Jan 18, 2025
1 parent dbb5df4 commit f587964
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
9 changes: 7 additions & 2 deletions no-ctor-deser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.fasterxml.jackson.module.noctordeser;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;

import junit.framework.TestCase;

import java.util.Arrays;

public class BasicNoConstructorTest extends TestCase
import static org.junit.jupiter.api.Assertions.*;

public class BasicNoConstructorTest
{
static class BeanWithoutDefaultConstructor {
public String value;
Expand Down Expand Up @@ -40,6 +42,7 @@ protected static ObjectMapper newObjectMapper() {

private final ObjectMapper MAPPER = newObjectMapper();

@Test
public void testReadValueWithoutDefaultConstructor() throws Exception
{
String json = MAPPER.writeValueAsString(new BeanWithoutDefaultConstructor("test"));
Expand All @@ -66,6 +69,7 @@ public void testReadValueWithoutDefaultConstructor() throws Exception
assertEquals(7, result2.y);
}

@Test
public void testReadValueWithDefaultConstructor() throws Exception {
BeanWithDefaultConstructor bean = new BeanWithDefaultConstructor();
bean.value = "test";
Expand Down
10 changes: 8 additions & 2 deletions osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@
<artifactId>org.osgi.core</artifactId>
<version>${version.osgi.core}</version>
</dependency>
<!-- Test dependencies: -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.fasterxml.jackson.module.osgi;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
Expand All @@ -13,15 +9,11 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
Expand All @@ -32,29 +24,26 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;

@RunWith(value = Parameterized.class)
import static org.junit.jupiter.api.Assertions.*;

public class InjectOsgiServiceTest
{
private static final String OSGI_FILTER = "osgi.filter";

private BundleContext bundleContext;

private ObjectMapper mapper;

@Parameter
public Class<?> beanClass;

@Parameters
public static Collection<Class<? extends VerifyableBean>> data() {
return Arrays.asList(

public static Stream<Class<? extends VerifyableBean>> data() {
return Stream.of(
BeanWithServiceInConstructor.class,
BeanWithFilter.class,
BeanWithServiceInField.class,
BeanWithNotFoundService.class);
}

@SuppressWarnings("unchecked")
@Before
@BeforeEach
public void setUp() throws Exception
{
bundleContext = mock(BundleContext.class);
Expand All @@ -69,9 +58,11 @@ public void setUp() throws Exception
.addModule(new OsgiJacksonModule(bundleContext))
.build();
}

@Test
public void testServiceIsInjected() throws Exception

@MethodSource("data")
@ParameterizedTest
public void testServiceIsInjected(Class<?> beanClass)
throws Exception
{
// ACTION
VerifyableBean result = mapper.reader().forType(beanClass)
Expand Down

0 comments on commit f587964

Please sign in to comment.