Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 19, 2025
2 parents e955c90 + f587964 commit 29cfa74
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 52 deletions.
11 changes: 8 additions & 3 deletions no-ctor-deser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- 20-Apr-2024, tatu: JUnit4 no longer from jackson-base -->
<!-- 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>
</dependencies>
Expand Down
3 changes: 2 additions & 1 deletion no-ctor-deser/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

// Additional test lib/framework dependencies

requires junit; // JUnit4 To Be Removed in future
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up some packages for JUnit et al
opens tools.jackson.module.noctordeser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package tools.jackson.module.noctordeser;

import java.util.Arrays;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

import junit.framework.TestCase;

import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;

public class BasicNoConstructorTest extends TestCase
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
11 changes: 8 additions & 3 deletions osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@
<version>${version.osgi.core}</version>
</dependency>

<!-- 20-Apr-2024, tatu: JUnit4 no longer from jackson-base -->
<!-- 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>

Expand Down
4 changes: 2 additions & 2 deletions osgi/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

// Additional test lib/framework dependencies

requires junit;
requires org.mockito;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up some packages for JUnit et al
opens tools.jackson.module.osgi;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
package tools.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.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import java.util.stream.Stream;

import java.util.Arrays;
import java.util.Collection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import org.junit.Before;
import org.junit.Ignore;
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.mockito.Mockito;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
Expand All @@ -34,30 +17,39 @@
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

@RunWith(value = Parameterized.class)
@Ignore("Does not work on JDK 17/Mockito 5.x")
import static org.junit.jupiter.api.Assertions.*;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

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(
BeanWithServiceInConstructor.class,
BeanWithFilter.class,
BeanWithServiceInField.class,
BeanWithNotFoundService.class);

public static Stream<Class<? extends VerifyableBean>> data() {
// 18-Jan-2025, tatu: Looks like we'll mostly fail to inject Service
// in Jackson 3.0/JDK 17/JUnit 5/JPMS (not sure which part matters most;
// possibly JPMS). So comment out ones that'd fail
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 @@ -73,8 +65,10 @@ public void setUp() throws Exception
.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 All @@ -98,7 +92,7 @@ public static abstract class VerifyableBean
{
public String field;

protected Service service;
public Service service;

public boolean verify(BundleContext bundleContext)
{
Expand Down Expand Up @@ -135,7 +129,7 @@ public boolean verify(BundleContext bundleContext)
public static class BeanWithServiceInField extends VerifyableBean
{
@JacksonInject
private Service service2;
public Service service2;

@Override
public boolean verify(BundleContext bundleContext)
Expand Down

0 comments on commit 29cfa74

Please sign in to comment.