diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6561aaa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.idea/ +AccessControl.iml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..2a1782b --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AccessControlLab \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..1c66e39 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5755a99 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d0f80ed --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..1a39558 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1003 @@ + + + + + + + + + + + + + squier.john.accessControl.* + + + squier.john.accessControl.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1484677864162 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AccessControl.iml b/AccessControl.iml new file mode 100644 index 0000000..5cf6df2 --- /dev/null +++ b/AccessControl.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AccessControlLab.png b/AccessControlLab.png new file mode 100644 index 0000000..f64460f Binary files /dev/null and b/AccessControlLab.png differ diff --git a/Access_Control_Lab.md b/Access_Control_Lab.md new file mode 100755 index 0000000..f290a1a --- /dev/null +++ b/Access_Control_Lab.md @@ -0,0 +1,41 @@ +# Access Control Lab - Bank Account + +## Description + +This lab focuses on implementing a simulated bank account and practicing using access control features of the Java language. By the end of this lab students should feel comfortable setting class members to be private or public, creating accessor and mutator functions for fields as needed, and using those methods to access the underlying fields. + +The bank account functionality produced in this lab will be integrated into the weekly project and may be further enhanced during the project. + +## Testing + +All features should be developed following a Test-Driven Development methodology. All features should be thoroughly tested and demonstrated through unit tests. + +## Instructions + +Create a class for bank accounts. + +Accounts must have: + +- Account type (Checking, Savings, Investment, etc.) +- Account number (Must be unique for each account created) +- Balance +- Account Holder's name +- Interest rate (some accounts may not draw interest) +- Status (Open, Closed, [OFAC](https://www.treasury.gov/about/organizational-structure/offices/Pages/Office-of-Foreign-Assets-Control.aspx) Freeze...) +- Overdraft prevention (enabled, disabled, or automatic account transfer*) +- A record of all transactions that have taken place on the accounts (withdrawals, deposits, transfers, and changes to the status, name, or interest rate) + + +Code that uses the Account class should not be able to change the properties of an account directly; this should be something handled by methods provided by the account class. The methods should enforce the following behavior: + +- Account type and account number must be set during account creation (in the constructor) and cannot be changed afterward. +- Balance inquiries are allowed at any time except while an account is under an OFAC freeze +- The balance can be changed with a credit (add money) or debit (remove money) + - Balance changes can only occur on `Open` accounts. + - The `debit` and `credit` methods should return an approval status indicating whether the transaction was approved. + - Accounts can transfer funds to or from another account with the same account holder -- Neither account's balance should fall below zero as a result of a transfer. +- Account holder's name must be set during account creation. It can be changed later (but not on closed accounts) +- Accounts with overdraft prevention enabled cannot over-draw (a debit that is greater than the account balance will be declined and the balance will not change) +- Accounts, once closed, cannot be reopened (frozen accounts can be unfrozen). + - No changes to the balance of an account can take place while it is closed or frozen + - Accounts must have a zero balance before they can be closed. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6775867 --- /dev/null +++ b/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + squier.john + AccessControlLab + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + + junit + junit + 4.12 + + + + \ No newline at end of file diff --git a/src/main/java/squier/john/accessControl/ApprovalStatus.java b/src/main/java/squier/john/accessControl/ApprovalStatus.java new file mode 100644 index 0000000..f19a6b8 --- /dev/null +++ b/src/main/java/squier/john/accessControl/ApprovalStatus.java @@ -0,0 +1,6 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public enum ApprovalStatus {APPROVED, NOT_APPROVED, ZERO_TRANSACTION, CANT_COMPLETE_DUE_TO_ACCT_STATUS;} diff --git a/src/main/java/squier/john/accessControl/BankAccount.java b/src/main/java/squier/john/accessControl/BankAccount.java new file mode 100644 index 0000000..74709b1 --- /dev/null +++ b/src/main/java/squier/john/accessControl/BankAccount.java @@ -0,0 +1,205 @@ +package squier.john.accessControl; + +import java.util.ArrayList; + +/** + * Created by johnsquier on 1/17/17. + */ +public class BankAccount { + + private BankAccountType accountType; + private int accountNumber; + private static int nextAccountNumber = 1; + private double balance; + private String accountHoldersName; + private double interestRate; + private BankAccountStatus accountStatus; + private OverdraftProtection overdraftProtection; + private ArrayList transactionRecord; + + public BankAccount(BankAccountType accountType, double balance, String accountHoldersName, double interestRate, + BankAccountStatus accountStatus, OverdraftProtection overdraftProtection) { + this.accountType = accountType; + accountNumber = nextAccountNumber++; + this.balance = balance; + this.accountHoldersName = accountHoldersName; + this.interestRate = interestRate; + this.accountStatus = accountStatus; + this.overdraftProtection = overdraftProtection; + transactionRecord = new ArrayList(); + } + + public Double getBalance() { + if ( accountStatus.equals(BankAccountStatus.OFAC_FROZEN) ) { + return null; + } + else { + return balance; + } + } + + public String getAccountHoldersName() { + return accountHoldersName; + } + + public void setAccountHoldersName(String newName) { + if (accountStatus.equals(BankAccountStatus.OPEN)) { + accountHoldersName = newName; + + transactionRecord.add(new BankAccountTransaction(TransactionType.NAME_CHANGE, 0.0, + accountStatus, this.accountHoldersName)); + + return; + } + } + + public BankAccountStatus getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(BankAccountStatus accountStatus) { + if ( isAccountOpenOrFrozen() ) { + // check balance if trying to close + if ( isNewAccountStatusClose(accountStatus) ) { + if ( this.balance == 0.0 ) { + this.accountStatus = accountStatus; + + transactionRecord.add(new BankAccountTransaction(TransactionType.STATUS_CHANGE, 0.0, + this.accountStatus, accountHoldersName)); + } + } + else { + this.accountStatus = accountStatus; + + transactionRecord.add(new BankAccountTransaction(TransactionType.STATUS_CHANGE, 0.0, + this.accountStatus, accountHoldersName)); + } + } + + return; + } + + private boolean isAccountOpenOrFrozen() { + return !accountStatus.equals(BankAccountStatus.CLOSED); + } + + private boolean isNewAccountStatusClose(BankAccountStatus newStatus) { + return newStatus.equals(BankAccountStatus.CLOSED); + } + + public ApprovalStatus updateBalanceWithCreditOrDebit(double amount) { + + if ( accountStatus.equals(BankAccountStatus.OPEN) ) { + + if ( overdraftProtection.equals(OverdraftProtection.ENABLED) ) { + if ( isTransactionAnOverDraft(amount) ) { + return ApprovalStatus.NOT_APPROVED; + } + } + + if ( amount > 0.0 ) { + return credit(amount); + } + else if ( amount < 0.0 ) { + return debit(amount); + } + else { + return ApprovalStatus.ZERO_TRANSACTION; + } + } + else { + return ApprovalStatus.CANT_COMPLETE_DUE_TO_ACCT_STATUS; + } + } + + private ApprovalStatus credit(double amountToCredit) { + Double previousBalance = getBalance(); + balance += amountToCredit; + + // check if balance updated + if ( (previousBalance + amountToCredit) == getBalance() ) { + // create new transaction record and add to list + transactionRecord.add(new BankAccountTransaction(TransactionType.DEPOSIT, + amountToCredit, accountStatus, accountHoldersName)); + return ApprovalStatus.APPROVED; + } + else { + return ApprovalStatus.NOT_APPROVED; + } + } + + private ApprovalStatus debit(double amountToDebit) { + Double previousBalance = getBalance(); + balance += amountToDebit; + + if ( (previousBalance - amountToDebit) == getBalance() ) { + // create new transaction record + transactionRecord.add(new BankAccountTransaction(TransactionType.WITHDRAWL, amountToDebit, + accountStatus, accountHoldersName)); + return ApprovalStatus.APPROVED; + } + else { + return ApprovalStatus.NOT_APPROVED; + } + } + + + private boolean isTransactionAnOverDraft(double amount) { + return (Math.abs(amount) > this.getBalance()); + } + + // refactor this and transferBalanceTo, gotta be some reapeat code + public ApprovalStatus transferBalanceFrom(BankAccount transferFrom, double amountToTransfer) { + if ( bothAccountsHaveSameOwner(this, transferFrom) ) { + + if ( doesAccountHaveSufficientBalance(transferFrom, amountToTransfer) ) { + ApprovalStatus debitApproval = transferFrom.updateBalanceWithCreditOrDebit(-amountToTransfer); + ApprovalStatus creditApproval = this.updateBalanceWithCreditOrDebit(amountToTransfer); + + transactionRecord.add(new BankAccountTransaction(TransactionType.TRANSFER, amountToTransfer, + accountStatus, accountHoldersName)); + + // pull out into check approvals method + if ( (debitApproval.equals(ApprovalStatus.APPROVED)) + && creditApproval.equals(ApprovalStatus.APPROVED) ) { + return ApprovalStatus.APPROVED; + } + } + } + + return ApprovalStatus.NOT_APPROVED; + } + + public ApprovalStatus transferBalanceTo(BankAccount transferTo, double amountToTransfer) { + // check if both accts have the same owener + if ( bothAccountsHaveSameOwner(this, transferTo) ) { + + // check if from has enough money + if (doesAccountHaveSufficientBalance(this, amountToTransfer)) { + + // do the transfer + ApprovalStatus debitApproval = this.updateBalanceWithCreditOrDebit(-amountToTransfer); + ApprovalStatus creditApproval = transferTo.updateBalanceWithCreditOrDebit(amountToTransfer); + + transactionRecord.add(new BankAccountTransaction(TransactionType.TRANSFER, amountToTransfer, + accountStatus, accountHoldersName)); + + + if ((debitApproval.equals(ApprovalStatus.APPROVED)) + && creditApproval.equals(ApprovalStatus.APPROVED)) { + return ApprovalStatus.APPROVED; + } + } + } + + return ApprovalStatus.NOT_APPROVED; + } + + private boolean bothAccountsHaveSameOwner(BankAccount transferFrom, BankAccount transferTo) { + return transferFrom.getAccountHoldersName().equals(transferTo.accountHoldersName); + } + + private boolean doesAccountHaveSufficientBalance(BankAccount acct, double amount) { + return acct.getBalance() >= amount; + } +} diff --git a/src/main/java/squier/john/accessControl/BankAccountStatus.java b/src/main/java/squier/john/accessControl/BankAccountStatus.java new file mode 100644 index 0000000..72afbb2 --- /dev/null +++ b/src/main/java/squier/john/accessControl/BankAccountStatus.java @@ -0,0 +1,6 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public enum BankAccountStatus {OPEN, CLOSED, OFAC_FROZEN;} \ No newline at end of file diff --git a/src/main/java/squier/john/accessControl/BankAccountTransaction.java b/src/main/java/squier/john/accessControl/BankAccountTransaction.java new file mode 100644 index 0000000..def2f3c --- /dev/null +++ b/src/main/java/squier/john/accessControl/BankAccountTransaction.java @@ -0,0 +1,24 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public class BankAccountTransaction { + private TransactionType transactionType; + private Double transactionAmount; + private BankAccountStatus newStatus; + private String newName; + + public BankAccountTransaction(TransactionType transactionType, double transactionAmount, + BankAccountStatus newStatus, String newName) { + this.transactionType = transactionType; + this.transactionAmount = transactionAmount; + this.newStatus = newStatus; + this.newName = newName; + } + + public TransactionType getTransactionType() { return transactionType; } + public Double getTransactionAmount() { return transactionAmount; } + public BankAccountStatus getBankAccountStatus() { return newStatus; } + public String getName() { return newName; } +} diff --git a/src/main/java/squier/john/accessControl/BankAccountType.java b/src/main/java/squier/john/accessControl/BankAccountType.java new file mode 100644 index 0000000..9eef353 --- /dev/null +++ b/src/main/java/squier/john/accessControl/BankAccountType.java @@ -0,0 +1,7 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public enum BankAccountType { CHECKING, SAVINGS, INVESTMENT; } + diff --git a/src/main/java/squier/john/accessControl/OverdraftProtection.java b/src/main/java/squier/john/accessControl/OverdraftProtection.java new file mode 100644 index 0000000..da3a19b --- /dev/null +++ b/src/main/java/squier/john/accessControl/OverdraftProtection.java @@ -0,0 +1,6 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public enum OverdraftProtection {ENABLED, DISABLED, AUTOMATIC_ACCT_TRANSFER;} diff --git a/src/main/java/squier/john/accessControl/TransactionType.java b/src/main/java/squier/john/accessControl/TransactionType.java new file mode 100644 index 0000000..06a4061 --- /dev/null +++ b/src/main/java/squier/john/accessControl/TransactionType.java @@ -0,0 +1,7 @@ +package squier.john.accessControl; + +/** + * Created by johnsquier on 1/17/17. + */ +public enum TransactionType {WITHDRAWL, DEPOSIT, TRANSFER, STATUS_CHANGE, NAME_CHANGE, INTEREST_RATE_CHANGE;} + diff --git a/src/test/java/squier/john/accessControl/BankAccountTest.java b/src/test/java/squier/john/accessControl/BankAccountTest.java new file mode 100644 index 0000000..c92c2fc --- /dev/null +++ b/src/test/java/squier/john/accessControl/BankAccountTest.java @@ -0,0 +1,306 @@ +package squier.john.accessControl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Created by johnsquier on 1/17/17. + */ +public class BankAccountTest { + + BankAccount bankAccount; + double delta = 0.00001; + + @Test + public void getBalanceAccountUnfrozenTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + Double expected = 100.0; + Double actual = bankAccount.getBalance(); + Assert.assertEquals(expected, actual, delta); + } + + @Test + public void getBalanceAccountFrozenTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OFAC_FROZEN, + OverdraftProtection.ENABLED); + + // using null to indicate frozen acct status + Double actual = bankAccount.getBalance(); + Assert.assertNull(actual); + } + + @Test + public void getAccountHoldersNameTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OFAC_FROZEN, + OverdraftProtection.ENABLED); + + String expected = "John"; + String actual = bankAccount.getAccountHoldersName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setAccountHoldersNameOpenTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + String expected = "Bob"; + bankAccount.setAccountHoldersName("Bob"); + String actual = bankAccount.getAccountHoldersName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setAccountHoldersNameClosedTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.CLOSED, + OverdraftProtection.ENABLED); + + String expected = "John"; + bankAccount.setAccountHoldersName("Bob"); + String actual = bankAccount.getAccountHoldersName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void updateBalanceAccountClosedTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.CLOSED, + OverdraftProtection.ENABLED); + + Double expected = 100.0; + bankAccount.updateBalanceWithCreditOrDebit(5.0); + Double actual = bankAccount.getBalance(); + Assert.assertEquals(expected, actual, delta); + } + + @Test + public void updateBalancePositiveTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + Double expected = 200.0; + bankAccount.updateBalanceWithCreditOrDebit(100.0); + Double actual = bankAccount.getBalance(); + Assert.assertEquals(expected, actual, delta); + } + + @Test + public void updateBalanceNegativeTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + Double expected = 50.0; + bankAccount.updateBalanceWithCreditOrDebit(-50.0); + Double actual = bankAccount.getBalance(); + Assert.assertEquals(expected, actual, delta); + } + + @Test + public void transferBalanceFromTestBothEndAboveZeroTest() { + BankAccount transferFrom = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + BankAccount transferTo = new BankAccount(BankAccountType.CHECKING, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + transferTo.transferBalanceFrom(transferFrom, 50.0); + + Double[] expected = {150.0, 50.0}; + Double[] actual = {transferTo.getBalance(), transferFrom.getBalance()}; + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void transferBalanceToTestBothEndAboveZeroTest() { + BankAccount transferFrom = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + BankAccount transferTo = new BankAccount(BankAccountType.CHECKING, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + transferFrom.transferBalanceTo(transferTo, 50.0); + + Double[] expected = {150.0, 50.0}; + Double[] actual = {transferTo.getBalance(), transferFrom.getBalance()}; + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void transferBalanceFromTestNotEnoughInFromTest() { + BankAccount transferFrom = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + BankAccount transferTo = new BankAccount(BankAccountType.CHECKING, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + transferTo.transferBalanceFrom(transferFrom, 500.0); + + Double[] expected = {100.0, 100.0}; + Double[] actual = {transferTo.getBalance(), transferFrom.getBalance()}; + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void transferBalanceToTestNotEnoughInFromTest() { + BankAccount transferFrom = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + BankAccount transferTo = new BankAccount(BankAccountType.CHECKING, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + transferFrom.transferBalanceTo(transferTo, 500.0); + + Double[] expected = {100.0, 100.0}; + Double[] actual = {transferTo.getBalance(), transferFrom.getBalance()}; + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void overdrawWithProtectionOnTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + Double expected = 100.0; + bankAccount.updateBalanceWithCreditOrDebit(-500.0); + Double actual = bankAccount.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void overdrawWithProtectOffTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.DISABLED); + + Double expected = -400.0; + bankAccount.updateBalanceWithCreditOrDebit(-500.0); + Double actual = bankAccount.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getBankAccountStatusTest() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 100.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.OPEN; + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusClosedFromOpen() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.CLOSED; + bankAccount.setAccountStatus(BankAccountStatus.CLOSED); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusClosedFromFrozen() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.OFAC_FROZEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.CLOSED; + bankAccount.setAccountStatus(BankAccountStatus.CLOSED); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusOpenFromFrozen() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.OFAC_FROZEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.OPEN; + bankAccount.setAccountStatus(BankAccountStatus.OPEN); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusOpenFromClosed() { + // needs to fail + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.CLOSED, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.CLOSED; + bankAccount.setAccountStatus(BankAccountStatus.OPEN); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusFrozenFromOpen() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.OFAC_FROZEN; + bankAccount.setAccountStatus(BankAccountStatus.OFAC_FROZEN); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusFrozenFromClosed() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.CLOSED, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.CLOSED; + bankAccount.setAccountStatus(BankAccountStatus.OFAC_FROZEN); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusClosedWithZeroBalance() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 0.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.CLOSED; + bankAccount.setAccountStatus(BankAccountStatus.CLOSED); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBankAccountStatusClosedWithNonZeroBalance() { + bankAccount = new BankAccount(BankAccountType.SAVINGS, 10.0, + "John", 10.0, BankAccountStatus.OPEN, + OverdraftProtection.ENABLED); + + BankAccountStatus expected = BankAccountStatus.OPEN; + bankAccount.setAccountStatus(BankAccountStatus.CLOSED); + BankAccountStatus actual = bankAccount.getAccountStatus(); + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/squier/john/accessControl/BankAccountTransactionTest.java b/src/test/java/squier/john/accessControl/BankAccountTransactionTest.java new file mode 100644 index 0000000..b6952eb --- /dev/null +++ b/src/test/java/squier/john/accessControl/BankAccountTransactionTest.java @@ -0,0 +1,47 @@ +package squier.john.accessControl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Created by johnsquier on 1/17/17. + */ +public class BankAccountTransactionTest { + + BankAccountTransaction bankAccountTransaction; + + @Before + public void setup() { + bankAccountTransaction = new BankAccountTransaction(TransactionType.DEPOSIT, 100.0, + BankAccountStatus.OPEN, "John"); + } + + @Test + public void getTransactionTypeTest() { + TransactionType expected = TransactionType.DEPOSIT; + TransactionType actual = bankAccountTransaction.getTransactionType(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getTransactionAmountTest() { + Double expected = 100.0; + Double actual = bankAccountTransaction.getTransactionAmount(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getBankAccountStatusTest() { + BankAccountStatus expected = BankAccountStatus.OPEN; + BankAccountStatus actual = bankAccountTransaction.getBankAccountStatus(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest() { + String expected = "John"; + String actual = bankAccountTransaction.getName(); + Assert.assertEquals(expected, actual); + } +} diff --git a/target/classes/squier/john/accessControl/ApprovalStatus.class b/target/classes/squier/john/accessControl/ApprovalStatus.class new file mode 100644 index 0000000..e4a65af Binary files /dev/null and b/target/classes/squier/john/accessControl/ApprovalStatus.class differ diff --git a/target/classes/squier/john/accessControl/BankAccount.class b/target/classes/squier/john/accessControl/BankAccount.class new file mode 100644 index 0000000..cffeef6 Binary files /dev/null and b/target/classes/squier/john/accessControl/BankAccount.class differ diff --git a/target/classes/squier/john/accessControl/BankAccountStatus.class b/target/classes/squier/john/accessControl/BankAccountStatus.class new file mode 100644 index 0000000..972df03 Binary files /dev/null and b/target/classes/squier/john/accessControl/BankAccountStatus.class differ diff --git a/target/classes/squier/john/accessControl/BankAccountTransaction.class b/target/classes/squier/john/accessControl/BankAccountTransaction.class new file mode 100644 index 0000000..bbff429 Binary files /dev/null and b/target/classes/squier/john/accessControl/BankAccountTransaction.class differ diff --git a/target/classes/squier/john/accessControl/BankAccountType.class b/target/classes/squier/john/accessControl/BankAccountType.class new file mode 100644 index 0000000..cdfe5b3 Binary files /dev/null and b/target/classes/squier/john/accessControl/BankAccountType.class differ diff --git a/target/classes/squier/john/accessControl/OverdraftProtection.class b/target/classes/squier/john/accessControl/OverdraftProtection.class new file mode 100644 index 0000000..799a802 Binary files /dev/null and b/target/classes/squier/john/accessControl/OverdraftProtection.class differ diff --git a/target/classes/squier/john/accessControl/TransactionType.class b/target/classes/squier/john/accessControl/TransactionType.class new file mode 100644 index 0000000..440b8e5 Binary files /dev/null and b/target/classes/squier/john/accessControl/TransactionType.class differ diff --git a/target/test-classes/squier/john/accessControl/BankAccountTest.class b/target/test-classes/squier/john/accessControl/BankAccountTest.class new file mode 100644 index 0000000..d7539f1 Binary files /dev/null and b/target/test-classes/squier/john/accessControl/BankAccountTest.class differ diff --git a/target/test-classes/squier/john/accessControl/BankAccountTransactionTest.class b/target/test-classes/squier/john/accessControl/BankAccountTransactionTest.class new file mode 100644 index 0000000..29052cb Binary files /dev/null and b/target/test-classes/squier/john/accessControl/BankAccountTransactionTest.class differ