lundi 16 avril 2018

Assertion for null value using Hamcrest and jsonPath

I would like to assert json output from rest controller, but I get "Expected: null but: was <[null]>". This is my testing code:

mockMvc.perform(post(TEST_ENDPOINT)
            .param("someParam", SOMEPARAM)
            .andDo(print())
            .andExpect(status().is2xxSuccessful())
            .andExpect(jsonPath("*.errorMessage").value(IsNull.nullValue())); 

Json:

{
    "some_string": {
        "errorMessage": null
    }
}

I found similar question How to assertThat something is null with Hamcrest?, but neither answers do work. Maybe this is due to jsonPath, cause it return null value in [] brackets?

Aucun commentaire:

Enregistrer un commentaire