### Question:
UserMgr { public boolean isUserInRole(Long userId, String role) { XXPortalUserRole xXPortalUserRole = daoManager.getXXPortalUserRole() .findByRoleUserId(userId, role); if (xXPortalUserRole != null) { String userRole = xXPortalUserRole.getUserRole(); if (userRole.equalsIgnoreCase(role)) { return true; } } return false; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForRead(XXPortalUser gjUser); String encrypt(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId);  }### Answer:
@Test public void test23IsUserInRole() { XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class); XXPortalUserRole XXPortalUserRole = new XXPortalUserRole(); XXPortalUserRole.setId(userId); XXPortalUserRole.setUserRole("ROLE_USER"); List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>(); list.add(XXPortalUserRole); Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao); Mockito.when(roleDao.findByRoleUserId(userId, "ROLE_USER")).thenReturn( XXPortalUserRole); boolean isValue = userMgr.isUserInRole(userId, "ROLE_USER"); Assert.assertTrue(isValue); Mockito.verify(daoManager).getXXPortalUserRole(); }