@Test public void identifyUser_usesDAO() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); when(passwordEncoder.matches(USER_A_PASSWORD, USER_A_PASSWORD_ENCODED)).thenReturn(true); communityServiceImpl.identifyUser(userA); verify(userRepository, times(1)).findOne(USER_A_NAME); }
@Test(expected = IllegalArgumentException.class) public void identifyUser_throwsIllegalArgumentException_002() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); when(passwordEncoder.matches(USER_A_PASSWORD, USER_A_PASSWORD_ENCODED)).thenReturn(false); userA.setPassword(""); communityServiceImpl.identifyUser(userA); }
@Test public void findOne_usesDAO() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userA); User user = communityServiceImpl.findOne(USER_A_NAME); assertEquals(userA, user); verify(userRepository, times(1)).findOne(USER_A_NAME); }
@Test(expected = ConstraintViolationException.class) public void createUser_byRoles_throwsForConflict() { when(userRepository.save(userA)).thenReturn(userA); when(userRepository.findOne(USER_A_NAME)) .thenThrow(new ConstraintViolationException("", null, null)); communityServiceImpl.createUser(userA, Role.ROLE_BASIC); }
@Test(expected = ConstraintViolationException.class) public void createUserWithBalance_throwsForConflict() { when(userRepository.save(userA)).thenReturn(userA); when(userRepository.findOne(USER_A_NAME)) .thenThrow(new ConstraintViolationException("", null, null)); Role[] roles = {Role.ROLE_BASIC, Role.ROLE_OAUTH2}; BigDecimal balance = new BigDecimal(123); communityServiceImpl.createUserWithBalance(userA, roles, balance); }
@Test(expected = ResourceAccessException.class) public void loadUserByUsername_throwsResourceAccessException() { when(userRepository.findOne(USER_A_NAME)).thenReturn(null); when(securityContext.getAuthentication()).thenReturn(authentication); when(authentication.getPrincipal()).thenReturn(null); communityServiceImpl.loadUserByUsername(USER_A_NAME); verify(securityContext, times(1)).getAuthentication(); verify(authentication, times(1)).getPrincipal(); }
@Test public void loadUserByUsername_usesSecurityContext() { when(userRepository.findOne(USER_A_NAME)).thenReturn(null); when(securityContext.getAuthentication()).thenReturn(authentication); when(authentication.getPrincipal()).thenReturn(userA); UserDetails result = communityServiceImpl.loadUserByUsername(USER_A_NAME); verify(securityContext, times(1)).getAuthentication(); verify(authentication, times(1)).getPrincipal(); assertEquals(USER_A_NAME, result.getUsername()); }
@Test public void loadUserByUsername_usesDAO() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); communityServiceImpl.loadUserByUsername(USER_A_NAME); verify(userRepository, times(1)).findOne(USER_A_NAME); }
@Test public void findByLogin_setsFilteredAttributes() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); UserDTO userDTO = communityServiceImpl.findByLogin(USER_A_NAME); assertDTOWithHiddenValues(userDTO, userA); }
@Test public void findByLogin_usesDAO() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); communityServiceImpl.findByLogin(USER_A_NAME); verify(userRepository, times(1)).findOne(USER_A_NAME); }
@Test(expected = BadCredentialsException.class) public void identifyUser_throwsBadCredentialsException() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userAStored); when(passwordEncoder.matches(USER_A_PASSWORD, USER_A_PASSWORD_ENCODED)).thenReturn(false); communityServiceImpl.identifyUser(userA); }
@Test public void getUser_usesDAO() { when(userRepository.findOne(USER_A_NAME)).thenReturn(userA); communityServiceImpl.getUser(USER_A_NAME); verify(userRepository, times(1)).findOne(USER_A_NAME); }