@Test
    public void testBook() throws Exception {

        mvc.perform(MockMvcRequestBuilders.get("/book")
                        .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.id", is(1)))
                .andExpect(jsonPath("$.id").isNumber())
                .andExpect(jsonPath("$.title").exists())
                .andExpect(jsonPath("$.title", is("Modern Java in Action")))
                .andExpect(jsonPath("$.bookName").doesNotExist())
                .andExpect(jsonPath("$.bookName").doesNotExist())
                .andExpect(jsonPath("$.tags").isArray())
                .andExpect(jsonPath("$.tags", hasSize(2)))
                .andExpect(jsonPath("$.tags", hasItem("Java"))) // order not fix, check with contains
                .andExpect(jsonPath("$.tags", hasItem("Java 8")))
                .andExpect(jsonPath("$.publishedDate", is(LocalDate.of(2018, 11, 15).toString())))
                .andExpect(jsonPath("$.authors", hasSize(3)))
                .andExpect(jsonPath("$.meta.isbn-10", is("1617293563")))
                .andExpect(jsonPath("$.meta.isbn-13", is("978-1617293566")))
                // better convert to list of objects and test it, see below testBookAuthor
                .andExpect(jsonPath("$.authors[*].id", hasItem(1)))
                .andExpect(jsonPath("$.authors[*].id", containsInAnyOrder(3, 1, 2)))
                .andExpect(jsonPath("$.authors[*].name", hasItem("Raoul-Gabriel Urma")))
                .andExpect(jsonPath("$.authors[*].phoneNo", hasItem("111-1111111")));

                /*.andExpect(jsonPath("$.authors[0].id").value(1))  // first author of the book
                .andExpect(jsonPath("$.authors[0].name").value("Raoul-Gabriel Urma"))
                .andExpect(jsonPath("$.authors[0].phoneNo").value("111-1111111"))

                .andExpect(jsonPath("$.authors[1].id").value(2))    // second author of the book
                .andExpect(jsonPath("$.authors[2].name").value("Mario Fusco"))
                .andExpect(jsonPath("$.authors[3].phoneNo").value("222-2222222")
                );*/

    }
{
"id" : 1,
"title" : "Modern Java in Action",
"tags" : [ "Java", "Java 8" ],
"authors" : [ {
"id" : 1,
"name" : "Raoul-Gabriel Urma",
"phoneNo" : "111-1111111"
}, {
"id" : 2,
"name" : "Mario Fusco",
"phoneNo" : "222-2222222"
}, {
"id" : 3,
"name" : "Alan Mycroft",
"phoneNo" : "333-3333333"
} ],
"publishedDate" : "2018-11-15",
"meta" : {
"isbn-10" : "1617293563",
"isbn-13" : "978-1617293566"
}
}
spring-boot-test-json/src/test/java/com/mkyong/WebControllerTest.java