1
0

Deserializer: BadRequestAlertException("Unknown property") with test code coverage

This commit is contained in:
Michael Hoennig
2019-05-15 07:41:21 +02:00
parent 60612f6c41
commit f9b68df901
5 changed files with 38 additions and 3 deletions

View File

@ -399,6 +399,24 @@ public class JSonDeserializationWithAccessFilterUnitTest {
.hasMessageContaining("GivenDtoWithUnknownFieldType.unknown");
}
@Test
public void shouldDetectUnknownPropertyName() throws IOException {
// given
securityContext.havingAuthenticatedUser().withAuthority(AuthoritiesConstants.ADMIN);
givenJSonTree(asJSon(ImmutablePair.of("somePropWhichDoesNotExist", "Some Value")));
// when
final Throwable exception = catchThrowable(
() -> deserializerForGivenDto().deserialize(jsonParser, null));
// then
assertThat(exception).isInstanceOfSatisfying(BadRequestAlertException.class, (exc) -> {
assertThat(exc).hasMessageStartingWith("Unknown property");
assertThat(exc.getParam()).isEqualTo("somePropWhichDoesNotExist");
assumeThat(exc.getErrorKey()).isEqualTo("unknownProperty");
});
}
// --- only fixture code below ---
private void givenJSonTree(String givenJSon) throws IOException {