### Question:
MapController { @RequestMapping(value = "/setLayersForMap.action", method = RequestMethod.POST) public @ResponseBody java.util.Map<String, Object> setLayersForMap( @RequestParam("mapModuleId") Integer mapModuleId, @RequestParam("layerIds") List<Integer> layerIds) { try { if (mapModuleId == null || layerIds == null || layerIds.isEmpty()) { throw new Exception(); } List<Layer> layers = this.service.setLayersForMap(mapModuleId, layerIds); return ResultSet.success(layers); } catch (Exception e) { return ResultSet.error(COULD_NOT_SET_ERROR_MSG); } } @SuppressWarnings("unchecked")  MapController(); protected  MapController(Class<E> type); @Autowired @Qualifier("mapService") void setService(S service); @RequestMapping(value = "/setLayersForMap.action", method = RequestMethod.POST) @ResponseBody java.util.Map<String, Object> setLayersForMap(
        @RequestParam("mapModuleId") Integer mapModuleId,
        @RequestParam("layerIds") List<Integer> layerIds); static final String COULD_NOT_SET_ERROR_MSG; }### Answer:
@Test public void setLayersForMapTest_erroneous() throws Exception { final List<Integer> layerIds = new ArrayList<>(); layerIds.add(new Integer(1909)); Mockito.when(mapService.setLayersForMap( Matchers.any(int.class), Matchers.any(List.class) ) ).thenReturn(layerIds); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(SETLAYERS_ENDPOINT) .param("mapModuleId", "") .param("layerIds", "")) .andExpect(status().isOk()).andReturn(); assertEquals(result.getResponse().getStatus(), 200); String content = result.getResponse().getContentAsString(); ObjectMapper objectMapper = new ObjectMapper(); Assert.assertEquals("Returned body matched mocked one.", objectMapper.writeValueAsString(ResultSet.error(MapController.COULD_NOT_SET_ERROR_MSG)), content); Mockito.verify(mapService, Mockito.times(0)). setLayersForMap( Matchers.any(int.class), Matchers.any(List.class) ); Mockito.verifyNoMoreInteractions(mapService); }
@Test public void setLayersForMapTest_ok() throws Exception { final List<Integer> layerIds = new ArrayList<>(); layerIds.add(new Integer(1909)); Mockito.when(mapService.setLayersForMap( Matchers.any(int.class), Matchers.anyList() ) ).thenReturn(layerIds); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(SETLAYERS_ENDPOINT) .param("mapModuleId", "1909") .param("layerIds", "0815") .param("layerIds", "4711")) .andExpect(status().isOk()).andReturn(); String content = result.getResponse().getContentAsString(); ObjectMapper objectMapper = new ObjectMapper(); Assert.assertEquals("Returned body matched mocked one.", objectMapper.writeValueAsString(ResultSet.success(layerIds)), content); Mockito.verify(mapService, Mockito.times(1)). setLayersForMap( Matchers.any(int.class), Matchers.any(List.class) ); Mockito.verifyNoMoreInteractions(mapService); }