@Test public void givenOneEmployee_whenGetEmployees_thenReturnCorrectJson() throws Exception { Employee employee = new EmployeeTestBuilder() .withIncome(200) .withFirstName("firstName") .build(); EmployeeTo employeeTo = new EmployeeTo(employee.getFirstName(), employee.getLastName(), employee.getEmail(), employee.getIncome(), Money.parse("EUR 200"), 1L, 0l); String expectedJSON = new Jackson2JsonObjectMapper().toJson(asList(employeeTo)); when(presentationEmployeeRepository.getEmployees(0, 10)).thenReturn(asList(employeeTo)); MvcResult mvcResult = mockMvc.perform(get("/employees?page=0&pageSize=10").contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); String actualJSON = mvcResult.getResponse().getContentAsString(); assertThat(actualJSON).isEqualTo(expectedJSON); }
@RequestMapping(method = RequestMethod.GET) @ResponseBody public List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize) { return presentationEmployeeRepository.getEmployees(page, pageSize); }
EmployeeRestController { @RequestMapping(method = RequestMethod.GET) @ResponseBody public List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize) { return presentationEmployeeRepository.getEmployees(page, pageSize); } }
EmployeeRestController { @RequestMapping(method = RequestMethod.GET) @ResponseBody public List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize) { return presentationEmployeeRepository.getEmployees(page, pageSize); }  }
EmployeeRestController { @RequestMapping(method = RequestMethod.GET) @ResponseBody public List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize) { return presentationEmployeeRepository.getEmployees(page, pageSize); }  @RequestMapping(method = RequestMethod.GET) @ResponseBody List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize); @RequestMapping(value = "/count", method = RequestMethod.GET) @ResponseBody long getEmployeeCount(); @RequestMapping(value = "/{employeeId}/details", method = RequestMethod.GET) @ResponseBody EmployeeTo getEmployeeDetails(@PathVariable(value = "employeeId") Long employeeId); @RequestMapping(value = "/{employeeId}/taxes", method = RequestMethod.GET) @ResponseBody List<EmployeeTaxTo> getEmployeeTaxes(@PathVariable(value = "employeeId") Long employeeId); }
EmployeeRestController { @RequestMapping(method = RequestMethod.GET) @ResponseBody public List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize) { return presentationEmployeeRepository.getEmployees(page, pageSize); }  @RequestMapping(method = RequestMethod.GET) @ResponseBody List<EmployeeTo> getEmployees(@RequestParam int page, @RequestParam int pageSize); @RequestMapping(value = "/count", method = RequestMethod.GET) @ResponseBody long getEmployeeCount(); @RequestMapping(value = "/{employeeId}/details", method = RequestMethod.GET) @ResponseBody EmployeeTo getEmployeeDetails(@PathVariable(value = "employeeId") Long employeeId); @RequestMapping(value = "/{employeeId}/taxes", method = RequestMethod.GET) @ResponseBody List<EmployeeTaxTo> getEmployeeTaxes(@PathVariable(value = "employeeId") Long employeeId);  }