diff --git a/README.md b/README.md
index 92d73b7..2414814 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
-# project-2-ATM
-Week 2 project: ATM Simulator
+# project-2-Menu
+Week 2 project: Menu Simulator
-## ATM Requirements
+## Menu Requirements
Every feature must have corresponding unit tests
Tests should demonstrate proper behavior, and proper handling of misuse (eg. attempts to deposit/transfer/withdraw negative amounts
-- User interface: CLI (Command line interface) Only
+- UserAccount interface: CLI (Command line interface) Only
- Direct Input
- Numbered options (instead of on-screen buttons)
- ASCII art welcome but not required
@@ -14,7 +14,7 @@ Tests should demonstrate proper behavior, and proper handling of misuse (eg. att
- Checking
- Savings
- Investment
-- Account Actions
+- BankAccount Actions
- Withdraw from acct
- Deposit to acct
- Transfer across accounts (self)
diff --git a/pom.xml b/pom.xml
index 9901415..83225ce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,8 +5,85 @@
4.0.0
io.zipcoder
- project-2-atm
+ project-2-menu
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
+
+
+ org.testng
+ testng
+ RELEASE
+ test
+
+<<<<<<< HEAD
+=======
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ compile
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+>>>>>>> af305ec406a1dd384cd44f62166ca43f3c4e159f
+
\ No newline at end of file
diff --git a/src/main/java/AccountTrans.java b/src/main/java/AccountTrans.java
new file mode 100644
index 0000000..ef1eec7
--- /dev/null
+++ b/src/main/java/AccountTrans.java
@@ -0,0 +1,75 @@
+
+import java.text.NumberFormat;
+
+public class AccountTrans {
+
+ private NumberFormat formatter;
+ private Console c;
+
+ public AccountTrans() {
+ this.c = new Console();
+ this.formatter = NumberFormat.getCurrencyInstance();
+ }
+
+ public void depositMoney(BankAccount chosenBankAccount) {
+ // Keeps track of which account to deposit money to - checking or saving
+ System.out.println("\nYour current " + chosenBankAccount.getAccountType() + " balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n");
+ System.out.println("How much money would you like to deposit?");
+
+ Double deposit;
+ deposit = c.getDoubleInput();
+ if (deposit < 0) {
+ System.out.println("Please enter amount greater than ZERO");
+ } else {
+ chosenBankAccount.deposit(deposit);
+ System.out.println("\nYour " + chosenBankAccount.getAccountType() + " balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n");
+ chosenBankAccount.printTxn(chosenBankAccount.getAccountType() + " Deposit ", deposit, chosenBankAccount.getBalance());
+ System.out.println();
+ }
+ }
+
+ public void withdrawMoney(BankAccount chosenBankAccount) {
+
+ System.out.println("\nYour current " + chosenBankAccount.getAccountType() + " balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n");
+ System.out.println("How much money would you like to withdraw?");
+
+ Double withdraw;
+ withdraw = c.getDoubleInput();
+ if (withdraw > chosenBankAccount.getBalance()) {
+ System.out.println("INSUFFICIENT BALANCE! Your request will not be processed. \n");
+ } else {
+ chosenBankAccount.withdraw(withdraw);
+ System.out.println("\nYour " + chosenBankAccount.getAccountType() + " balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n");
+ chosenBankAccount.printTxn(chosenBankAccount.getAccountType() + " withdraw ", withdraw, chosenBankAccount.getBalance() );
+ System.out.println();
+ }
+ }
+
+ public void transferMoney(BankAccount chosenTransferFromAccount, BankAccount chosenTransferToAccount) {
+ System.out.println("\nYour current " + chosenTransferFromAccount.getAccountType() + " balance is: " + formatter.format(chosenTransferFromAccount.getBalance()) + "\n");
+ System.out.print("How much money do you wish to transfer from " + chosenTransferFromAccount.getAccountType() + " to " + chosenTransferToAccount.getAccountType() + "?: ");
+
+ Double tranAmount;
+ tranAmount = c.getDoubleInput();
+ if (tranAmount > chosenTransferFromAccount.getBalance()) {
+ System.out.println("INSUFFICIENT BALANCE! " + "Please enter a new amount.");
+ } else {
+ chosenTransferFromAccount.withdraw(tranAmount);
+ chosenTransferToAccount.deposit(tranAmount);
+
+ System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from " + chosenTransferFromAccount.getAccountType() + " to " + chosenTransferToAccount.getAccountType());
+ System.out.println("\n" + chosenTransferFromAccount.getAccountType() + " Balance: " + formatter.format(chosenTransferFromAccount.getBalance()));
+ System.out.println(chosenTransferToAccount.getAccountType() + " Balance: " + formatter.format(chosenTransferToAccount.getBalance()) + "\n");
+ }
+ }
+
+ public void checkBalance (UserAccount currentUser) {
+ System.out.println("\nChecking Balance: " + formatter.format(currentUser.getCheckingAccount().getBalance()));
+ System.out.println("Savings Balance: " + formatter.format(currentUser.getSavingsAccount().getBalance()));
+ System.out.println("Investment Balance: " + formatter.format(currentUser.getInvestmentAccount().getBalance()) + "\n");
+ }
+
+
+}
+
+
diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java
new file mode 100644
index 0000000..5a4585f
--- /dev/null
+++ b/src/main/java/BankAccount.java
@@ -0,0 +1,67 @@
+import java.text.NumberFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+
+
+public class BankAccount {
+
+
+ public String accountType;
+ private double currentBalance;
+ NumberFormat formatter = NumberFormat.getCurrencyInstance();
+
+
+ public BankAccount(String chosenAccountType) {
+ this.accountType = chosenAccountType;
+ this.currentBalance = 0;
+ }
+
+
+ void setType(String accType) {
+ accountType = accType;
+ }
+
+ void setBalance(Double accBal) {
+ currentBalance = accBal;
+ }
+
+ public String getAccountType() {
+ return this.accountType;
+ }
+
+ Double getBalance() {
+ return currentBalance;
+ }
+
+ void deposit(Double dep) {
+ currentBalance = currentBalance + dep;
+ }
+
+ void withdraw(Double wit) {
+ currentBalance = currentBalance - wit;
+ }
+
+ void printTxn(String txnType, Double amt, Double balance){
+
+
+ System.out.println("|---------------------------------------------------------");
+ System.out.println("| BANK OF ZIP CODE WILMINGTON DE ");
+ System.out.println("|---------------------------------------------------------");
+ System.out.println("|" + dateTime() + " ");
+ System.out.println("|---------------------------------------------------------");
+ System.out.println("| Transaction Receipt ");
+ System.out.println("|" + txnType + " ");
+ System.out.println("|" + amt + "" + " ");
+ System.out.println("|Remaining Balance: " + balance + " ");
+ System.out.println("|---------------------------------------------------------");
+
+ }
+ String dateTime(){
+
+ DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
+ LocalDateTime now = LocalDateTime.now();
+
+ return timeFormat.format(now);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/Console.java b/src/main/java/Console.java
new file mode 100644
index 0000000..6b437a4
--- /dev/null
+++ b/src/main/java/Console.java
@@ -0,0 +1,35 @@
+import java.util.Scanner;
+
+public class Console {
+
+ public String getStringInput() {
+ Scanner scanner = new Scanner(System.in);
+ String userInput = scanner.nextLine();
+ if (userInput.isEmpty()) {
+ System.out.println("Invalid Input!");
+ userInput = scanner.nextLine();
+ }
+ return userInput;
+ }
+
+ public Integer getIntegerInput() {
+ Scanner scanner = new Scanner(System.in);
+ while(!scanner.hasNextInt()) {
+ System.out.println("Invalid Input!");
+ scanner.next();
+ }
+ int userInput = scanner.nextInt();
+ return userInput;
+ }
+
+ public Double getDoubleInput() {
+ Scanner scanner = new Scanner(System.in);
+ while(!scanner.hasNextDouble()) {
+ System.out.println("Invalid Input!");
+ scanner.next();
+ }
+ double userInput = scanner.nextDouble();
+ return userInput;
+ }
+
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 05e41a9..2eee3e9 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -4,6 +4,7 @@
public class Main {
public static void main(String[] args){
-
+ Menu menu = new Menu();
+ menu.printMenus();
}
}
diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java
new file mode 100644
index 0000000..00d7572
--- /dev/null
+++ b/src/main/java/Menu.java
@@ -0,0 +1,140 @@
+public class Menu {
+
+ private UserAccount currentUser;
+ private boolean loggedIn;
+ private Console c;
+ private UserManagement ls;
+ private AccountTrans ae;
+
+ public Menu() {
+ this.c = new Console();
+ this.ls = new UserManagement();
+ this.ae = new AccountTrans();
+ this.loggedIn = false;
+ this.currentUser = null;
+ }
+
+ public void printMenus() {
+
+ while (true) { // If user not logged in, show welcome menu
+ if (this.loggedIn == false) {
+ this.printWelcomeMenu();
+
+ } else { // If user is logged in, show User menu
+ this.printUserMenu();
+ }
+ }
+
+ }
+
+ public void printWelcomeMenu() {
+ System.out.println("WELCOME TO THE BANK OF ZIP CODE");
+ System.out.println("LOCATED IN WILMINGTON, DELAWARE");
+ System.out.println("PRESS 1 TO LOGIN");
+ System.out.println("PRESS 2 IF YOU ARE A NEW USER");
+
+ Integer userInput;
+ userInput = c.getIntegerInput();
+
+ switch (userInput) {
+ case 1: // LOGIN
+ this.currentUser = ls.validateLoginCredentials();
+ if (this.currentUser != null) {
+ this.loggedIn = true;
+ }
+ break;
+ case 2: // CREATE NEW ACCOUNT
+ this.currentUser = ls.createNewUserAccount();
+ if (this.currentUser != null) {
+ this.loggedIn = true;
+ }
+ break;
+ default:
+ System.out.println("Invalid input. Please select either 1 or 2.");
+ }
+ }
+
+ public void printUserMenu() {
+ System.out.println("WELCOME " + this.currentUser.getUsername());
+ System.out.println("USER MENU");
+ System.out.println("0 - LogOut");
+ System.out.println("1 - Deposit");
+ System.out.println("2 - Withdraw");
+ System.out.println("3 - Transfer Funds");
+ System.out.println("4 - Check Balance");
+ System.out.println("5 - Close Account");
+
+ Integer userInput;
+ userInput = c.getIntegerInput();
+
+ switch (userInput) {
+ case 0:
+ this.loggedIn = false;
+ this.currentUser = null;
+ this.printWelcomeMenu();
+ break;
+ case 1: // Deposit
+ this.ae.depositMoney(this.chooseAccount());
+ break;
+ case 2: // Withdraw
+ this.ae.withdrawMoney(this.chooseAccount());
+ break;
+ case 3: // Transfer between accounts
+ System.out.println("TRANSFER FROM ACCOUNT:");
+ BankAccount transferFrom = chooseAccount();
+ System.out.println("TRANSFER TO ACCOUNT:");
+ BankAccount transferTo = chooseAccount();
+ this.ae.transferMoney(transferFrom, transferTo);
+ break;
+ case 4: // Check Balance
+ this.ae.checkBalance(this.currentUser);
+ break;
+ case 5: // Close Account
+ this.ls.closeAccount();
+ this.loggedIn = false;
+ this.currentUser = null;
+ this.printWelcomeMenu();
+ break;
+ default:
+ System.out.println("Invalid input. Please select one of the listed options.");
+ break;
+ }
+ }
+
+ public BankAccount chooseAccount() {
+ BankAccount currentAccount = null;
+ System.out.println("Which Account would you like to use?");
+ System.out.println("Press 0 to Log Out");
+ System.out.println("Press 1 for Checking");
+ System.out.println("Press 2 for Savings");
+ System.out.println("Press 3 for Investment");
+
+ Integer userInput = c.getIntegerInput();
+
+ switch (userInput) {
+ case 0: // Log out
+ this.loggedIn = false;
+ this.currentUser = null;
+ this.printWelcomeMenu();
+ break;
+ case 1: // Choose checking
+ currentAccount = this.currentUser.getCheckingAccount();
+ break;
+ case 2: // Choose savings
+ currentAccount = this.currentUser.getSavingsAccount();
+ break;
+ case 3: // Choose Investments
+ currentAccount= this.currentUser.getInvestmentAccount();
+ break;
+ default:
+ System.out.println("Invalid input.");
+ this.printUserMenu();
+ break;
+ }
+
+ return currentAccount;
+ }
+
+}
+
+
diff --git a/src/main/java/UserAccount.java b/src/main/java/UserAccount.java
new file mode 100644
index 0000000..a8a8717
--- /dev/null
+++ b/src/main/java/UserAccount.java
@@ -0,0 +1,39 @@
+import java.util.HashMap;
+import java.util.Map;
+
+public class UserAccount {
+
+ private String username;
+ private String password;
+ private Map userBankAccounts;
+
+ public UserAccount(String username, String password) {
+ this.username = username;
+ this.password = password;
+ this.userBankAccounts = new HashMap();
+ this.userBankAccounts.put("Checking", new BankAccount("Checking"));
+ this.userBankAccounts.put("Savings", new BankAccount("Savings"));
+ this.userBankAccounts.put("Investment", new BankAccount("Investment"));
+ }
+
+ public BankAccount getCheckingAccount() {
+ return this.userBankAccounts.get("Checking");
+ }
+
+ public BankAccount getSavingsAccount() {
+ return this.userBankAccounts.get("Savings");
+ }
+
+ public BankAccount getInvestmentAccount() {
+ return this.userBankAccounts.get("Investment");
+ }
+
+ public String getUsername() {
+ return this.username;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+}
diff --git a/src/main/java/UserManagement.java b/src/main/java/UserManagement.java
new file mode 100644
index 0000000..6a00331
--- /dev/null
+++ b/src/main/java/UserManagement.java
@@ -0,0 +1,96 @@
+import java.util.HashMap;
+
+public class UserManagement {
+
+ Console c = new Console();
+ private String enteredUserName;
+ private String enteredPassword;
+ private HashMap userNamePasswordMap;
+ private HashMap userAccountsList;
+
+ public UserManagement() {
+ this.userNamePasswordMap = new HashMap();
+ this.userAccountsList = new HashMap();
+ }
+
+ // Need this one for testing
+ public UserManagement(String username, String password) {
+ this.userNamePasswordMap = new HashMap();
+ this.userAccountsList = new HashMap();
+ this.enteredPassword = password;
+ this.enteredUserName = username;
+ }
+
+ // Need this one for testing
+ public HashMap getUserNamePasswordMap() {
+ return this.userNamePasswordMap;
+ }
+
+ // Need this one for testing
+ public HashMap getUserAccountsList() {
+ return this.userAccountsList;
+ }
+
+ public void getInputUserName() {
+ System.out.println("Username:");
+ this.enteredUserName = c.getStringInput();
+ }
+
+ public void getInputPassword() {
+ System.out.println("Password:");
+ this.enteredPassword = c.getStringInput();
+ }
+
+ public boolean validateUserNameExists() {
+ return this.userNamePasswordMap.containsKey(this.enteredUserName);
+ }
+
+ public boolean validatePasswordCorrect() {
+ return this.userNamePasswordMap.get(this.enteredUserName).equals(this.enteredPassword);
+ }
+
+ public UserAccount validateLoginCredentials() {
+ getInputUserName();
+ getInputPassword();
+ if(this.validateUserNameExists() == false) {
+ System.out.println("No such user exists.");
+ } else if (this.validatePasswordCorrect() == false) {
+ System.out.println("Password is incorrect.");
+ } else {
+ System.out.println("You are now logged in.");
+ return userAccountsList.get(this.enteredUserName);
+ }
+
+ return null;
+ }
+
+ public UserAccount createNewUserAccount() {
+ System.out.println("Enter your new username and password.");
+ getInputUserName();
+ int attempts = 0;
+ while (attempts < 3) {
+ if (this.validateUserNameExists() == false) {
+ getInputPassword();
+ setUpUserAccount();
+ System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!");
+ return userAccountsList.get(this.enteredUserName);
+ } else {
+ System.out.println("Username is already taken. Be a bit more original!");
+ attempts += 1;
+ }
+ }
+ return null;
+ }
+
+ public void setUpUserAccount() {
+ this.userNamePasswordMap.put(this.enteredUserName, this.enteredPassword);
+ this.userAccountsList.put(this.enteredUserName, new UserAccount(this.enteredUserName, this.enteredPassword));
+ }
+
+ public void closeAccount() {
+ this.userNamePasswordMap.remove(this.enteredUserName);
+ this.userAccountsList.remove(this.enteredUserName);
+ System.out.println("Sorry to see you go " + this.enteredUserName + "! Your account is now closed...Oh, you want your money? LOL");
+ }
+}
+
diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java
deleted file mode 100644
index cbea4ad..0000000
--- a/src/main/test/AccountTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.junit.Assert.assertEquals;
-
-
-// Test the expected Account class from ATM.
-public class AccountTest {
-
- @Test
- public void testA0() {
- Account a = new Account(0.0);
- assertEquals(0.0, a.balance(), 0.0001);
- }
-
- @Test
- public void testA00() {
- Account a = new Account(10.0);
- assertEquals(10.0, a.balance(), 0.0001);
- }
-
- @Test
- public void testA01() {
- Account a = new Account(0.0);
- assertEquals(true, a.closeAccount());
- }
-
- @Test
- public void testA02() {
- Account a = new Account(10.0);
- assertEquals(false, a.closeAccount());
- }
-
- @Test
- public void testA1() {
- Account a = new Account(0.0);
- a.deposit(100.0);
- assertEquals(100.0, a.balance(), 0.0001);
- }
-
- @Test
- public void testA2() {
- Account a = new Account(10.0);
- a.deposit(100.0);
- assertEquals(110.0, a.balance(), 0.0001);
- }
-
- @Test
- public void testA3() {
- Account a = new Account(200.0);
- Double actual = a.withdraw(100.0);
- assertEquals(100.0, actual, 0.0001);
- }
-
- @Test
- public void testA4() {
- Account a = new Account(0.0);
- Double actual = a.withdraw(1.0);
- assertEquals(0.0, actual, 0.0001);
- }
-
- @Test
- public void testA5() {
- Account a = new Account(10.0);
- Account b = new Account(0.0);
- a.transfer(b, 10.0);
- assertEquals(0.0, a.balance(), 0.0001);
- assertEquals(10.0, b.balance(), 0.0001);
- }
-
- @Test
- public void testA6() {
- Account a = new Account(10.0);
- Account b = new Account(0.0);
- a.transfer(b, 100.0); // nothing should happen
- assertEquals(10.0, a.balance(), 0.0001);
- assertEquals(0.0, b.balance(), 0.0001);
- }
-
-
-}
diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java
new file mode 100644
index 0000000..9abf247
--- /dev/null
+++ b/src/main/test/BankAccountTest.java
@@ -0,0 +1,136 @@
+
+import org.testng.annotations.Test;
+import org.testng.Assert;
+
+// Test the expected Account class from ATM.
+public class BankAccountTest {
+
+ @Test
+ public void constructorCActTypeTest1() { // tests creation of checking account - type field
+ // Arrange
+ BankAccount testAccount = new BankAccount("Checking");
+ String givenCAcctType = "Checking";
+ String returnedCAcctType = testAccount.getAccountType();
+ Assert.assertEquals(givenCAcctType, returnedCAcctType);
+ }
+
+ @Test
+ public void constructorInitialBalanceTest1 () { // tests account balance 0.0 upon creation of BankAccount
+ //Arrange
+ String givenAccountType = "Checking";
+ Double givenCurrentBalance = 0.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ Double returnedBalance = testBankAccount.getBalance();
+ //Assert
+ Assert.assertEquals(givenCurrentBalance, returnedBalance);
+ }
+
+ @Test
+ public void constructorAcctTypeArgTest2 () { // tests creation of BankAccount sets account type
+ //Arrange
+ String givenAccountType = "Checking";
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ String returnedAccountType = testBankAccount.accountType;
+ //Assert
+ Assert.assertEquals(givenAccountType, returnedAccountType);
+
+ }
+ @Test
+ public void setTypeTest() { // tests method to reset account type
+ //Arrange
+ String givenAccountType = "Checking";
+ Double givenCurrentBalance = 0.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ testBankAccount.setType("Savings");
+ String returnedAccountType = testBankAccount.getAccountType();
+ //Assert
+ Assert.assertEquals("Savings", returnedAccountType);
+ }
+
+
+ @Test
+ public void getAccountTypeTest () { // tests method for return account type
+ //Arrange
+ String givenAccountType = "Checking";
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ String returnedAccountType = testBankAccount.getAccountType();
+ //Assert
+ Assert.assertEquals(givenAccountType, returnedAccountType);
+ }
+
+ @Test
+ public void setBalanceTest () { // tests method to reset account balance
+ //Arrange
+ String givenAccountType = "Investment";
+ Double givenCurrentBalance = 0.0;
+ Double expectedAccountBal = 100.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ testBankAccount.setBalance(100.0);
+ Double returnedAccountBal = testBankAccount.getBalance();
+ //Assert
+ Assert.assertEquals(expectedAccountBal, returnedAccountBal);
+ }
+
+ @Test
+ public void getBalanceTest () { // tests method to reset account balance
+ //Arrange
+ String givenAccountType = "Investment";
+ Double givenCurrentBalance = 0.0;
+ Double expectedAccountBal = 100.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ testBankAccount.setBalance(100.0);
+ Double returnedAccountBal = testBankAccount.getBalance();
+ //Assert
+ Assert.assertEquals(expectedAccountBal, returnedAccountBal);
+ }
+
+ @Test
+ public void depositTest () {
+ //Arrange
+ String givenAccountType = "Investment";
+ Double expectedAccountBal = 200.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ testBankAccount.setBalance(100.00);
+ testBankAccount.deposit(100.0);
+ Double returnedAccountBalance = testBankAccount.getBalance();
+ //Assert
+ Assert.assertEquals(expectedAccountBal, returnedAccountBalance);
+ }
+
+ @Test
+ public void withdrawTest () {
+ //Arrange
+ String givenAccountType = "Investment";
+ Double expectedAccountBal = 0.0;
+ //Act
+ BankAccount testBankAccount = new BankAccount(givenAccountType);
+ testBankAccount.setBalance(100.00);
+ testBankAccount.withdraw(100.0);
+ Double returnedAccountBalance = testBankAccount.getBalance();
+ //Assert
+ Assert.assertEquals(expectedAccountBal, returnedAccountBalance);
+ }
+
+ @Test
+ public void dateTimeTest () { // tests return of date and time method
+ //Arrange
+ String givenAccountType = "Checking";
+ //Act
+ BankAccount testBankAccount1 = new BankAccount(givenAccountType);
+ BankAccount testBankAccount2 = new BankAccount(givenAccountType);
+ System.out.println(testBankAccount1.dateTime());
+ System.out.println(testBankAccount2.dateTime());
+ String expectedDateTime = testBankAccount1.dateTime();
+ String returnedDateTime = testBankAccount2.dateTime();
+ //Assert
+ Assert.assertEquals(expectedDateTime, returnedDateTime);
+ }
+
+}
diff --git a/src/main/test/ConsoleTest.java b/src/main/test/ConsoleTest.java
new file mode 100644
index 0000000..2ac2799
--- /dev/null
+++ b/src/main/test/ConsoleTest.java
@@ -0,0 +1,25 @@
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+public class ConsoleTest {
+
+ @Test
+ public void testStringInput() {
+ InputStream sysInBackup = System.in; // backup System.in to restore it later
+ ByteArrayInputStream in = new ByteArrayInputStream("1".getBytes());
+ System.setIn(in);
+
+ Console c = new Console();
+ String actual = c.getStringInput();
+
+ Assert.assertEquals(actual, "1");
+
+ System.setIn(sysInBackup);
+ }
+
+}
+
diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java
new file mode 100644
index 0000000..d8d4c0d
--- /dev/null
+++ b/src/main/test/UserAccountTest.java
@@ -0,0 +1,94 @@
+
+// Test the expected User class from ATM.
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class UserAccountTest {
+
+ @Test // tests constructor for user with name & password
+ public void testGetConstructorUserNamePWTest() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+ String actualUsername = testUser.getUsername();
+ String actualPassword = testUser.getPassword();
+
+ Assert.assertEquals(expectedUsername, actualUsername);
+ Assert.assertEquals(expectedPassword, actualPassword);
+ }
+
+ @Test // method returns username how to test: pass in username value, check to make sure username returned
+ // is same as what you passed in
+ public void testGetUsernameTest() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+ String actualUsername = testUser.getUsername();
+
+ Assert.assertEquals(actualUsername, expectedUsername);
+ }
+
+ @Test
+ public void testGetUsernameTestNeg() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+ String actualUsername = testUser.getUsername();
+
+ Assert.assertNotEquals(actualUsername, "unknown");
+ }
+
+ @Test // method returns password how to test: pass in username value, check to make sure username returned
+ // is same as what you passed in
+ public void testGetPasswordTest() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+ String actualPassword = testUser.getPassword();
+
+ Assert.assertEquals(actualPassword, expectedPassword);
+ }
+
+ @Test
+ public void testGetPasswordTestNeg() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+ String actualPassword = testUser.getPassword();
+
+ Assert.assertNotEquals(actualPassword, "Unknown");
+ }
+
+ @Test
+ public void testGetCheckingAccount() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+
+ String actual = testUser.getCheckingAccount().getAccountType();
+
+ Assert.assertEquals(actual, "Checking");
+ }
+
+ @Test
+ public void testGetSavingsAccount() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+
+ String actual = testUser.getSavingsAccount().getAccountType();
+
+ Assert.assertEquals(actual, "Savings");
+ }
+
+ @Test
+ public void testGetInvestmentAccount() {
+ String expectedUsername = "User01";
+ String expectedPassword = "password123";
+ UserAccount testUser = new UserAccount(expectedUsername, expectedPassword);
+
+ String actual = testUser.getInvestmentAccount().getAccountType();
+
+ Assert.assertEquals(actual, "Investment");
+ }
+}
diff --git a/src/main/test/UserManagementTest.java b/src/main/test/UserManagementTest.java
new file mode 100644
index 0000000..ef64f88
--- /dev/null
+++ b/src/main/test/UserManagementTest.java
@@ -0,0 +1,64 @@
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.HashMap;
+
+public class UserManagementTest {
+
+ @Test
+ public void testConstructor() {
+ UserManagement um = new UserManagement("TestAccount", "123");
+
+ String actual = (String) um.getUserAccountsList().get("TestAccount");
+ String actual2 = (String) um.getUserNamePasswordMap().get("TestAccount");
+
+ Assert.assertEquals(actual, null);
+ }
+
+ @Test
+ public void testValidateUserNameExists() {
+ UserManagement um = new UserManagement("TestAccount", "123");
+
+ um.setUpUserAccount();
+ boolean actual = um.validateUserNameExists();
+
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testValidatePasswordCorrect() {
+ UserManagement um = new UserManagement("TestAccount", "123");
+
+ um.setUpUserAccount();
+ boolean actual = um.validatePasswordCorrect();
+
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void setUpUserAccount() {
+ UserManagement um = new UserManagement("TestAccount", "123");
+
+ um.setUpUserAccount();
+ boolean actualPass = um.validatePasswordCorrect();
+ boolean actualUN = um.validateUserNameExists();
+
+ Assert.assertTrue(actualPass);
+ Assert.assertTrue(actualUN);
+ }
+
+ @Test
+ public void closeUserAccount() {
+ UserManagement um = new UserManagement("TestAccount", "123");
+
+ um.setUpUserAccount();
+ um.closeAccount();
+
+ String actual = (String) um.getUserNamePasswordMap().get("TestAccount");
+ String actual2 = (String) um.getUserAccountsList().get("TestAccount");
+
+ Assert.assertEquals(actual, null);
+ Assert.assertEquals(actual2, null);
+ }
+
+}