Skip to content

Lacking org.hamcrest.Matcher helpers to perform assertion in unit tests #162

Description

@DevDengChao

Story

Spring MVC's MockMvcResultMatchers#jsonPath() uses com.jayway.jsonpath.JsonPath to evaluate string content into objects, and JsonPath uses JsonSmartJsonProvider by default, when a developer attempt to do an unit test like below, there is no suitable helper methods he/she can use:

/*
{
    "firstName": "John",
    "lastName": "doe",
    "age": 26,
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": [
        {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}
*/
mockMvc.perform(get("/user/John"))
    .andExpect(jsonPath("$.phoneNumbers[*].type").value( ??? ));

Expected solution

Provide some org.hamcrest.Matcher helpers like Matchers.arrayContaining() ?

Related documents

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions