@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); }
@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); }