Spring MockMvc verify body is empty

There’s a cleaner way:

andExpect(jsonPath("$").doesNotExist())

Note that you can’t use isEmpty because it checks for an empty value, and assumes the existence of the attribute. When the attribute doesn’t exist, isEmpty throws an exception. Whereas, doesNotExist verifies that the attribute doesn’t exist, and when used with $, it checks for an empty JSON document.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)