Пример #1
0
 @Test
 public void shouldFindAccountByName() {
   when(accountRepository.findByUsername(TEST_USERNAME)).thenReturn(testAccount);
   AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder);
   Account found = accountService.findByUsername(TEST_USERNAME);
   Assert.assertEquals(testAccount, found);
 }
Пример #2
0
 @Test
 public void shouldCreateNonExistentAccount() throws DuplicateAccountException {
   when(accountRepository.save(testAccount)).thenReturn(testAccount);
   AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder);
   accountService.create(testAccount);
   verify(accountRepository, times(1)).save(testAccount);
 }
Пример #3
0
 @Test(expected = DuplicateAccountException.class)
 public void shouldNotCreateDuplicateAccount() throws DuplicateAccountException {
   when(accountRepository.findByUsername(TEST_USERNAME)).thenReturn(testAccount);
   when(testAccount.getUsername()).thenReturn(TEST_USERNAME);
   AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder);
   accountService.create(testAccount);
   verify(accountRepository, times(0)).save(testAccount);
 }