From 264c1ca99edd713afca48bfed0e1bf837fb6ded3 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 12 Nov 2024 15:16:00 -0800 Subject: [PATCH] Fix unit tests wrt `jackson-databind` change wrt abstract Collection deserializer error messages --- .../guava/ImmutableContainersTest.java | 21 +++++++++++++------ .../jackson/datatype/guava/MultisetsTest.java | 6 +++++- .../pcollections/TestPCollections.java | 14 +++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java index 1aa47970..f11371b2 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java @@ -68,7 +68,7 @@ public void testWithoutSerializers() throws Exception /** * Deserialization will fail, however. */ - public void testWithoutDeserializers() throws Exception + public void testWithoutDeserializersFail() throws Exception { ObjectMapper mapper = new ObjectMapper(); try { @@ -76,31 +76,40 @@ public void testWithoutDeserializers() throws Exception new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + _verifyImmutableException(e, ImmutableList.class); } try { mapper.readValue("[1,2,3]", new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + _verifyImmutableException(e, ImmutableSet.class); } try { mapper.readValue("[1,2,3]", new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + _verifyImmutableException(e, ImmutableSortedSet.class); } - + + // 12-Nov-2024, tatu: Failure message for Maps only changed in 2.19, however try { mapper.readValue("{\"a\":true,\"b\":false}", new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + verifyException(e, "Cannot find a deserializer for non-concrete"); } } + private void _verifyImmutableException(InvalidDefinitionException e, Class type) { + // Exception changed a bit in 2.18.2, need to match + //verifyException(e, "cannot find a deserializer"); + verifyException(e, "Cannot construct instance of "); + verifyException(e, "No creators"); + verifyException(e, type.getName()); + } + /* /********************************************************************** /* Unit tests for actual registered module diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java index a351aad8..5e29a28d 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/MultisetsTest.java @@ -46,7 +46,11 @@ public void testWithoutDeserializers() throws Exception new TypeReference>() { }); fail("Should have failed"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + // Exception changed a bit in 2.18.2, need to match + //verifyException(e, "cannot find a deserializer"); + verifyException(e, "Cannot construct instance of "); + verifyException(e, "No creators"); + verifyException(e, Multiset.class.getName()); } } diff --git a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java index c062f4ba..2fb96d32 100644 --- a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java +++ b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java @@ -65,24 +65,34 @@ public void withoutDeserializers() throws Exception new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + _verifyImmutableException(e, PSequence.class); } try { mapper.readValue("[1,2,3]", new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { - verifyException(e, "cannot find a deserializer"); + _verifyImmutableException(e, PSet.class); } try { mapper.readValue("{\"a\":true,\"b\":false}", new TypeReference>() { }); fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { + // 12-Nov-2024, tatu: Map exception changes in 2.19, not yet in 2.18 so +// _verifyImmutableException(e, PMap.class); verifyException(e, "cannot find a deserializer"); } } + private void _verifyImmutableException(InvalidDefinitionException e, Class type) { + // Exception changed a bit in 2.18.2, need to match + //verifyException(e, "cannot find a deserializer"); + verifyException(e, "Cannot construct instance of "); + verifyException(e, "No creators"); + verifyException(e, type.getName()); + } + /* /********************************************************************** /* Unit tests for actual registered module