### Question:
UserRolesServiceImpl implements UserRolesService { @Override public UserRoles getUserRoleById(final String roleId) throws PacManException { boolean isRoleIdExits = userRolesRepository.existsById(roleId); if(isRoleIdExits) { return userRolesRepository.findById(roleId).get(); } else { throw new PacManException(USER_ROLE_NOT_EXITS); } }  @Override Page<UserRolesResponse> getAllUserRoles(String searchTerm, int page, int size); @Override String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId); @Override String updateUserRole(final UpdateRoleDetailsRequest roleDetailsRequest, final String userId); @Override UserRoles getUserRoleById(final String roleId);  }### Answer:
@Test public void getUserRoleByIdTest() throws PacManException { Optional<UserRoles> userRolesDetail = getUserRoleDetails(); when(userRolesRepository.existsById(anyString())).thenReturn(true); when(userRolesRepository.findById(anyString())).thenReturn(userRolesDetail); assertThat(userRolesService.getUserRoleById(anyString()).getOwner(), is("owner123")); }
@Test public void getUserRoleByIdRoleIdNotExitsTest() throws PacManException { Optional<UserRoles> userRolesDetail = getUserRoleDetails(); when(userRolesRepository.existsById(anyString())).thenReturn(false); when(userRolesRepository.findById(anyString())).thenReturn(userRolesDetail); assertThatThrownBy(() -> userRolesService.getUserRoleById(anyString())).isInstanceOf(PacManException.class); }