From 6d56d99f46e179fafe7b06927554917eccdfb650 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sat, 18 Jan 2025 17:31:46 +0900 Subject: [PATCH] Migrate `OSGi` test to JUnit 5 --- osgi/pom.xml | 10 ++++- .../module/osgi/InjectOsgiServiceTest.java | 39 +++++++------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/osgi/pom.xml b/osgi/pom.xml index 554a5cb24..9e3c91c65 100644 --- a/osgi/pom.xml +++ b/osgi/pom.xml @@ -46,9 +46,15 @@ org.osgi.core ${version.osgi.core} + - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api test diff --git a/osgi/src/test/java/com/fasterxml/jackson/module/osgi/InjectOsgiServiceTest.java b/osgi/src/test/java/com/fasterxml/jackson/module/osgi/InjectOsgiServiceTest.java index e3cae3d91..3d8fcd956 100644 --- a/osgi/src/test/java/com/fasterxml/jackson/module/osgi/InjectOsgiServiceTest.java +++ b/osgi/src/test/java/com/fasterxml/jackson/module/osgi/InjectOsgiServiceTest.java @@ -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; @@ -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; @@ -32,7 +24,8 @@ 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"; @@ -40,13 +33,9 @@ public class InjectOsgiServiceTest private BundleContext bundleContext; private ObjectMapper mapper; - - @Parameter - public Class beanClass; - - @Parameters - public static Collection> data() { - return Arrays.asList( + + public static Stream> data() { + return Stream.of( BeanWithServiceInConstructor.class, BeanWithFilter.class, BeanWithServiceInField.class, @@ -54,7 +43,7 @@ public static Collection> data() { } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { bundleContext = mock(BundleContext.class); @@ -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)