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 6a94443 + 14d1ffb commit fefa9bb
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 103 deletions.
3 changes: 2 additions & 1 deletion eclipse-collections/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
requires org.eclipse.collections.impl;

// 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 @@ -42,8 +42,9 @@
import org.eclipse.collections.impl.factory.primitive.*;
import org.eclipse.collections.impl.tuple.Tuples;
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public final class DeserializerTest extends ModuleTestBase {

Expand Down Expand Up @@ -327,7 +328,7 @@ static void primitiveMaps0(ObjectMapper mapper, boolean serialize) throws Except
.getMethod("ofAll", baseMapType)
.invoke(immutableFactory, mutableSample);

Assert.assertEquals(mutableSample, immutableSample);
assertEquals(mutableSample, immutableSample);

Function<Class<?>, JavaType> generify;
if (key == Object.class || value == Object.class) {
Expand All @@ -345,21 +346,21 @@ static void primitiveMaps0(ObjectMapper mapper, boolean serialize) throws Except
mapper.writerFor(generify.apply(baseMapType)).writeValueAsString(mutableSample);
String polyPrinted = mapper.writeValueAsString(mutableSample);
// compare trees so property order doesn't matter
Assert.assertEquals(mapper.readTree(json), mapper.readTree(mutablePrinted));
Assert.assertEquals(mapper.readTree(json), mapper.readTree(immutablePrinted));
Assert.assertEquals(mapper.readTree(json), mapper.readTree(basePrinted));
Assert.assertEquals(mapper.readTree(json), mapper.readTree(polyPrinted));
assertEquals(mapper.readTree(json), mapper.readTree(mutablePrinted));
assertEquals(mapper.readTree(json), mapper.readTree(immutablePrinted));
assertEquals(mapper.readTree(json), mapper.readTree(basePrinted));
assertEquals(mapper.readTree(json), mapper.readTree(polyPrinted));
} else {
Object mutableParsed = mapper.readValue(json, generify.apply(mutableMapType));
Object immutableParsed = mapper.readValue(json, generify.apply(immutableMapType));
Object baseParsed = mapper.readValue(json, generify.apply(baseMapType));
Assert.assertEquals(mutableSample, mutableParsed);
Assert.assertEquals(immutableSample, immutableParsed);
Assert.assertEquals(mutableSample, baseParsed);
assertEquals(mutableSample, mutableParsed);
assertEquals(immutableSample, immutableParsed);
assertEquals(mutableSample, baseParsed);

Assert.assertTrue(mutableMapType.isInstance(mutableParsed));
Assert.assertTrue(immutableMapType.isInstance(immutableParsed));
Assert.assertTrue(baseMapType.isInstance(baseParsed));
assertTrue(mutableMapType.isInstance(mutableParsed));
assertTrue(immutableMapType.isInstance(immutableParsed));
assertTrue(baseMapType.isInstance(baseParsed));
}
}
}
Expand All @@ -371,19 +372,19 @@ private static String capitalize(String simpleName) {

@Test
public void objectObjectMaps() throws Exception {
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<MutableMap<String, String>>() {}),
Maps.mutable.of("abc", "def")
);
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<ImmutableMap<String, String>>() {}),
Maps.immutable.of("abc", "def")
);
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<MapIterable<String, String>>() {}),
Maps.mutable.of("abc", "def")
);
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue("{\"abc\":\"def\"}",
new TypeReference<UnsortedMapIterable<String, String>>() {}),
Maps.mutable.of("abc", "def")
Expand All @@ -405,7 +406,7 @@ private static Object randomSample(Class<?> type) {

@Test
public void typeInfoObjectMap() throws Exception {
Assert.assertEquals(
assertEquals(
mapperWithModule()
.readValue("{\"map\":{\"0\":{\"@c\":\".DeserializerTest$B\"}}}", Container.class).map,
IntObjectMaps.immutable.of(0, new B())
Expand Down Expand Up @@ -442,7 +443,7 @@ public void typeInfoNestedMapList() throws Exception {
// test case for jackson-datatypes-collections#71
ImmutableMap<String, ImmutableList<A>> property =
Maps.immutable.of("foo", Lists.immutable.of(new B()));
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue(
"{\"foo\": [{\"@c\": \".DeserializerTest$B\"}]}",
new TypeReference<ImmutableMap<String, ImmutableList<A>>>() {}),
Expand All @@ -455,7 +456,7 @@ public void typeInfoNestedMapMap() throws Exception {
// auxiliary test case for jackson-datatypes-collections#71 - also worked before fix
ImmutableMap<String, ImmutableMap<String, A>> property =
Maps.immutable.of("foo", Maps.immutable.of("bar", new B()));
Assert.assertEquals(
assertEquals(
mapperWithModule().readValue(
"{\"foo\": {\"bar\": {\"@c\": \".DeserializerTest$B\"}}}",
new TypeReference<ImmutableMap<String, ImmutableMap<String, A>>>() {}),
Expand Down Expand Up @@ -517,8 +518,8 @@ public void primitivePairs() throws Exception {
+ ",\"two\":" + mapperWithModule().writeValueAsString(sampleTwo) + "}";
Object samplePair = factory.invoke(null, sampleOne, sampleTwo);

Assert.assertEquals(expectedJson, mapperWithModule().writeValueAsString(samplePair));
Assert.assertEquals(samplePair, mapperWithModule().readValue(expectedJson, pairType));
assertEquals(expectedJson, mapperWithModule().writeValueAsString(samplePair));
assertEquals(samplePair, mapperWithModule().readValue(expectedJson, pairType));
}
}
}
Expand All @@ -531,8 +532,8 @@ public void twin() throws Exception {
String expectedJson = "{\"one\":" + mapper.writeValueAsString(sampleOne)
+ ",\"two\":" + mapper.writeValueAsString(sampleTwo) + "}";
Twin<String> twin = Tuples.twin((String) sampleOne, (String) sampleTwo);
Assert.assertEquals(expectedJson, mapper.writeValueAsString(twin));
Assert.assertEquals(twin, mapper.readValue(expectedJson, new TypeReference<Twin<String>>() {}));
assertEquals(expectedJson, mapper.writeValueAsString(twin));
assertEquals(twin, mapper.readValue(expectedJson, new TypeReference<Twin<String>>() {}));
}

@Test
Expand All @@ -542,8 +543,8 @@ public void pairTyped() throws Exception {
final String actJson = mapper.writerFor(new TypeReference<ObjectIntPair<A>>() {})
.writeValueAsString(pair);
String expJson = "{\"one\":{\"@c\":\".DeserializerTest$B\"},\"two\":5}";
Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
Assert.assertEquals(pair,
assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
assertEquals(pair,
mapper.readValue(actJson, new TypeReference<ObjectIntPair<A>>() {})
);
}
Expand All @@ -554,8 +555,8 @@ public void nestedMap() throws Exception {
String json = "{\"a\":{\"b\":\"c\"}}";
TypeReference<MutableMap<String, MutableMap<String, String>>> type =
new TypeReference<MutableMap<String, MutableMap<String, String>>>() {};
Assert.assertEquals(json, mapperWithModule().writerFor(type).writeValueAsString(pair));
Assert.assertEquals(pair, mapperWithModule().readValue(json, type));
assertEquals(json, mapperWithModule().writerFor(type).writeValueAsString(pair));
assertEquals(pair, mapperWithModule().readValue(json, type));
}

@Test
Expand All @@ -565,8 +566,8 @@ public void triple() throws Exception {
String actJson = mapper.writerFor(new TypeReference<Triple<String, Integer, Boolean>>() {})
.writeValueAsString(triple);
String expJson = "{\"one\":\"a\",\"two\":2,\"three\":false}";
Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
Assert.assertEquals(
assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
assertEquals(
triple,
mapper.readValue(actJson, new TypeReference<Triple<String, Integer, Boolean>>() {})
);
Expand All @@ -579,8 +580,8 @@ public void triplet() throws Exception {
String actJson = mapper.writerFor(new TypeReference<Triplet<String>>() {})
.writeValueAsString(triple);
String expJson = "{\"one\":\"a\",\"two\":\"b\",\"three\":\"c\"}";
Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
Assert.assertEquals(
assertEquals(mapper.readTree(expJson), mapper.readTree(actJson));
assertEquals(
triple,
mapper.readValue(actJson, new TypeReference<Triplet<String>>() {})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package tools.jackson.datatype.eclipsecollections;

import static org.junit.Assert.assertTrue;

import org.junit.Assert;
import org.junit.Test;

import org.eclipse.collections.api.map.primitive.MutableCharCharMap;
import org.junit.jupiter.api.Test;

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

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

/**
* Unit tests for verifying the fixes for OSS-Fuzz issues
* work as expected
Expand All @@ -25,7 +23,7 @@ public void testOSSFuzzIssue64629() throws Exception
// Invalid token {"x?":[x?]: where ? is not ascii characters
final char[] invalid = {123, 34, 824, 34, 58, 91, 120, 7, 93};

MismatchedInputException e = Assert.assertThrows(
MismatchedInputException e = assertThrows(
MismatchedInputException.class,
() -> MAPPER.readValue(new String(invalid), MutableCharCharMap.class));
assertTrue(e.getMessage().contains("Cannot convert a JSON Null into a char element of map"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package tools.jackson.datatype.eclipsecollections;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

import java.util.Arrays;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;

import tools.jackson.core.type.TypeReference;

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

public abstract class ModuleTestBase {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.fail;

public abstract class ModuleTestBase
{
protected ObjectMapper mapperWithModule() {
return mapperBuilder().build();
}
Expand Down Expand Up @@ -44,19 +42,19 @@ protected final <T> void testCollection(
for (TypeReference<?> type : types) {
ObjectMapper objectMapper = mapperWithModule();
Object value = objectMapper.readValue(json, type);
Assert.assertEquals(expected, value);
assertEquals(expected, value);
Class<?> collectionClass =
objectMapper.getTypeFactory().constructType(type).getRawClass();
assertThat(value, CoreMatchers.instanceOf(collectionClass));
assertInstanceOf(collectionClass, value);
}
}

protected final <T> void testCollection(T expected, String json, Class<?>... types)
{
for (Class<?> type : types) {
Object value = mapperWithModule().readValue(json, type);
Assert.assertEquals(expected, value);
assertThat(value, CoreMatchers.instanceOf(type));
assertEquals(expected, value);
assertInstanceOf(type, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tools.jackson.datatype.eclipsecollections;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonTypeInfo;

Expand All @@ -27,6 +26,8 @@
import org.eclipse.collections.impl.factory.primitive.LongLists;
import org.eclipse.collections.impl.factory.primitive.ShortLists;

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

public final class SerializerTest extends ModuleTestBase {
static class Wrapper {
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
Expand All @@ -37,37 +38,37 @@ static class Wrapper {

@Test
public void ref() throws Exception {
Assert.assertEquals(
assertEquals(
"[\"a\",\"b\",\"c\"]",
MAPPER.writeValueAsString(Sets.immutable.of("a", "b", "c"))
);
}

@Test
public void primitive() throws Exception {
Assert.assertEquals("[true,false,true]", MAPPER.writeValueAsString(
assertEquals("[true,false,true]", MAPPER.writeValueAsString(
BooleanLists.immutable.of(true, false, true)));
Assert.assertEquals("[1,2,3]", MAPPER.writeValueAsString(
assertEquals("[1,2,3]", MAPPER.writeValueAsString(
ShortLists.immutable.of((short) 1, (short) 2, (short) 3)));
Assert.assertEquals("[1,2,3]", MAPPER.writeValueAsString(
assertEquals("[1,2,3]", MAPPER.writeValueAsString(
IntLists.immutable.of(1, 2, 3)));
Assert.assertEquals("[1.1,2.3,3.5]", MAPPER.writeValueAsString(
assertEquals("[1.1,2.3,3.5]", MAPPER.writeValueAsString(
FloatLists.immutable.of(1.1F, 2.3F, 3.5F)));
Assert.assertEquals("[1,2,3]", MAPPER.writeValueAsString(
assertEquals("[1,2,3]", MAPPER.writeValueAsString(
LongLists.immutable.of(1, 2, 3)));
Assert.assertEquals("[1.1,2.3,3.5]", MAPPER.writeValueAsString(
assertEquals("[1.1,2.3,3.5]", MAPPER.writeValueAsString(
DoubleLists.immutable.of(1.1, 2.3, 3.5)));

Assert.assertEquals(
assertEquals(
MAPPER.writeValueAsString(new byte[]{ 1, 2, 3 }),
MAPPER.writeValueAsString(ByteLists.immutable.of((byte) 1, (byte) 2, (byte) 3)));
Assert.assertEquals(
assertEquals(
MAPPER.writeValueAsString(new char[]{ '1', '2', '3' }),
MAPPER.writeValueAsString(CharLists.immutable.of('1', '2', '3')));
Assert.assertEquals(
assertEquals(
MAPPER.writer().with(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS)
.writeValueAsString(new char[]{ '1', '2', '3' }),
MAPPER.writer().with(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS)
MAPPER.writer().with(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS)
.writeValueAsString(CharLists.immutable.of('1', '2', '3')));
}

Expand Down Expand Up @@ -109,7 +110,7 @@ private void primitiveTypeSer(String data, PrimitiveIterable iterable,
Wrapper wrapper = new Wrapper();
wrapper.object = iterable;

Assert.assertEquals("{\"object\":[\"" + iterable.getClass().getName() + "\"," + data + "]}",
assertEquals("{\"object\":[\"" + iterable.getClass().getName() + "\"," + data + "]}",
objectMapper.writeValueAsString(wrapper));
}

Expand All @@ -121,27 +122,27 @@ public void primitiveMaps() throws Exception

@Test
public void objectObjectMaps() throws Exception {
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writerFor(MutableMap.class).writeValueAsString(Maps.mutable.of("abc", "def"))
);
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writerFor(ImmutableMap.class).writeValueAsString(Maps.immutable.of("abc", "def"))
);
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writerFor(MapIterable.class).writeValueAsString(Maps.immutable.of("abc", "def"))
);
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writerFor(MutableMapIterable.class).writeValueAsString(Maps.mutable.of("abc", "def"))
);
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writeValueAsString(Maps.immutable.of("abc", "def"))
);
Assert.assertEquals(
assertEquals(
"{\"abc\":\"def\"}",
MAPPER.writerFor(new TypeReference<MapIterable<String, String>>() {})
.writeValueAsString(Maps.immutable.of("abc", "def"))
Expand All @@ -150,7 +151,7 @@ public void objectObjectMaps() throws Exception {

@Test
public void typeInfoObjectMap() throws Exception {
Assert.assertEquals(
assertEquals(
"{\"map\":{\"0\":{\"@c\":\".SerializerTest$B\"}}}",
MAPPER.writeValueAsString(new Container())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Collections;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import tools.jackson.core.type.TypeReference;

Expand Down
Loading

0 comments on commit fefa9bb

Please sign in to comment.