### Question:
UserRolesMappingController { @ApiOperation(httpMethod = "GET", value = "API to get all user roles mappings details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> getAllUserRolesMapping( @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="", name = "searchTerm", required = false) String searchTerm) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.getAllUserRolesMapping(searchTerm.trim(), page, size)); } 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 mappings details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRolesMapping(
		@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="", name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest);  }### Answer:
@Test public void getAllUserRolesMappingTest() throws Exception { List<UserRolesMappingResponse> userRolesDetails = new ArrayList<UserRolesMappingResponse>(); userRolesDetails.add(getUserRolesMappingDetails()); Page<UserRolesMappingResponse> allUserRolesDetails = new PageImpl<UserRolesMappingResponse>(userRolesDetails,new PageRequest(0, 1), userRolesDetails.size()); when(userRolesMappingService.getAllUserRolesMapping(anyString(), anyInt(), anyInt())).thenReturn(allUserRolesDetails); mockMvc.perform(get("/users-roles/list") .param("searchTerm", StringUtils.EMPTY) .param("page", "0") .param("size", "1")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.message", is("success"))); }
@Test @SuppressWarnings("unchecked") public void getAllUserRolesMappingExceptionTest() throws Exception { when(userRolesMappingService.getAllUserRolesMapping(anyString(), anyInt(), anyInt())).thenThrow(Exception.class); mockMvc.perform(get("/users-roles/list") .param("searchTerm", StringUtils.EMPTY) .param("page", "0") .param("size", "1")) .andExpect(status().isExpectationFailed()) .andExpect(jsonPath("$.message", is(UNEXPECTED_ERROR_OCCURRED))); }