/** * Test method for {@link edu.cecs274.BankCustomer#closeAccount(edu.cecs274.BankAccount)}. Cancels * an account that exist in aCustomer's list of accounts. */ @Test public void testCancelAccount() { // Add two accounts to aCustomer's list of accounts BankAccount oneAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER); aCustomer.addAccount(oneAccount); BankAccount anotherAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 1); aCustomer.addAccount(anotherAccount); int expected = 2; assertEquals(expected, aCustomer.getNumberOfAccounts()); // Cancel an account, should remove from aCustomer's list of accounts aCustomer.closeAccount(oneAccount); assertEquals(--expected, aCustomer.getNumberOfAccounts()); }
/** * Test method for {@link edu.cecs274.BankCustomer#closeAccount(edu.cecs274.BankAccount)}. Cancels * an account that does not exist in aCustomer's list of accounts. */ @Test(expected = AccountDoesNotExistException.class) public void testCancelAccountDoesNotExist() { // Add two accounts to aCustomer's list of accounts BankAccount oneAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER); aCustomer.addAccount(oneAccount); BankAccount anotherAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 1); aCustomer.addAccount(anotherAccount); int expected = 2; assertEquals(expected, aCustomer.getNumberOfAccounts()); // Cancel an account that does not exist in aCustomer's list of accounts BankAccount newAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER - 1); aCustomer.closeAccount(newAccount); }
/** Test method for {@link edu.cecs274.BankCustomer#getTotalBalance()}. */ @Test public void testGetTotalBalance() { BankAccount oneAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER, INITIAL_BALANCE); BankAccount twoAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 1); BankAccount threeAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 2); aCustomer.addAccount(oneAccount); aCustomer.addAccount(twoAccount); aCustomer.addAccount(threeAccount); double expected = INITIAL_BALANCE; double totalBalance = aCustomer.getTotalBalance(); assertEquals(expected, totalBalance, DELTA); // Adds more money to twoAccount, the change should be reflected in aCustomers totalBalance twoAccount.deposit(INITIAL_BALANCE); expected = INITIAL_BALANCE * 2; totalBalance = aCustomer.getTotalBalance(); assertEquals(expected, totalBalance, DELTA); }
/** Test method for {@link edu.cecs274.BankCustomer#addAccount(edu.cecs274.BankAccount)}. */ @Test public void testAddAccount() { // Initially, aCustomer has no bank accounts int numberOfAccounts = aCustomer.getNumberOfAccounts(); double totalBalance = aCustomer.getTotalBalance(); BankAccount newAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER); aCustomer.addAccount(newAccount); // Now aCustomer has a newAccount with the default initial balance assertEquals(++numberOfAccounts, aCustomer.getNumberOfAccounts()); assertEquals(totalBalance, aCustomer.getTotalBalance(), DELTA); // Add another account with a balance newAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 1, INITIAL_BALANCE); aCustomer.addAccount(newAccount); // Now aCustomer has two accounts, with totalBalance == INITIAL_BALANCE assertEquals(++numberOfAccounts, aCustomer.getNumberOfAccounts()); assertEquals(totalBalance + INITIAL_BALANCE, aCustomer.getTotalBalance(), DELTA); }
/** Test method for {@link edu.cecs274.BankCustomer#getNumberOfAccounts()}. */ @Test public void testGetNumberOfAccounts() { int expected = 0; int numberOfAccounts = aCustomer.getNumberOfAccounts(); assertEquals(expected, numberOfAccounts); BankAccount oneAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER); aCustomer.addAccount(oneAccount); expected++; numberOfAccounts = aCustomer.getNumberOfAccounts(); assertEquals(expected, numberOfAccounts); }