### Question:
UserRolesController { @ApiOperation(httpMethod = "GET", value = "API to get user role by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> getUserRoleById( @ApiParam(value = "provide valid role id", required = true) @RequestParam(defaultValue="", name = "roleId", required = true) String roleId) { try { return ResponseUtils.buildSucessResponse(userRolesService.getUserRoleById(roleId)); } 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 user roles details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRoles(
		@ApiParam(value = "provide valid page number", required = true) @RequestParam("page") Integer page,
		@ApiParam(value = "provide valid page size", required = true) @RequestParam("size") Integer size,
		@ApiParam(value = "provide valid search term", required = false) @RequestParam(defaultValue = StringUtils.EMPTY, name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "GET", value = "API to get user role by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getUserRoleById(
		@ApiParam(value = "provide valid role id", required = true) @RequestParam(defaultValue="", name = "roleId", required = true) String roleId); @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest); @ApiOperation(httpMethod = "POST", value = "API to update roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/update", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> updateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UpdateRoleDetailsRequest roleDetailsRequest);  }### Answer:
@Test public void getUserRoleByIdTest() throws Exception { UserRoles userRoleDetails = getUserRoleDetails(); when(userRolesService.getUserRoleById(anyString())).thenReturn(userRoleDetails); mockMvc.perform(get("/roles/details-by-id") .param("roleId", StringUtils.EMPTY)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.message", is("success"))); }
@Test @SuppressWarnings("unchecked") public void getUserRoleByIdExceptionTest() throws Exception { when(userRolesService.getUserRoleById(anyString())).thenThrow(Exception.class); mockMvc.perform(get("/roles/details-by-id") .param("roleId", StringUtils.EMPTY)) .andExpect(status().isExpectationFailed()) .andExpect(jsonPath("$.message", is(UNEXPECTED_ERROR_OCCURRED))); }