diff --git a/.gitignore b/.gitignore index 3c8b8dd5..00e87a5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +target/ + + # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 28c6362f..9bca3b8b 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,5 +9,6 @@ + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index b26911bd..fade66b8 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d87af9ac..f11b0ebd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + + - + \ No newline at end of file diff --git a/.idea/sbt.xml b/.idea/vcs.xml similarity index 51% rename from .idea/sbt.xml rename to .idea/vcs.xml index 20187435..35eb1ddf 100644 --- a/.idea/sbt.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - - \ No newline at end of file diff --git a/README.md b/README.md index 87c23b2d..4654c61e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,21 @@ # SoftwareEngineeringPractice -## grading - -To Do | correct ----|--- -at least 8 commits| -isEmailValid| -withdraw| -isamountValid| -constructor & withdraw fix| + +Link to state diagram: https://drive.google.com/file/d/1BPTHJmOLGr9hiQ0BJnvLTYXEDLRx6saK/view?usp=sharing + +link to Ioan's sequence diagram: https://drive.google.com/file/d/1fHwd0fRkoscI03Zu2G8p7B5D6bBiBh87/view?usp=sharing +link to Aidan's sequence diagram: https://drive.google.com/file/d/1L447NcwgO0GbktDt5HXLOZCDhwc7hFZX/view?usp=sharing + +* UML Diagram - https://drive.google.com/file/d/1BKs9DEbUAkv-ynNGjp099HZ6vRylucr6/view?usp=sharing +* Use Case Diagram - https://drive.google.com/file/d/1OTOZ-MegXgHVpB8rYiUERVfmFXZhzAlF/view?usp=sharing +* freeze account sequence diagram - https://drive.google.com/file/d/19AFoU-Of_jHAxNgIwXVeigCMnlGSpC1D/view?usp=sharing +* unfreeze account sequence diagram - https://drive.google.com/file/d/1AA96lVdDmQhyHeB5tIYJtLMJNSpWDMh1/view?usp=sharing + + +Plan for Friday: +Update the class diagram to better include the user class. +Update the use case diagram to include confirm credentials and check balances. As well as clarify "request report" +Change our code to better implement the user. Change the code to work again with both the collection of bankaccount and user. + +Aidan - Code review notes: +Class diagram - savings & checkings should inherit, transaction should be a composition to BankAccount +Code - tests for multiple suspicious transactions, timestamps - multiple rapid transactions diff --git a/SequenceDiagram.pdf b/SequenceDiagram.pdf new file mode 100644 index 00000000..6d8a3f16 Binary files /dev/null and b/SequenceDiagram.pdf differ diff --git a/SoftwareEngineeringPractice.iml b/SoftwareEngineeringPractice.iml deleted file mode 100644 index 78b2cc53..00000000 --- a/SoftwareEngineeringPractice.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 416ce09a..8b225cb9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 - 1.10 + 1.13 4.12 5.0.0 diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java new file mode 100644 index 00000000..4a28307e --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -0,0 +1,151 @@ +package edu.ithaca.dragon.bank; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +public class ATM implements BasicAPI { + CentralBank bank; + + public ATM(CentralBank bank) { + this.bank = bank; + } + + public boolean confirmCredentials(String username, String password) { + + Iterator itr = this.bank.users.iterator(); + while (itr.hasNext()) { + User current = itr.next(); + if (current.getUsername().equals(username)) { + if (current.getPassword().equals(password)) { + return true; + } + } + } + + return false; + } + + public User getUser(String username, String password) { + Iterator itr = this.bank.users.iterator(); + while (itr.hasNext()) { + User current = itr.next(); + if (current.getUsername().equals(username)) { + if (current.getPassword().equals(password)) { + return current; + } + } + } + return null; + } + + public double checkBalance(String acctId) { + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()) { + BankAccount current = itr.next(); + if (current.getAcctId().equals(acctId)) { + return current.getBalance(); + } + } + throw new IllegalArgumentException("invalid account id"); + } + + + public void withdraw(String acctId, double amount) throws InsufficientFundsException, IllegalArgumentException { + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()) { + BankAccount current = itr.next(); + if (current.getAcctId().equals(acctId)) { + if (!current.isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Amount"); + } + + if (current.getBalance() < amount) { + throw new InsufficientFundsException("Not enough funds"); + } + if (current.isAmountValid(amount)) { + double balance = current.getBalance(); + balance -= amount; + current.setBalance(balance); + return; + } + } + } + throw new IllegalArgumentException("invalid account id"); + + } + + public void deposit(String acctId, double amount) { + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()) { + BankAccount current = itr.next(); + if (current.getAcctId() == acctId) { + if (current.isAmountValid(amount)) { + double balance = current.getBalance(); + balance += amount; + current.setBalance(balance); + return; + } + if (!current.isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Amount"); + } + + } + } + throw new IllegalArgumentException("invalid account id"); + + } + + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + int count = 0; + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()) { + BankAccount current = itr.next(); + if (current.getAcctId().equals(acctIdToWithdrawFrom)) { + if (!current.isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Amount"); + } + if (current.getBalance() < amount) { + throw new InsufficientFundsException("Not enough funds"); + } + if (current.isAmountValid(amount)) { + double balance = current.getBalance(); + balance -= amount; + current.setBalance(balance); + count += 1; + } + } + + if (current.getAcctId().equals(acctIdToDepositTo)) { + if (!current.isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Amount"); + } + + if (current.isAmountValid(amount)) { + double balance = current.getBalance(); + balance += amount; + current.setBalance(balance); + count += 1; + } + } + } + if (count == 2) { + return; + } else { + throw new IllegalArgumentException("invalid account id"); + } + + } + + public ArrayList transactionHistory(String acctId) { + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()) { + BankAccount current = itr.next(); + if (current.getAcctId().equals(acctId)) { + return current.getTransactionHistory(); + } + } + throw new IllegalArgumentException("Invalid account id"); + } +} + diff --git a/src/main/java/edu/ithaca/dragon/bank/ATMUI.java b/src/main/java/edu/ithaca/dragon/bank/ATMUI.java new file mode 100644 index 00000000..bb181c8d --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/ATMUI.java @@ -0,0 +1,157 @@ +package edu.ithaca.dragon.bank; + +import java.util.Scanner; + +enum ATMUIState {Login, Frozen, Account, Menu, Withdraw, Deposit, Transfer} + + /* + TEST SCRIPT FOR THE UI: + When asked for the username, input 'ioan' + When asked for the password, input '123' + when asked for the ID, input 'ioan' + withdraw 2000, should give an error + withdraw 100, should pass + deposit 1000, should pass, + transfer 200 to account ID 'aidan' should pass + log out + */ + +public class ATMUI { + + private static CentralBank bank; + private static BasicAPI atm; + private static ATMUIState currentState; + private static BankAccount currentAccount; + private static User currentUser; + private static Scanner in; + + public static void main(String[] args) throws IllegalArgumentException,InsufficientFundsException { + User christian = new User("christian","123"); + User aidan = new User("aidan","123"); + User ioan = new User("ioan","123"); + BankAccount christianacct = new CheckingAccount(1000, "christian"); + BankAccount aidanacct = new CheckingAccount(1000, "aidan"); + BankAccount ioanacct = new CheckingAccount(1000, "ioan"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christianacct); + myBank.accounts.add(aidanacct); + myBank.accounts.add(ioanacct); + myBank.users.add(christian); + myBank.users.add(aidan); + myBank.users.add(ioan); + bank = myBank; + atm = new ATM(bank); + currentState = ATMUIState.Login; + in = new Scanner(System.in); + + while (true) { + if(currentState == ATMUIState.Login) { + Login(); + } else if(currentState == ATMUIState.Menu) { + Menu(); + } else if(currentState == ATMUIState.Frozen) { + Frozen(); + } else if(currentState == ATMUIState.Deposit) { + Deposit(); + } else if(currentState == ATMUIState.Withdraw) { + Withdraw(); + } else if(currentState == ATMUIState.Transfer) { + Transfer(); + } else if(currentState == ATMUIState.Account) { + Account(); + } + } + } + + + + static void Login() { + System.out.println("Please enter your username and password: "); + System.out.print("Username:"); + String username = in.nextLine(); + System.out.print("\nPassword:"); + String password = in.nextLine(); + + if(atm.confirmCredentials(username, password)) { + currentUser = atm.getUser(username, password); + currentState = ATMUIState.Account; + } + else { + System.out.println("Error: invalid credentials, please try again."); + currentState = ATMUIState.Login; + } + } + + static void Account() { + System.out.println("Enter account ID: "); + String accID = in.nextLine(); + try { + currentAccount = currentUser.getBankAccount(accID); + if(currentAccount.isFrozen()) { + currentState = ATMUIState.Frozen; + } + else { + currentState = ATMUIState.Menu; + } + } catch (Exception e){ + System.out.println("Error: invalid account ID, please try again."); + } + } + + static void Menu() { + System.out.println("Current balance: " + currentAccount.getBalance() + ". Would you like to withdraw, deposit, transfer, or logout?"); + String action = in.nextLine(); + if(action.equalsIgnoreCase("withdraw")) { + currentState = ATMUIState.Withdraw; + } else if (action.equalsIgnoreCase("deposit")) { + currentState = ATMUIState.Deposit; + } else if (action.equalsIgnoreCase("transfer")) { + currentState = ATMUIState.Transfer; + } else if (action.equalsIgnoreCase("logout")) { + System.out.println("Thank you for banking with us today."); + currentState = ATMUIState.Login; + } else { + System.out.println("Error: invalid command, please try again."); + currentState = ATMUIState.Menu; + } + } + + static void Frozen() { + System.out.println("This account is currently frozen due to suspicious activity. " + + "For more information, please contact customer service at 1-888-555-1212."); + currentState = ATMUIState.Login; + } + + static void Withdraw() throws InsufficientFundsException{ + System.out.println("Enter amount to withdraw: "); + double amount = in.nextDouble(); + atm.withdraw(currentAccount.getAcctId(),amount); + System.out.println("Withdraw successful. New balance: " + currentAccount.getBalance()); + currentState = ATMUIState.Menu; + } + + static void Deposit() throws InsufficientFundsException { + System.out.println("Enter amount to deposit: "); + double amount = in.nextDouble(); + atm.deposit(currentAccount.getAcctId(),amount); + System.out.println("Deposit successful. New balance: " + currentAccount.getBalance()); + currentState = ATMUIState.Menu; + } + + static void Transfer() { + System.out.println("Enter accountID to transfer to: "); + String accIDTo = in.nextLine(); + try { + BankAccount accTo = bank.getBankAccount(accIDTo); + System.out.println("Enter amount to transfer: "); + double amount = in.nextDouble(); + atm.transfer(currentAccount.getAcctId(),accIDTo,amount); + System.out.println("Transfer successful. New balance: " + currentAccount.getBalance()); + currentState = ATMUIState.Menu; + } + catch (Exception e){ + System.out.println("Error: invalid account ID, please try again."); + currentState = ATMUIState.Transfer; + } + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java new file mode 100644 index 00000000..3aa11e5f --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -0,0 +1,76 @@ +package edu.ithaca.dragon.bank; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +public class Admin implements AdminAPI { + CentralBank bank; + + public Admin(CentralBank bank){ + this.bank=bank; + } + + public double calcTotalAssets() { + double totalAssets = 0; + Iterator itr = this.bank.accounts.iterator(); + while(itr.hasNext()) { + BankAccount curr = itr.next(); + totalAssets += curr.getBalance(); + } + return totalAssets; + } + + public Collection findAcctIdsWithSuspiciousActivity() { + Collection ids = new ArrayList(); + double depositThreshold = 2; + double withdrawThreshold = .5; + + Iterator itr = this.bank.accounts.iterator(); + while(itr.hasNext()) { + BankAccount curr = itr.next(); + Iterator itr2 = curr.transactionHistory.iterator(); + while(itr2.hasNext()) { + Transaction curr2 = itr2.next(); + if(curr2.getFlagSuspicious()) { + ids.add(curr.getAcctId()); + break; + } + } + } + return ids; + } + + //freeze accounts + public void freezeAccount(String acctId) { + boolean accountpresent = false; + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()){ + BankAccount current = itr.next(); + if (current.getAcctId()== acctId){ + accountpresent = true; + current.setFrozen(true); + } + } + if (accountpresent ==false){ + throw new IllegalArgumentException("invalid account id"); + } + + + } + + public void unfreezeAcct(String acctId) { + boolean accountpresent = false; + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()){ + BankAccount current = itr.next(); + if (current.getAcctId()== acctId){ + accountpresent = true; + current.setFrozen(false); + } + } + if (accountpresent == false){ + throw new IllegalArgumentException("invalid account id"); + } + + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/AdminAPI.java b/src/main/java/edu/ithaca/dragon/bank/AdminAPI.java new file mode 100644 index 00000000..b11e2b4e --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/AdminAPI.java @@ -0,0 +1,15 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public interface AdminAPI { + + public double calcTotalAssets(); + + public Collection findAcctIdsWithSuspiciousActivity(); + + public void freezeAccount(String acctId); + + public void unfreezeAcct(String acctId); + +} diff --git a/src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java b/src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java new file mode 100644 index 00000000..31324086 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java @@ -0,0 +1,9 @@ +package edu.ithaca.dragon.bank; + +//API to be used by Teller systems +public interface AdvancedAPI extends BasicAPI { + + public void createAccount(User user, String acctId, double startingBalance, boolean Savings); + + public void closeAccount(User user, String acctId); +} diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index e340e0ea..4453423e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,46 +1,160 @@ package edu.ithaca.dragon.bank; +import java.util.ArrayList; +import java.time.LocalDateTime; + public class BankAccount { - private String email; + private String acctId; private double balance; + private boolean frozen = false; + public ArrayList transactionHistory = new ArrayList(); /** - * @throws IllegalArgumentException if email is invalid + * @post creates a bank account object + * @throws IllegalArgumentException if dollar amount is invalid + * */ - public BankAccount(String email, double startingBalance){ - if (isEmailValid(email)){ - this.email = email; - this.balance = startingBalance; + public BankAccount(double startingBalance, String acctId) { + if (isAmountValid(startingBalance)){ + this.balance = startingBalance; + this.acctId = acctId; } + else { - throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); - } + throw new IllegalArgumentException("Dollar Amount: " + startingBalance + " is invalid, cannot create account"); + } } - public double getBalance(){ + + public double getBalance() { return balance; } - public String getEmail(){ - return email; + public boolean isFrozen() { + return frozen; + } + + public String getAcctId() { + return acctId; + } + + public ArrayList getTransactionHistory() { return transactionHistory; } + + public void setFrozen(boolean frozen) { + this.frozen = frozen; + } + + public void setBalance(double balance){ this.balance=balance; } + + /** + * @post checks if inputted dollar amount is a valid dollar amount + * + */ + public static boolean isAmountValid(double amount) { + + if (amount < 0) { + return false; + } + + String amtstring = String.valueOf(amount); + int decimalplace = amtstring.indexOf("."); + String postdecimal = amtstring.substring(decimalplace+1); + + if (postdecimal.length() > 2) { + return false; + } + + return true; + } + + /** * @post reduces the balance by amount if amount is non-negative and smaller than balance + * @throws InsufficientFundsException if trying to withdraw more than whats in account. + * @throws IllegalArgumentException if inputted amount is invalid. + * */ - public void withdraw (double amount) { - balance -= amount; + public void withdraw (double amount) throws InsufficientFundsException, IllegalArgumentException { + + //checks for valid input + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Input"); + } + //checks for valid withdraw amount + if (balance < amount) { + throw new InsufficientFundsException("Cannot withdraw an amount larger than your balance"); + } + + else{ + double oldBalance = this.balance; + balance -= amount; + + boolean flag = false; + if(amount > oldBalance/2) { + flag = true; + } + transactionHistory.add(new Transaction(oldBalance, -amount, balance, LocalDateTime.now(), flag)); + } } - public static boolean isEmailValid(String email){ - if (email.indexOf('@') == -1){ - return false; + + + /** + * @post Adds the amount to the balance if amount is non-negative and smaller than balance + * @throws IllegalArgumentException if inputted amount is invalid. + * + */ + public void Deposit(double amount) throws IllegalArgumentException, InsufficientFundsException { + //checks for valid input + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Invalid Input"); } + else { - return true; + double oldBalance = this.balance; + balance += amount; + + boolean flag = false; + if(amount > (oldBalance*2)) { + flag = true; + } + transactionHistory.add(new Transaction(oldBalance, amount, balance, LocalDateTime.now(), flag)); } } + + + /** + * @post removes the amount from the balance and adds the amount to the other bank account if amount is non-negative and smaller than balance + * @throws InsufficientFundsException if trying to withdraw more than whats in account. + * @throws IllegalArgumentException if inputted amount is invalid. + * + */ + public void Transfer(BankAccount transferacct, double amount) throws IllegalArgumentException, InsufficientFundsException{ + //checks for valid input + if (!isAmountValid(amount)){ + throw new IllegalArgumentException("Invalid Input"); + } + + //checks for valid transfer amount + if (balance < amount){ + throw new InsufficientFundsException("Cannot transfer an amount larger than your balance"); + } + + else{ + balance-= amount; + transferacct.balance+=amount; + } + } + } + + + + + + diff --git a/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java new file mode 100644 index 00000000..99822ef4 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java @@ -0,0 +1,22 @@ +package edu.ithaca.dragon.bank; + +import java.util.ArrayList; + +//API to be used by ATMs +public interface BasicAPI { + + boolean confirmCredentials(String acctId, String password); + + User getUser(String username, String password); + + double checkBalance(String acctId); + + void withdraw(String acctId, double amount) throws InsufficientFundsException; + + void deposit(String acctId, double amount); + + void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException; + + ArrayList transactionHistory(String acctId); + +} diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java new file mode 100644 index 00000000..75f428b0 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -0,0 +1,44 @@ +package edu.ithaca.dragon.bank; + +import javax.swing.plaf.basic.BasicLookAndFeel; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +public class CentralBank { + + public Collection accounts; + public Collection users; + + public CentralBank(){ + Collection accounts = new ArrayList(); + Collection users = new ArrayList(); + this.accounts=accounts; + this.users=users; + } + + public Collection getAccounts() { + return accounts; + } + + public Collection getUsers() { + return users; + } + + public BankAccount getBankAccount(String acctID){ + boolean accountpresent = false; + Iterator itr = this.accounts.iterator(); + while (itr.hasNext()){ + BankAccount current = itr.next(); + if (current.getAcctId()== acctID){ + return current; + } + } + if (accountpresent == false){ + throw new IllegalArgumentException("invalid account id"); + } + + throw new IllegalArgumentException("invalid account id"); + + } +} \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java new file mode 100644 index 00000000..bd6883ce --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -0,0 +1,10 @@ +package edu.ithaca.dragon.bank; + +public class CheckingAccount extends BankAccount { + public CheckingAccount(double startingBalance, String acctId) { + super(startingBalance,acctId); + } +} + + + diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java new file mode 100644 index 00000000..1af62574 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -0,0 +1,17 @@ +package edu.ithaca.dragon.bank; + +public class SavingsAccount extends BankAccount { + public SavingsAccount(double startingBalance, String acctId){ + super(startingBalance, acctId); + } + + private double interestRate; + private double maximumWithdrawal; + + + public SavingsAccount(double startingBalance, String acctId, double interestRate, double maximumWithdrawal) { + super(startingBalance,acctId); + this.interestRate = interestRate; + this.maximumWithdrawal = maximumWithdrawal; + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java new file mode 100644 index 00000000..06849e4a --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -0,0 +1,34 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public class Teller extends ATM implements AdvancedAPI { + + public Teller(CentralBank bank) { + super(bank); + + } + public void createAccount(User user, String acctId, double startingBalance, boolean Savings){ + if(Savings){ + BankAccount acct= new SavingsAccount(startingBalance, acctId); + bank.accounts.add(acct); + user.accounts.add(acct); + + } + else if(!Savings){ + BankAccount acct= new CheckingAccount(startingBalance, acctId); + bank.accounts.add(acct); + user.accounts.add(acct); + } + + } + + + public void closeAccount (User user, String acctId){ + BankAccount acct=bank.getBankAccount(acctId); + bank.accounts.remove(acct); + user.accounts.remove(acct); + + } + } + diff --git a/src/main/java/edu/ithaca/dragon/bank/Transaction.java b/src/main/java/edu/ithaca/dragon/bank/Transaction.java new file mode 100644 index 00000000..7c708ca9 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Transaction.java @@ -0,0 +1,40 @@ +package edu.ithaca.dragon.bank; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Transaction { + + private double oldBalance; + private double transactionAmount; + private double newBalance; + private boolean flagSuspicious; + //private LocalDateTime transactionTime = LocalDateTime.now(); + private String transactionTime; + + public Transaction(double oldBalanceIn, double transactionAmountIn, double newBalanceIn, LocalDateTime transactionTimeIn, boolean flagSuspiciousIn) { + this.oldBalance = oldBalanceIn; + this.transactionAmount = transactionAmountIn; + this.newBalance = newBalanceIn; + DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss"); + this.transactionTime = transactionTimeIn.format(format); + this.flagSuspicious = flagSuspiciousIn; + } + + public double getBalance() { + return this.oldBalance; + } + + public double getTransactionAmount() { + return this.transactionAmount; + } + + public boolean getFlagSuspicious() { + return this.flagSuspicious; + } + + public String toString() { + return "Balance before: " + oldBalance + " Transaction amount: " + transactionAmount + + " Balance after: " + newBalance + " Time: " + transactionTime + " Suspicious: " + flagSuspicious + "\n"; + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/User.java b/src/main/java/edu/ithaca/dragon/bank/User.java new file mode 100644 index 00000000..7168fdd5 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/User.java @@ -0,0 +1,45 @@ +package edu.ithaca.dragon.bank; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + + +public class User { + + Collection accounts; + private String username; + private String password; + + public User(String username, String password){ + this.username=username; + this.password=password; + Collection accounts = new ArrayList(); + this.accounts=accounts; + } + + public BankAccount getBankAccount(String acctID){ + boolean accountpresent = false; + Iterator itr = this.accounts.iterator(); + while (itr.hasNext()){ + BankAccount current = itr.next(); + if (current.getAcctId()== acctID){ + return current; + } + } + if (accountpresent == false){ + throw new IllegalArgumentException("invalid account id"); + } + + throw new IllegalArgumentException("invalid account id"); + + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } +} diff --git a/src/test/java/edu/ithaca/dragon/bank/ATMTest.java b/src/test/java/edu/ithaca/dragon/bank/ATMTest.java new file mode 100644 index 00000000..062499b6 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/ATMTest.java @@ -0,0 +1,140 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.jupiter.api.Assertions.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ATMTest { + + @Test + void confirmCredentialsTest(){ + User christian = new User("christian","martano"); + CentralBank mybank = new CentralBank(); + mybank.users.add(christian); + ATM atm = new ATM(mybank); + + //correct credentialss + assertEquals(true,atm.confirmCredentials("christian","martano")); + + //incorrect credetials + assertEquals(false,atm.confirmCredentials("abc","123")); + + //correct username incorrect password + assertEquals(false,atm.confirmCredentials("christian","123")); + + //incorrect username correct password + assertEquals(false,atm.confirmCredentials("CCC","martano")); + + + + } + + @Test + void checkbalanceTest(){ + BankAccount christian = new CheckingAccount(1000, "christian"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christian); + ATM atm = new ATM(myBank); + //basic check balance + assertEquals(1000,atm.checkBalance("christian")); + //invalid account id + assertThrows(IllegalArgumentException.class, () -> atm.checkBalance("Chistian")); + } + + @Test + void withdrawTest() throws InsufficientFundsException, IllegalArgumentException { + BankAccount christian = new CheckingAccount(1000, "christian"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christian); + ATM atm = new ATM(myBank); + //greater than balance + assertThrows(InsufficientFundsException.class, ()->atm.withdraw("christian",1001)); + + //less than balance + atm.withdraw("christian",50); + assertEquals(950, christian.getBalance()); + + + //equal to balance + atm.withdraw("christian",950); + assertEquals(0, christian.getBalance()); + + + //negative - argument thrown + assertThrows(IllegalArgumentException.class,() -> atm.withdraw("christian",-1)); + + + //invalid input + atm.deposit("christian",1000); + assertThrows(IllegalArgumentException.class,() -> atm.withdraw("christian",100.0005)); + } + + @Test + void depositTest() throws InsufficientFundsException, IllegalArgumentException { + BankAccount christian = new CheckingAccount(1000, "christian"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christian); + ATM atm = new ATM(myBank); + + //regular deposit + atm.deposit("christian",50); + assertEquals(1050, christian.getBalance()); + + + //negative - argument thrown + assertThrows(IllegalArgumentException.class,() -> atm.deposit("christian",-1)); + + + //invalid input + atm.deposit("christian",1000); + assertThrows(IllegalArgumentException.class,() -> atm.deposit("christian",100.0005)); + } + + @Test + void transferTest() throws IllegalArgumentException, InsufficientFundsException{ + BankAccount sender = new CheckingAccount(500, "christian"); + BankAccount reciever = new SavingsAccount(0, "martano"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(sender); + myBank.accounts.add(reciever); + ATM atm = new ATM(myBank); + //successfull transfer + atm.transfer("christian","martano",100); + assertEquals(400, sender.getBalance()); + assertEquals(100, reciever.getBalance()); + + //transfer with change + atm.transfer("christian","martano", 1.50); + assertEquals(398.50, sender.getBalance()); + assertEquals(101.50, reciever.getBalance()); + + //0 dollars transfered + atm.transfer("christian","martano", 0); + assertEquals(398.50, sender.getBalance()); + assertEquals(101.50, reciever.getBalance()); + + //negative amount trying to be transfered + assertThrows(IllegalArgumentException.class, ()->atm.transfer("christian","martano", -1)); + + //invalid input check + assertThrows(IllegalArgumentException.class, ()-> atm.transfer("christian","martano", 100.0005)); + + //trying to transfer insufficent funds + assertThrows(InsufficientFundsException.class, ()->atm.transfer("christian","martano", 500)); + + //checks to be sure illegal argument is thrown rather than insufficient funds when both are valid + assertThrows(IllegalArgumentException.class, ()->atm.transfer("christian","martano", 500.0005)); + + //invalid email + assertThrows(IllegalArgumentException.class, ()->atm.transfer("christiann","martano", 500)); + } + + + +} diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTesttt.java b/src/test/java/edu/ithaca/dragon/bank/AdminTesttt.java new file mode 100644 index 00000000..6e835500 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTesttt.java @@ -0,0 +1,108 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.jupiter.api.Assertions.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class AdminTesttt { + + @Test + void freezeAccountTest() { + BankAccount christian = new CheckingAccount(1000, "christian"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christian); + Admin admin = new Admin(myBank); + //no change + assertEquals(false, christian.isFrozen()); + + admin.freezeAccount("christian"); + //after freezing check + assertEquals(true, christian.isFrozen()); + + admin.freezeAccount("christian"); + //freexing a frozen account + assertEquals(true, christian.isFrozen()); + //Checking with IDs not present in collection + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("123")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("abcd")); + + } + + @Test + void unFreezeAccountTest() { + BankAccount christian = new CheckingAccount(1000, "christian"); + CentralBank myBank = new CentralBank(); + myBank.accounts.add(christian); + Admin admin = new Admin(myBank); + //no change + assertEquals(false, christian.isFrozen()); + + admin.freezeAccount("christian"); + admin.unfreezeAcct("christian"); + //after unfreezing check + assertEquals(false, christian.isFrozen()); + admin.unfreezeAcct("christian"); + //unfreezing an unfrozen account + assertEquals(false, christian.isFrozen()); + //Checking with IDs not present in collection + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("123")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("abcd")); + + } + + @Test + void calcTotalAssetsTest() { + BankAccount acc1 = new CheckingAccount(1000, "acc1"); + BankAccount acc2 = new CheckingAccount(1500, "acc2"); + BankAccount acc3 = new SavingsAccount(3000, "acc3"); + CentralBank bank = new CentralBank(); + bank.accounts.add(acc1); + bank.accounts.add(acc2); + bank.accounts.add(acc3); + Admin admin = new Admin(bank); + assertEquals(5500, admin.calcTotalAssets()); + } + + //integration test + @Test + void findAcctIdsWithSuspiciousActivityTest() throws InsufficientFundsException { + BankAccount acc1 = new CheckingAccount(1000, "acc1"); + BankAccount acc2 = new CheckingAccount(1500, "acc2"); + BankAccount acc3 = new SavingsAccount(3000, "acc3"); + BankAccount acc4 = new CheckingAccount(10000, "acc4"); + BankAccount acc5 = new CheckingAccount(1000, "acc5"); + CentralBank bank = new CentralBank(); + bank.accounts.add(acc1); + bank.accounts.add(acc2); + bank.accounts.add(acc3); + bank.accounts.add(acc4); + bank.accounts.add(acc5); + Admin admin = new Admin(bank); + + //should flag as suspicious - withdrawing more than 50% of balance + acc1.withdraw(1000); + //should not flag as suspicious - withdrawing less than 50% of balance + acc2.withdraw(300); + //should flag as suspicious - depositing more than 200% of balance + acc3.Deposit(1000000); + //should not flag as suspicious - depositing less than 200% of balance + acc4.Deposit(15000); + //should flag as suspicious - depositing more than 200% of balance + acc5.Deposit(3000); + + Collection expectedStr = new ArrayList(); + expectedStr.add("acc1"); + expectedStr.add("acc3"); + expectedStr.add("acc5"); + assertEquals(expectedStr, admin.findAcctIdsWithSuspiciousActivity()); + + } +} diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index d19ecb02..13ae218f 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -2,39 +2,169 @@ import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.Collection; + import static org.junit.jupiter.api.Assertions.*; class BankAccountTest { +// @Test +// void getBalanceTest() throws InsufficientFundsException { +// +// //valid case +// BankAccount bankAccount = new BankAccount("", 200); +// assertEquals(200, bankAccount.getBalance()); +// +// //after successfull withdraw +// bankAccount.withdraw(100); +// assertEquals(100, bankAccount.getBalance()); +// +// } + @Test - void getBalanceTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); + void isAmountValidTest(){ + //negative amount border case + assertFalse(BankAccount.isAmountValid(-00.01)); - assertEquals(200, bankAccount.getBalance()); - } + //negative amount + assertFalse(BankAccount.isAmountValid(-100)); - @Test - void withdrawTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); - bankAccount.withdraw(100); + //positive border case + assertTrue(BankAccount.isAmountValid(00.01)); - assertEquals(100, bankAccount.getBalance()); - } + //positive amount + assertTrue(BankAccount.isAmountValid(100.00)); - @Test - void isEmailValidTest(){ - assertTrue(BankAccount.isEmailValid( "a@b.com")); - assertFalse( BankAccount.isEmailValid("")); + //invalid format border case + assertFalse(BankAccount.isAmountValid(123.987)); + + //invalid format + assertFalse(BankAccount.isAmountValid(83746.82736453)); } - @Test - void constructorTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); - assertEquals("a@b.com", bankAccount.getEmail()); - assertEquals(200, bankAccount.getBalance()); - //check for exception thrown correctly - assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); - } +// @Test +// void withdrawTest() throws InsufficientFundsException, IllegalArgumentException{ +// //greater than balance +// assertThrows(InsufficientFundsException.class, ()-> new BankAccount("a@b.com", 100).withdraw(101)); +// +// +// //less than balance +// BankAccount bankaccount = new BankAccount("a@b.com", 200); +// bankaccount.withdraw(100); +// assertEquals(100, bankaccount.getBalance()); +// +// +// //equal to balance +// bankaccount = new BankAccount("a@b.com", 300); +// bankaccount.withdraw(300); +// assertEquals(0, bankaccount.getBalance()); +// +// +// //negative - argument thrown +// assertThrows(IllegalArgumentException.class,() -> new BankAccount("a@b.com", 300).withdraw(-1)); +// +// +// //invalid input +// assertThrows(IllegalArgumentException.class,() -> new BankAccount("a@b.com",200).withdraw(100.005)); +// } + + +// @Test +// void isEmailValidTestUpdated(){ +// // checks for a basic, valid email and for empty string +// assertTrue(BankAccount.isEmailValid( "a@b.com")); +// assertFalse( BankAccount.isEmailValid(" ")); +// +// // checks for forbidden characters... border case: one forbidden characters is present +// assertFalse(BankAccount.isEmailValid("ab#c@gmail.com")); +// assertFalse(BankAccount.isEmailValid("ab-c @gmail.com")); +// +// // checks for 1 period after the @... border case: 0, 1, or 2 periods found +// assertTrue(BankAccount.isEmailValid("hay@mail.com")); +// assertFalse(BankAccount.isEmailValid("hayyy@mailcom")); +// assertFalse(BankAccount.isEmailValid("hay@ma.il.com")); +// +// // checks for the proper number of @ symbols... border case: 0, 1, or 2 @'s present +// assertTrue(BankAccount.isEmailValid("cmartano@gmail.com")); +// assertFalse(BankAccount.isEmailValid("cmartanoaol.com")); +// assertFalse(BankAccount.isEmailValid("c@martano@yahoo.com")); +// +// // checks for the number of characters after the last period... border case: 1 or 2 +// assertTrue(BankAccount.isEmailValid("name@place.co")); +// assertFalse(BankAccount.isEmailValid("name@place.c")); +// +// // checks that each dash is a "legal" dash... border case: dash to start, 2 in a row, before @ symbol +// assertTrue(BankAccount.isEmailValid("c-martano@gmail.com")); +// assertFalse(BankAccount.isEmailValid("marta--no@gmail.com")); +// assertFalse(BankAccount.isEmailValid("-christianmar-tano@aol.com")); +// assertFalse(BankAccount.isEmailValid("c-l-martano-@gmail.com")); +// +// // checks that each period is a "legal" period... border case: period to start, 2 in a row, before @ symbol +// assertTrue(BankAccount.isEmailValid("c.martano@gmail.com")); +// assertFalse(BankAccount.isEmailValid("c.ma..rtano@gmail.com")); +// assertFalse(BankAccount.isEmailValid(".christian@gmail.com")); +// assertFalse(BankAccount.isEmailValid("c.l.martano.@gmail.com")); +// +// +// //presence of invalid character +// assertTrue(BankAccount.isEmailValid("abc@google.com")); +// assertFalse( BankAccount.isEmailValid("abc-@mail.com")); +// assertFalse( BankAccount.isEmailValid("abc.@mail.com")); +// assertFalse( BankAccount.isEmailValid(".abc@mail.com")); +// assertFalse( BankAccount.isEmailValid("abc#def@mail.com")); +// } +// +// +// @Test +// void constructorTest() { +// //valid test case +// BankAccount bankAccount = new BankAccount("a@b.com", 200); +// assertEquals("a@b.com", bankAccount.getEmail()); +// assertEquals(200, bankAccount.getBalance()); +// +// //check for email exception thrown correctly +// assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); +// +// //check for balance exception thrown correctly, border case +// assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -00.01)); +// +// } + + +// @Test +// void transferTest() throws IllegalArgumentException, InsufficientFundsException{ +// BankAccount sender = new BankAccount("a@b.com", 500); +// BankAccount reciever = new BankAccount("y@z.com", 0); +// //successfull transfer +// sender.Transfer(reciever,100); +// assertEquals(400, sender.getBalance()); +// assertEquals(100, reciever.getBalance()); +// +// //transfer with change +// sender.Transfer(reciever, 1.50); +// assertEquals(398.50, sender.getBalance()); +// assertEquals(101.50, reciever.getBalance()); +// +// //0 dollars transfered +// sender.Transfer(reciever, 0); +// assertEquals(398.50, sender.getBalance()); +// assertEquals(101.50, reciever.getBalance()); +// +// //negative amount trying to be transfered +// assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 100).Transfer(new BankAccount("c@d.com", 0),-5)); +// +// //invalid input check +// assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 100).Transfer(new BankAccount("y@z.com", 0),0.223)); +// +// //trying to transfer insufficent funds +// assertThrows(InsufficientFundsException.class, ()-> new BankAccount("a@b.com", 100).Transfer(new BankAccount("hay@hay.com", 0),300)); +// +// //checks to be sure illegal argument is thrown rather than insufficient funds when both are valid +// assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 10).Transfer(new BankAccount("c@d.com", 0),100.3131)); +// } + + } \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java new file mode 100644 index 00000000..6dadecdf --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java @@ -0,0 +1,14 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CentralBankTest { + @Test + void checkbalanceTest(){ + //CheckingAccount acct =new CheckingAccount("christian",200); + //assertEquals(200,acct.getBalance()); + } + +} diff --git a/src/test/java/edu/ithaca/dragon/bank/SystemTest.java b/src/test/java/edu/ithaca/dragon/bank/SystemTest.java new file mode 100644 index 00000000..2bc78a20 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/SystemTest.java @@ -0,0 +1,79 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.jupiter.api.Assertions.*; + +public class SystemTest { + + @Test + void SystemTest() throws InsufficientFundsException { + CentralBank bank = new CentralBank(); + + User user1 = new User("user1", "pass1"); + User user2 = new User("user2", "pass2"); + bank.users.add(user1); + bank.users.add(user2); + + CheckingAccount acc1 = new CheckingAccount(1000, "acc1"); + SavingsAccount acc2 = new SavingsAccount(1000, "acc2", .01, 200); + bank.accounts.add(acc1); + bank.accounts.add(acc2); + + acc1.Deposit(100); + acc2.Deposit(100); + acc1.withdraw(200); + acc2.withdraw(200); + + assertEquals(900, acc1.getBalance()); + assertEquals(900, acc2.getBalance()); + + Admin admin = new Admin(bank); + assertEquals(1800, admin.calcTotalAssets()); + + Collection expectedStr = new ArrayList(); + assertEquals(expectedStr, admin.findAcctIdsWithSuspiciousActivity()); + } + + @Test + void getTransactionHistoryTest() throws InsufficientFundsException { + CentralBank bank = new CentralBank(); + + User user1 = new User("user1", "pass1"); + User user2 = new User("user2", "pass2"); + bank.users.add(user1); + bank.users.add(user2); + + CheckingAccount acc1 = new CheckingAccount(1000, "acc1"); + SavingsAccount acc2 = new SavingsAccount(1000, "acc2", .01, 200); + bank.accounts.add(acc1); + bank.accounts.add(acc2); + + acc1.Deposit(100); + LocalDateTime time1 = LocalDateTime.now(); + acc2.Deposit(100); + LocalDateTime time2 = LocalDateTime.now(); + acc1.withdraw(200); + LocalDateTime time3 = LocalDateTime.now(); + acc2.withdraw(200); + LocalDateTime time4 = LocalDateTime.now(); + + Transaction acc1trn1 = new Transaction(1000, 100, 1100, time1, false); + Transaction acc1trn2 = new Transaction(1100, -200, 900, time2, false); + ArrayList acc1Trns = new ArrayList(); + acc1Trns.add(acc1trn1); + acc1Trns.add(acc1trn2); + assertEquals(acc1Trns.toString(), acc1.getTransactionHistory().toString()); + + Transaction acc2trn1 = new Transaction(1000, 100, 1100, time3, false); + Transaction acc2trn2 = new Transaction(1100, -200, 900, time4, false); + ArrayList acc2Trns = new ArrayList(); + acc2Trns.add(acc2trn1); + acc2Trns.add(acc2trn2); + assertEquals(acc2Trns.toString(), acc2.getTransactionHistory().toString()); + } +} diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java new file mode 100644 index 00000000..17dbae28 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -0,0 +1,39 @@ +package edu.ithaca.dragon.bank; +import java.io.*; +import java.util.*; +import org.junit.jupiter.api.Test; + +import java.util.Collection; + +import static org.junit.jupiter.api.Assertions.*; + +public class TellerTest { + + @Test + void createAccountTest() { + CentralBank myBank = new CentralBank(); + Collection users = new ArrayList(); + User charles = new User("Charles","123"); + Teller acct= new Teller(myBank); + acct.createAccount(charles,"CharlesSaves", 100, true); + assertTrue(myBank.accounts.contains(myBank.getBankAccount("CharlesSaves"))); + acct.createAccount(charles,"CharlesChecking", 100, false); + assertTrue(myBank.accounts.contains(myBank.getBankAccount("CharlesChecking"))); + + } + + @Test + void CloseAccountTest() { + CentralBank myBank = new CentralBank(); + User charles = new User("Charles","123"); + Collection users = new ArrayList(); + Teller acct= new Teller(myBank); + acct.createAccount(charles,"CharlesSaves", 100, true); + acct.closeAccount(charles,"CharlesSaves"); + assertThrows(IllegalArgumentException.class, ()-> myBank.accounts.contains(myBank.getBankAccount("CharlesSaves"))); + acct.createAccount(charles,"CharlesChecking", 100, false); + acct.closeAccount(charles,"CharlesChecking"); + assertThrows(IllegalArgumentException.class, ()-> myBank.accounts.contains(myBank.getBankAccount("CharlesChecking"))); + + } +}