@Test public void addAccountManager() { final Client jack = bankService.createClient("jack", LocalDate.parse("1966-12-31")); final Account jacksGiro = jack.createAccount("Jack's Giro").getAccount(); final Account jacksSavings = jack.createAccount("Jack's Savings").getAccount(); final Client chloe = bankService.createClient("chloe", LocalDate.parse("1992-12-01")); try { chloe.transfer(jacksGiro, jacksSavings.accountNo(), new Amount(0, 01)); fail("Client.WithoutRightExc expected"); } catch (Client.WithoutRightExc expected) { } try { chloe.addAccountManager(jacksGiro, chloe); fail("Client.NotOwnerExc expected"); } catch (Client.NotOwnerExc expected) { } jack.addAccountManager(jacksGiro, chloe); chloe.transfer(jacksGiro, jacksSavings.accountNo(), new Amount(0, 01)); final Client tony = bankService.createClient("tony", LocalDate.parse("1964-03-22")); try { chloe.addAccountManager(jacksGiro, tony); fail("Client.NotOwnerExc expected"); } catch (Client.NotOwnerExc expected) { } try { jack.addAccountManager(jacksGiro, chloe); fail("Client.DoubleManagerExc expected"); } catch (Client.DoubleManagerExc expected) { } }
public AccountAccess addAccountManager(final Account account, Client manager) { final Optional<AccountAccess> ownerAccessOptional = accountAccessRepository.find(this, account); if (!ownerAccessOptional.isPresent()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final AccountAccess ownerAccess = ownerAccessOptional.get(); if (!ownerAccess.isOwner()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final Optional<AccountAccess> managerAccessOptional = accountAccessRepository.find(manager, account); if (managerAccessOptional.isPresent()) { throw create(DoubleManagerExc.class, manager.username, account.accountNo()); } final AccountAccess managerAccountAccess = new AccountAccess(manager, false, account); return accountAccessRepository.save(managerAccountAccess); }
Client extends EntityBase<Client> { public AccountAccess addAccountManager(final Account account, Client manager) { final Optional<AccountAccess> ownerAccessOptional = accountAccessRepository.find(this, account); if (!ownerAccessOptional.isPresent()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final AccountAccess ownerAccess = ownerAccessOptional.get(); if (!ownerAccess.isOwner()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final Optional<AccountAccess> managerAccessOptional = accountAccessRepository.find(manager, account); if (managerAccessOptional.isPresent()) { throw create(DoubleManagerExc.class, manager.username, account.accountNo()); } final AccountAccess managerAccountAccess = new AccountAccess(manager, false, account); return accountAccessRepository.save(managerAccountAccess); } }
Client extends EntityBase<Client> { public AccountAccess addAccountManager(final Account account, Client manager) { final Optional<AccountAccess> ownerAccessOptional = accountAccessRepository.find(this, account); if (!ownerAccessOptional.isPresent()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final AccountAccess ownerAccess = ownerAccessOptional.get(); if (!ownerAccess.isOwner()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final Optional<AccountAccess> managerAccessOptional = accountAccessRepository.find(manager, account); if (managerAccessOptional.isPresent()) { throw create(DoubleManagerExc.class, manager.username, account.accountNo()); } final AccountAccess managerAccountAccess = new AccountAccess(manager, false, account); return accountAccessRepository.save(managerAccountAccess); } @SuppressWarnings("unused") private  Client();  Client(final String username, final LocalDate birthDate); }
Client extends EntityBase<Client> { public AccountAccess addAccountManager(final Account account, Client manager) { final Optional<AccountAccess> ownerAccessOptional = accountAccessRepository.find(this, account); if (!ownerAccessOptional.isPresent()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final AccountAccess ownerAccess = ownerAccessOptional.get(); if (!ownerAccess.isOwner()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final Optional<AccountAccess> managerAccessOptional = accountAccessRepository.find(manager, account); if (managerAccessOptional.isPresent()) { throw create(DoubleManagerExc.class, manager.username, account.accountNo()); } final AccountAccess managerAccountAccess = new AccountAccess(manager, false, account); return accountAccessRepository.save(managerAccountAccess); } @SuppressWarnings("unused") private  Client();  Client(final String username, final LocalDate birthDate); @Column(unique = true, nullable = false) String getUsername(); LocalDate getBirthDate(); @Override String toString(); AccountAccess createAccount(final String accountName); void deposit(final AccountNo destination, final Amount amount); void transfer(final Account source, final AccountNo destination, final Amount amount); AccountAccess addAccountManager(final Account account, Client manager); Account findMyAccount(final AccountNo accountNo); String accountsReport(); }
Client extends EntityBase<Client> { public AccountAccess addAccountManager(final Account account, Client manager) { final Optional<AccountAccess> ownerAccessOptional = accountAccessRepository.find(this, account); if (!ownerAccessOptional.isPresent()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final AccountAccess ownerAccess = ownerAccessOptional.get(); if (!ownerAccess.isOwner()) { throw create(NotOwnerExc.class, this.username, account.accountNo()); } final Optional<AccountAccess> managerAccessOptional = accountAccessRepository.find(manager, account); if (managerAccessOptional.isPresent()) { throw create(DoubleManagerExc.class, manager.username, account.accountNo()); } final AccountAccess managerAccountAccess = new AccountAccess(manager, false, account); return accountAccessRepository.save(managerAccountAccess); } @SuppressWarnings("unused") private  Client();  Client(final String username, final LocalDate birthDate); @Column(unique = true, nullable = false) String getUsername(); LocalDate getBirthDate(); @Override String toString(); AccountAccess createAccount(final String accountName); void deposit(final AccountNo destination, final Amount amount); void transfer(final Account source, final AccountNo destination, final Amount amount); AccountAccess addAccountManager(final Account account, Client manager); Account findMyAccount(final AccountNo accountNo); String accountsReport();  }