Skip to content

Commit

Permalink
Fix unit tests wrt jackson-databind change wrt abstract Collection …
Browse files Browse the repository at this point in the history
…deserializer error messages
  • Loading branch information
cowtowncoder committed Nov 12, 2024
1 parent e743aea commit 264c1ca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,48 @@ public void testWithoutSerializers() throws Exception
/**
* Deserialization will fail, however.
*/
public void testWithoutDeserializers() throws Exception
public void testWithoutDeserializersFail() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readValue("[1,2,3]",
new TypeReference<ImmutableList<Integer>>() { });
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<ImmutableSet<Integer>>() { });
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<ImmutableSortedSet<Integer>>() { });
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<ImmutableMap<Integer,Boolean>>() { });
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public void testWithoutDeserializers() throws Exception
new TypeReference<Multiset<String>>() { });
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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,34 @@ public void withoutDeserializers() throws Exception
new TypeReference<PSequence<Integer>>() { });
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<PSet<Integer>>() { });
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<PMap<Integer,Boolean>>() { });
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
Expand Down

0 comments on commit 264c1ca

Please sign in to comment.