Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC Test empty json

How can I test for an empty JSON response from a rest endpoint. I was hoping for something along the lines:

    ResultActions actions = mockMvc.perform(..);
    actions.andExpect(jsonPath("$", empty()));

obviously this fails as {} is not exactly empty. Any advice?

like image 426
Suryavanshi Avatar asked Dec 05 '15 11:12

Suryavanshi


2 Answers

Try this one:

 ResultActions actions = mockMvc.perform(..);
 actions.andExpect(content().string("[]"));
like image 128
mdziob Avatar answered Oct 22 '22 01:10

mdziob


This worked for me:

ResultActions actions = mockMvc.perform(..);
actions.andExpect(content().string(""));
like image 26
Juan Bustamante Avatar answered Oct 22 '22 00:10

Juan Bustamante