### Question:
DatasourceController { @ApiOperation(httpMethod = "GET", value = "API to get all datasource details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> getAllDatasourceDetails() { try { return ResponseUtils.buildSucessResponse(datasourceService.getAllDatasourceDetails()); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  @ApiOperation(httpMethod = "GET", value = "API to get all datasource details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) //@PreAuthorize("@securityService.hasPermission(authentication)") @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllDatasourceDetails();  }### Answer:
@Test public void getAllDatasourceDetailsTest() throws Exception { when(datasourceService.getAllDatasourceDetails()).thenReturn(new ArrayList<>()); mockMvc.perform(get("/datasource/list")).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.data", hasSize(0))); }
@Test @SuppressWarnings("unchecked") public void getAllDatasourceDetailsExceptionTest() throws Exception { when(datasourceService.getAllDatasourceDetails()).thenThrow(Exception.class); mockMvc.perform(get("/datasource/list").contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(status().isExpectationFailed()).andExpect(jsonPath("$.message", is(UNEXPECTED_ERROR_OCCURRED))); }