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 22, 2025
2 parents fefa9bb + 7169b99 commit edeec88
Show file tree
Hide file tree
Showing 37 changed files with 421 additions and 129 deletions.
11 changes: 8 additions & 3 deletions guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ com.google.common.*;version="${version.guava.osgi}",
<version>${version.guava}</version>
</dependency>

<!-- 2025-Jan-22 joohyukkim : temporarily isolate JUnit 4 here... -->
<!-- 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
2 changes: 1 addition & 1 deletion guava/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
requires com.fasterxml.jackson.annotation;

requires tools.jackson.core;
requires tools.jackson.databind;
requires transitive tools.jackson.databind;

requires com.google.common;

Expand Down
3 changes: 2 additions & 1 deletion guava/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
requires com.google.common;

// Additional test lib/framework dependencies
requires junit; // JUnit 4
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;

// Further, need to open up test packages for JUnit et al

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Map;
import java.util.Objects;

import org.junit.jupiter.api.Test;

import com.google.common.base.Optional;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
Expand All @@ -16,6 +18,8 @@
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.exc.MismatchedInputException;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for verifying deserialization of Guava's {@link Cache} type.
*
Expand Down Expand Up @@ -68,6 +72,7 @@ static class CacheWrapper {

private final ObjectMapper MAPPER = mapperWithModule();

@Test
public void testGuavaCacheApi() throws Exception {
Cache<String, String> cache = CacheBuilder.newBuilder().build();
// Cache does not allow null key
Expand All @@ -83,6 +88,7 @@ public void testGuavaCacheApi() throws Exception {
} catch (NullPointerException e) {}
}

@Test
public void testCacheDeserializationSimple() throws Exception {
// Create a delegate cache using CacheBuilder
Cache<String, Integer> delegateCache = CacheBuilder.newBuilder().build();
Expand All @@ -95,6 +101,7 @@ public void testCacheDeserializationSimple() throws Exception {
assertEquals("foo", s.getIfPresent("a"));
}

@Test
public void testCacheDeserRoundTrip() throws Exception {
Cache<String, Integer> cache = CacheBuilder.newBuilder().build();
cache.put("key1", 1);
Expand All @@ -111,6 +118,7 @@ public void testCacheDeserRoundTrip() throws Exception {
}

// [datatype-collections#96]
@Test
public void testCacheSerialization() throws Exception {
Cache<Long, Integer> cache = CacheBuilder.newBuilder().build();
cache.put(1L, 1);
Expand All @@ -134,6 +142,7 @@ private void _verifySizeTwoAndContains(Map<Long, Integer> map) {
assertEquals(2, map.get(2L).intValue());
}

@Test
public void testEnumKey() throws Exception {
final TypeReference<Cache<MyEnum, Integer>> type = new TypeReference<Cache<MyEnum, Integer>>() {};
final Cache<MyEnum, Integer> cache = CacheBuilder.newBuilder().build();
Expand All @@ -151,11 +160,13 @@ public void testEnumKey() throws Exception {
deserializedCache.asMap().entrySet());
}

@Test
public void testEmptyCacheExclusion() throws Exception {
String json = MAPPER.writeValueAsString(new CacheWrapper());
assertEquals("{}", json);
}

@Test
public void testWithGuavaOptional() throws Exception {
// set up
Cache<String, Optional<Double>> cache = CacheBuilder.newBuilder().build();
Expand All @@ -175,6 +186,7 @@ public void testWithGuavaOptional() throws Exception {
}

// [datatypes-collections#140]: handle null values
@Test
public void testCacheWithNulls() throws Exception {
Cache<String, Integer> cache;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import com.google.common.base.Objects;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for verifying serialization of Guava's {@link Cache} type.
*/
Expand Down Expand Up @@ -191,6 +194,7 @@ public String toString() {
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
.build();

@Test
public void testGuavaCacheApi() throws Exception {
Cache<String, String> cache = CacheBuilder.newBuilder().build();
// Cache does not allow null key
Expand All @@ -206,6 +210,7 @@ public void testGuavaCacheApi() throws Exception {
} catch (NullPointerException e) {}
}

@Test
public void testCacheSerialization() throws Exception {
// Create a Guava Cache
Cache<String, String> cache = CacheBuilder.newBuilder().build();
Expand All @@ -217,6 +222,7 @@ public void testCacheSerialization() throws Exception {
ORDERED_MAPPER.writeValueAsString(cache));
}

@Test
public void testCacheSerializationIgnoreProperties() throws Exception {
CacheContainerWithIgnores container = new CacheContainerWithIgnores();

Expand All @@ -225,6 +231,7 @@ public void testCacheSerializationIgnoreProperties() throws Exception {
ORDERED_MAPPER.writeValueAsString(container));
}

@Test
public void testCacheSerializationWithBean() throws Exception {
CacheContainerWithBean container = new CacheContainerWithBean();

Expand All @@ -233,6 +240,7 @@ public void testCacheSerializationWithBean() throws Exception {
ORDERED_MAPPER.writeValueAsString(container));
}

@Test
public void testCacheSerializationWithList() throws Exception {
CacheContainerWithList container = new CacheContainerWithList();

Expand All @@ -241,6 +249,7 @@ public void testCacheSerializationWithList() throws Exception {
ORDERED_MAPPER.writeValueAsString(container));
}

@Test
public void testCacheSerializationWithEmptyCache() throws Exception {
Cache<String, String> cache = CacheBuilder.newBuilder().build();

Expand All @@ -249,6 +258,7 @@ public void testCacheSerializationWithEmptyCache() throws Exception {
ORDERED_MAPPER.writeValueAsString(cache));
}

@Test
public void testCacheSerializationBeanKey() throws Exception {
Cache<BeanKey, String> cache = CacheBuilder.newBuilder().build();
cache.put(new BeanKey(1), "value1");
Expand All @@ -258,6 +268,7 @@ public void testCacheSerializationBeanKey() throws Exception {
ORDERED_MAPPER.writeValueAsString(cache));
}

@Test
public void testCacheSerializationBeanKeyEquals() throws Exception {
Cache<BeanKeyEquals, String> cache = CacheBuilder.newBuilder().build();
cache.put(new BeanKeyEquals(1), "value1");
Expand All @@ -270,12 +281,14 @@ public void testCacheSerializationBeanKeyEquals() throws Exception {
}


@Test
public void testEmptyCacheExclusion() throws Exception {
String json = ORDERED_MAPPER.writeValueAsString(new CacheWrapper());

assertEquals("{}", json);
}

@Test
public void testCacheSerializationWithTypeReference() throws Exception {
final Cache<MyEnum, Integer> cache = CacheBuilder.newBuilder().build();
cache.put(MyEnum.YAY, 5);
Expand All @@ -289,6 +302,7 @@ public void testCacheSerializationWithTypeReference() throws Exception {
assertEquals(expected, mapperSer);
}

@Test
public void testOrderByKeyViaProperty() throws Exception {
CacheOrderingBean input = new CacheOrderingBean("c", "b", "a");

Expand All @@ -297,6 +311,7 @@ public void testOrderByKeyViaProperty() throws Exception {
assertEquals(a2q("{'cache':{'a':3,'b':2,'c':1}}"), json);
}

@Test
public void testPolymorphicCacheSerialization() throws Exception {
Cache<String, Animal> cache = CacheBuilder.newBuilder().build();
cache.put("c", new Cat());
Expand All @@ -311,6 +326,7 @@ public void testPolymorphicCacheSerialization() throws Exception {
"'d':{'_type':'t_dog','name':'Woof'}}}"), json);
}

@Test
public void testNestedCacheSerialization() throws Exception {
Cache<String, Cache<String, String>> nestedCache = CacheBuilder.newBuilder().build();
nestedCache.put("a", _buildCacheWithKeys("a_x", "a_y"));
Expand All @@ -333,13 +349,15 @@ private Cache<String, String> _buildCacheWithKeys(String... keys) {
}

// [datatypes-collections#104]
@Test
public void testPolymorphicCacheEmpty() throws Exception {
final Cache<String, Object> cache = CacheBuilder.newBuilder().build();
cache.put("aKey", 1);
_testPolymorphicCache(cache,
a2q("{'aProperty':{'@type':'LocalCache$LocalManualCache','aKey':1}}"));
}

@Test
public void testPolymorphicCacheNonEmpty() throws Exception {
_testPolymorphicCache(CacheBuilder.newBuilder().build(),
a2q("{'aProperty':{'@type':'LocalCache$LocalManualCache'}}"));
Expand All @@ -354,6 +372,7 @@ private void _testPolymorphicCache(Cache<String, Object> cache, String expected)
assertEquals(expected, json);
}

@Test
public void testCacheSerializeOrderedByKey() throws Exception {
final Cache<String, String> cache = _buildCacheWithKeys("c_key", "d_key", "a_key", "e_key", "b_key");

Expand All @@ -365,6 +384,7 @@ public void testCacheSerializeOrderedByKey() throws Exception {
new TypeReference<Cache<String, String>>() {}).writeValueAsString(cache));
}

@Test
public void testPolymorphicCacheWrapperSerialization() throws Exception {
final Cache<String, String> cache = _buildCacheWithKeys("c_key", "a_key", "e_key", "b_key", "d_key");
PolymorphicWrapperBean outside = new PolymorphicWrapperBean();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package tools.jackson.datatype.guava;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.Nulls;

import tools.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import static org.junit.jupiter.api.Assertions.*;

public class EmptyCollectionsTest extends ModuleTestBase
{
// [datatypes-collections#67]
Expand All @@ -24,6 +28,7 @@ public static class ImmutableMapContainer67 {
.build();

// [datatypes-collections#67]
@Test
public void testEmptyForLists() throws Exception
{
ImmutableListContainer67 result;
Expand All @@ -47,6 +52,7 @@ public void testEmptyForLists() throws Exception
assertEquals(0, result.lists.size());
}

@Test
public void testEmptyForMaps() throws Exception
{
ImmutableMapContainer67 result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import java.util.Arrays;

import org.junit.jupiter.api.Test;

import com.google.common.collect.FluentIterable;

import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Unit tests to verify serialization of {@link FluentIterable}s.
*/
Expand All @@ -27,22 +31,24 @@ static FluentIterable<Integer> createFluentIterable() {
* or Guava's implementation of FluentIterable changes.
* @throws Exception
*/
@Test
public void testSerializationWithoutModule() throws Exception {
ObjectMapper mapper = new ObjectMapper();
FluentHolder holder = new FluentHolder();
String json = mapper.writeValueAsString(holder);
assertEquals("{\"value\":{\"empty\":false}}", json);
}

@Test
public void testSerialization() throws Exception {
String json = MAPPER.writeValueAsString(createFluentIterable());
assertEquals("[1,2,3]", json);
}

@Test
public void testWrappedSerialization() throws Exception {
FluentHolder holder = new FluentHolder();
String json = MAPPER.writeValueAsString(holder);
assertEquals("{\"value\":[1,2,3]}", json);
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package tools.jackson.datatype.guava;

import org.junit.jupiter.api.Test;

import com.google.common.hash.HashCode;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.exc.MismatchedInputException;

import com.google.common.hash.HashCode;
import static org.junit.jupiter.api.Assertions.*;

public class HashCodeTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

@Test
public void testSerialization() throws Exception
{
HashCode input = HashCode.fromString("cafebabe12345678");
String json = MAPPER.writeValueAsString(input);
assertEquals("\"cafebabe12345678\"", json);
}

@Test
public void testDeserialization() throws Exception
{
// success:
Expand Down
Loading

0 comments on commit edeec88

Please sign in to comment.