@Test public void transfer() { 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 Amount minimumBalance = Account.getMinimumBalance(); final Amount maximumTransferAmount = minimumBalance.times(-1); final AccountNo jacksSavingsAccountNo = jacksSavings.accountNo(); jack.transfer(jacksGiro, jacksSavingsAccountNo, maximumTransferAmount); final String report = jack.accountsReport(); final String maximumTransferAmountString = maximumTransferAmount.toString(); final AccountNo jacksGiroAccountNo = jacksGiro.accountNo(); assertEquals("Accounts of client: jack\n" + jacksSavingsAccountNo + "\tisOwner\t" + maximumTransferAmountString + "\tJack's Savings\n" + jacksGiroAccountNo + "\tisOwner\t-" + maximumTransferAmountString + "\tJack's Giro\n", report); }
public void transfer(final Account source, final AccountNo destination, final Amount amount) throws AmountExc, WithoutRightExc, MinimumBalanceExc, DestinationAccountNotFoundExc { if (amount.toDouble() <= 0) { throw create(Client.AmountExc.class, amount); } final Optional<AccountAccess> accountAccessOptional = accountAccessRepository.find(this, source); if (!accountAccessOptional.isPresent()) { throw create(WithoutRightExc.class, username, source.accountNo()); } final Amount newBalance = source.getBalance().minus(amount); if (newBalance.compareTo(Account.getMinimumBalance()) < 0) { throw create(MinimumBalanceExc.class, newBalance, Account.getMinimumBalance()); } final Account destinationAccount = _findDestinationAccount(destination); source.setBalance(source.getBalance().minus(amount)); destinationAccount.setBalance(destinationAccount.getBalance().plus(amount)); accountRepository.save(source); accountRepository.save(destinationAccount); }
Client extends EntityBase<Client> { public void transfer(final Account source, final AccountNo destination, final Amount amount) throws AmountExc, WithoutRightExc, MinimumBalanceExc, DestinationAccountNotFoundExc { if (amount.toDouble() <= 0) { throw create(Client.AmountExc.class, amount); } final Optional<AccountAccess> accountAccessOptional = accountAccessRepository.find(this, source); if (!accountAccessOptional.isPresent()) { throw create(WithoutRightExc.class, username, source.accountNo()); } final Amount newBalance = source.getBalance().minus(amount); if (newBalance.compareTo(Account.getMinimumBalance()) < 0) { throw create(MinimumBalanceExc.class, newBalance, Account.getMinimumBalance()); } final Account destinationAccount = _findDestinationAccount(destination); source.setBalance(source.getBalance().minus(amount)); destinationAccount.setBalance(destinationAccount.getBalance().plus(amount)); accountRepository.save(source); accountRepository.save(destinationAccount); } }
Client extends EntityBase<Client> { public void transfer(final Account source, final AccountNo destination, final Amount amount) throws AmountExc, WithoutRightExc, MinimumBalanceExc, DestinationAccountNotFoundExc { if (amount.toDouble() <= 0) { throw create(Client.AmountExc.class, amount); } final Optional<AccountAccess> accountAccessOptional = accountAccessRepository.find(this, source); if (!accountAccessOptional.isPresent()) { throw create(WithoutRightExc.class, username, source.accountNo()); } final Amount newBalance = source.getBalance().minus(amount); if (newBalance.compareTo(Account.getMinimumBalance()) < 0) { throw create(MinimumBalanceExc.class, newBalance, Account.getMinimumBalance()); } final Account destinationAccount = _findDestinationAccount(destination); source.setBalance(source.getBalance().minus(amount)); destinationAccount.setBalance(destinationAccount.getBalance().plus(amount)); accountRepository.save(source); accountRepository.save(destinationAccount); } @SuppressWarnings("unused") private  Client();  Client(final String username, final LocalDate birthDate); }
Client extends EntityBase<Client> { public void transfer(final Account source, final AccountNo destination, final Amount amount) throws AmountExc, WithoutRightExc, MinimumBalanceExc, DestinationAccountNotFoundExc { if (amount.toDouble() <= 0) { throw create(Client.AmountExc.class, amount); } final Optional<AccountAccess> accountAccessOptional = accountAccessRepository.find(this, source); if (!accountAccessOptional.isPresent()) { throw create(WithoutRightExc.class, username, source.accountNo()); } final Amount newBalance = source.getBalance().minus(amount); if (newBalance.compareTo(Account.getMinimumBalance()) < 0) { throw create(MinimumBalanceExc.class, newBalance, Account.getMinimumBalance()); } final Account destinationAccount = _findDestinationAccount(destination); source.setBalance(source.getBalance().minus(amount)); destinationAccount.setBalance(destinationAccount.getBalance().plus(amount)); accountRepository.save(source); accountRepository.save(destinationAccount); } @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 void transfer(final Account source, final AccountNo destination, final Amount amount) throws AmountExc, WithoutRightExc, MinimumBalanceExc, DestinationAccountNotFoundExc { if (amount.toDouble() <= 0) { throw create(Client.AmountExc.class, amount); } final Optional<AccountAccess> accountAccessOptional = accountAccessRepository.find(this, source); if (!accountAccessOptional.isPresent()) { throw create(WithoutRightExc.class, username, source.accountNo()); } final Amount newBalance = source.getBalance().minus(amount); if (newBalance.compareTo(Account.getMinimumBalance()) < 0) { throw create(MinimumBalanceExc.class, newBalance, Account.getMinimumBalance()); } final Account destinationAccount = _findDestinationAccount(destination); source.setBalance(source.getBalance().minus(amount)); destinationAccount.setBalance(destinationAccount.getBalance().plus(amount)); accountRepository.save(source); accountRepository.save(destinationAccount); } @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();  }