January 2018
Intermediate to advanced
414 pages
10h 29m
English
We will now work on our CustomerControllerTest to make it more expressive.
First, let's look at our original test for the list of customers:
@Testfun `we should GET a list of customers`() { given(customerService.getAllCustomers()) .willReturn(listOf(Customer(1, "test"), Customer(2, "mocks"))) mockMvc.perform(get("/customers")) .andExpect(status().isOk) .andExpect(jsonPath("\$").isArray) .andExpect(jsonPath("\$[0].id").value(1)) .andExpect(jsonPath("\$[0].name").value("test")) .andExpect(jsonPath("\$[1].id").value(2)) .andExpect(jsonPath("\$[1].name").value("mocks")) .andDo(print()) then(customerService).should(times(1)).getAllCustomers() then(customerService).shouldHaveNoMoreInteractions() reset(customerService ...
Read now
Unlock full access