From 21c78f1d2646365ae447a7b948f835959550bb2b Mon Sep 17 00:00:00 2001 From: eostendarp Date: Wed, 29 Jan 2020 20:46:57 -0500 Subject: [PATCH 01/86] update isEmailValidTest --- .idea/misc.xml | 2 +- .../ithaca/dragon/bank/BankAccountTest.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 750d1d0b..50a7f10e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index df0150db..0b89e522 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -24,8 +24,26 @@ void withdrawTest() throws InsufficientFundsException{ @Test void isEmailValidTest(){ - assertTrue(BankAccount.isEmailValid( "a@b.com")); + assertTrue(BankAccount.isEmailValid("a@b.com")); assertFalse( BankAccount.isEmailValid("")); + + assertFalse(BankAccount.isEmailValid("abc-@mail.com")); + assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); + assertFalse(BankAccount.isEmailValid("abc..def@mail.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + assertFalse(BankAccount.isEmailValid(".abc@mail.com")); + assertTrue(BankAccount.isEmailValid("abc@mail.com")); + assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); + + assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); + assertFalse(BankAccount.isEmailValid("abc.def@mail")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); + assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); } @Test From 7fce7073911be97439cef928c952374ff452354f Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 09:28:53 -0500 Subject: [PATCH 02/86] update withdraw documentation and withdrawTest --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 6 ++++-- src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 8e35fb64..dfab1d3a 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -27,7 +27,10 @@ public String getEmail(){ } /** - * @post reduces the balance by amount if amount is non-negative and smaller than balance + * reduces the balance by amount if amount is non-negative and smaller than balance + * @param amount quantity to reduce balance by + * @throws IllegalArgumentException if amount is negative + * @throws InsufficientFundsException if amount is larger than balance */ public void withdraw (double amount) throws InsufficientFundsException{ if (amount <= balance){ @@ -38,7 +41,6 @@ public void withdraw (double amount) throws InsufficientFundsException{ } } - public static boolean isEmailValid(String email){ if (email.indexOf('@') == -1){ return false; diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 0b89e522..4df66cc3 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -20,6 +20,8 @@ void withdrawTest() throws InsufficientFundsException{ assertEquals(100, bankAccount.getBalance()); assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); + + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100)); } @Test From 10f73682cba841964ad3dc1679b18fa3d1bf99bf Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 09:45:58 -0500 Subject: [PATCH 03/86] implemented withdraw and isEmailVaild --- .../edu/ithaca/dragon/bank/BankAccount.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index dfab1d3a..c7f3f2e7 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,5 +1,7 @@ package edu.ithaca.dragon.bank; +import java.util.regex.Pattern; + public class BankAccount { private String email; @@ -33,20 +35,17 @@ public String getEmail(){ * @throws InsufficientFundsException if amount is larger than balance */ public void withdraw (double amount) throws InsufficientFundsException{ - if (amount <= balance){ - balance -= amount; - } - else { + if (amount < 0) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot create account"); + } else if (amount > balance) { throw new InsufficientFundsException("Not enough money"); + } else { + balance -= amount; } } - public static boolean isEmailValid(String email){ - if (email.indexOf('@') == -1){ - return false; - } - else { - return true; - } + public static boolean isEmailValid(String email) { + String regex = "[\\w-]+(\\.[\\w]+)*(? Date: Thu, 30 Jan 2020 10:02:55 -0500 Subject: [PATCH 04/86] add withdrawTest and isEmailValidTest comments --- .../edu/ithaca/dragon/bank/BankAccount.java | 2 +- .../ithaca/dragon/bank/BankAccountTest.java | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index c7f3f2e7..d75ac8f5 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -29,7 +29,7 @@ public String getEmail(){ } /** - * reduces the balance by amount if amount is non-negative and smaller than balance + * reduces the balance by amount if amount is non-negative and smaller or equal to balance * @param amount quantity to reduce balance by * @throws IllegalArgumentException if amount is negative * @throws InsufficientFundsException if amount is larger than balance diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 4df66cc3..3539e137 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -14,37 +14,57 @@ void getBalanceTest() { } @Test - void withdrawTest() throws InsufficientFundsException{ + void withdrawTest() throws InsufficientFundsException { BankAccount bankAccount = new BankAccount("a@b.com", 200); - bankAccount.withdraw(100); + //non-negative amount less than or equal to balance + bankAccount.withdraw(100); assertEquals(100, bankAccount.getBalance()); - assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); + //non-negative amount greater than balance + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); + //negative amount assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100)); } @Test - void isEmailValidTest(){ + void isEmailValidTest() { + //valid prefix and domain assertTrue(BankAccount.isEmailValid("a@b.com")); - assertFalse( BankAccount.isEmailValid("")); + //missing prefix and/or domain + assertFalse(BankAccount.isEmailValid("")); + //prefix with underscore, period, or dash not followed by one or more letter or number assertFalse(BankAccount.isEmailValid("abc-@mail.com")); + //prefix with underscore, period, or dash followed by one or more letter or number assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); + //prefix with underscore, period, or dash not followed by one or more letter or number assertFalse(BankAccount.isEmailValid("abc..def@mail.com")); + //prefix with underscore, period, or dash followed by one or more letter or number assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + //prefix with underscore, period, or dash not preceded by one or more letter or number assertFalse(BankAccount.isEmailValid(".abc@mail.com")); + //valid prefix and domain assertTrue(BankAccount.isEmailValid("abc@mail.com")); + //prefix with invalid character assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + //prefix with underscore, period, or dash followed by one or more letter or number assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); - + //last portion of the domain without at least two characters assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); + //last portion of the domain with at least two characters assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); + //domain with invalid character assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + //domain with period or dash followed by one or more letter or number assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); + //last portion of the domain without at least two characters assertFalse(BankAccount.isEmailValid("abc.def@mail")); + //last portion of the domain with at least two characters assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); + //domain with period or dash not followed by one or more letter or number assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); + //prefix with underscore, period, or dash followed by one or more letter or number assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); } From 7d8d1fb24c29e7004babb6d26bccb0faadeae7e1 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 10:16:05 -0500 Subject: [PATCH 05/86] improve withdrawTest --- .../java/edu/ithaca/dragon/bank/BankAccountTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 3539e137..0ab2787f 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -21,10 +21,22 @@ void withdrawTest() throws InsufficientFundsException { bankAccount.withdraw(100); assertEquals(100, bankAccount.getBalance()); + //non-negative amount less than or equal to balance + bankAccount.withdraw(0); + assertEquals(100, bankAccount.getBalance()); + + //non-negative amount greater than balance + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(101)); + //non-negative amount greater than balance assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); + //negative amount assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100)); + + //non-negative amount less than or equal to balance + bankAccount.withdraw(100); + assertEquals(0, bankAccount.getBalance()); } @Test From 97de2b5fd6f7b68fb55b009f0c33e709355c9b7a Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 10:20:26 -0500 Subject: [PATCH 06/86] update getBalanceTest --- .../java/edu/ithaca/dragon/bank/BankAccountTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 0ab2787f..f5834201 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -8,9 +8,17 @@ class BankAccountTest { @Test void getBalanceTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); + //negative balance + BankAccount bankAccount = new BankAccount("a@b.com", -200); + assertEquals(-200, bankAccount.getBalance()); - assertEquals(200, bankAccount.getBalance()); + //non-negative balance + bankAccount = new BankAccount("a@b.com", 0); + assertEquals(0, bankAccount.getBalance()); + + //non-negative balance + bankAccount = new BankAccount("a@b.com", 100); + assertEquals(100, bankAccount.getBalance()); } @Test From 0e6499ff6610a6b5b98db1705817b96a21ff2b7f Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 12:43:55 -0500 Subject: [PATCH 07/86] added isAmountValid header and isAmountValidTest --- .../edu/ithaca/dragon/bank/BankAccount.java | 9 ++++++ .../ithaca/dragon/bank/BankAccountTest.java | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index d75ac8f5..497ed843 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -48,4 +48,13 @@ public static boolean isEmailValid(String email) { String regex = "[\\w-]+(\\.[\\w]+)*(? Date: Thu, 30 Jan 2020 13:13:18 -0500 Subject: [PATCH 08/86] implemented isAmountValid and fixed incorrect test --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 5 ++++- src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 497ed843..439fb56f 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,5 +1,6 @@ package edu.ithaca.dragon.bank; +import java.math.BigDecimal; import java.util.regex.Pattern; public class BankAccount { @@ -55,6 +56,8 @@ public static boolean isEmailValid(String email) { * @return true if the amount is non-negative and has two decimal points or less, and false otherwise */ public static boolean isAmountValid(double amount) { - return false; + String amountStr = String.valueOf(amount); + int charsAfterDec = amountStr.length() - amountStr.indexOf('.') - 1; + return amount >= 0 && charsAfterDec <= 2; } } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 31e9fcfd..5ceeac39 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -100,7 +100,7 @@ void isAmountValidTest() { //non-negative amount with more than two decimal points assertFalse(BankAccount.isAmountValid(0.001)); assertFalse(BankAccount.isAmountValid(0.9999)); - assertFalse(BankAccount.isAmountValid(536)); + assertFalse(BankAccount.isAmountValid(536.125)); assertFalse(BankAccount.isAmountValid(Double.MIN_VALUE)); assertFalse(BankAccount.isAmountValid(Double.MAX_VALUE)); From f9825cf2c416c4cb1521e4a15395102130e3046a Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 21:50:21 -0500 Subject: [PATCH 09/86] updated withdrawTest and constructorTest --- .../ithaca/dragon/bank/BankAccountTest.java | 100 ++++++++++++++---- 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 5ceeac39..f96fcc3f 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -6,6 +6,8 @@ class BankAccountTest { + private static final double THRESHOLD = .001; + @Test void getBalanceTest() { //negative balance @@ -23,28 +25,49 @@ void getBalanceTest() { @Test void withdrawTest() throws InsufficientFundsException { - BankAccount bankAccount = new BankAccount("a@b.com", 200); - - //non-negative amount less than or equal to balance - bankAccount.withdraw(100); - assertEquals(100, bankAccount.getBalance()); - - //non-negative amount less than or equal to balance + BankAccount bankAccount = new BankAccount("a@b.com", 1000); + + //non-negative amount less than or equal to balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(3141.592)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(Double.MIN_VALUE)); + + //non-negative amount greater than balance with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(5432)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(3216.8)); + + //non-negative amount greater than balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(9876.543)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-2718.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-14850.607)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MAX_VALUE)); + + //non-negative amount less than or equal to balance with two decimal places or less bankAccount.withdraw(0); - assertEquals(100, bankAccount.getBalance()); - - //non-negative amount greater than balance - assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(101)); - - //non-negative amount greater than balance - assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); - - //negative amount - assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100)); - - //non-negative amount less than or equal to balance + assertEquals(1000, bankAccount.getBalance(), THRESHOLD); bankAccount.withdraw(100); - assertEquals(0, bankAccount.getBalance()); + assertEquals(900, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(0.01); + assertEquals(899.99, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(0.99); + assertEquals(899, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(898.99); + assertEquals(0.01, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(0.01); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); } @Test @@ -108,7 +131,7 @@ void isAmountValidTest() { assertFalse(BankAccount.isAmountValid(-0.01)); assertFalse(BankAccount.isAmountValid(-0.99)); assertFalse(BankAccount.isAmountValid(-120)); - assertFalse(BankAccount.isAmountValid(-946.50)); + assertFalse(BankAccount.isAmountValid(-946.5)); //negative amount with more than two decimal points assertFalse(BankAccount.isAmountValid(-0.001)); @@ -124,7 +147,40 @@ void constructorTest() { assertEquals("a@b.com", bankAccount.getEmail()); assertEquals(200, bankAccount.getBalance()); //check for exception thrown correctly - assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("", 100)); + + //non-negative balance with two decimal places or less + bankAccount = new BankAccount("a@b.com", 0); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + bankAccount = new BankAccount("a@b.com", 0.01); + assertEquals(0.01, bankAccount.getBalance(), THRESHOLD); + bankAccount = new BankAccount("a@b.com", 0.99); + assertEquals(0.99, bankAccount.getBalance(), THRESHOLD); + bankAccount = new BankAccount("a@b.com", 9876.5); + assertEquals(9876.5, bankAccount.getBalance(), THRESHOLD); + bankAccount = new BankAccount("a@b.com", 248); + assertEquals(248, bankAccount.getBalance(), THRESHOLD); + + //non-negative balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", 0.001)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", 0.9999)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", 369.333)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", Double.MIN_VALUE)); + + //negative balance with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -0.01)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -0.99)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -10.2)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -125)); + + //negative balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -0.001)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -0.9999)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -369.333)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -Double.MIN_VALUE)); + } } \ No newline at end of file From 62991c1e2720961e5d9a94790d656f6d4b6e3515 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 22:10:34 -0500 Subject: [PATCH 10/86] updated comstructor and withdraw to use isValidAmount and fixed incorrect tests --- .../edu/ithaca/dragon/bank/BankAccount.java | 19 +++++++++-------- .../ithaca/dragon/bank/BankAccountTest.java | 21 +++++++------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 439fb56f..02c4665b 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -9,16 +9,17 @@ public class BankAccount { private double balance; /** - * @throws IllegalArgumentException if email is invalid + * @throws IllegalArgumentException if email or startingBalance is invalid */ - public BankAccount(String email, double startingBalance){ - if (isEmailValid(email)){ + public BankAccount(String email, double startingBalance) { + if (!isEmailValid(email)) { + throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); + } else if (!isAmountValid(startingBalance)) { + throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); + } else { this.email = email; this.balance = startingBalance; } - else { - throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); - } } public double getBalance(){ @@ -35,9 +36,9 @@ public String getEmail(){ * @throws IllegalArgumentException if amount is negative * @throws InsufficientFundsException if amount is larger than balance */ - public void withdraw (double amount) throws InsufficientFundsException{ - if (amount < 0) { - throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot create account"); + public void withdraw (double amount) throws InsufficientFundsException { + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot withdraw"); } else if (amount > balance) { throw new InsufficientFundsException("Not enough money"); } else { diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index f96fcc3f..0051c883 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -6,16 +6,15 @@ class BankAccountTest { - private static final double THRESHOLD = .001; + private static final double THRESHOLD = 0.001; @Test void getBalanceTest() { //negative balance - BankAccount bankAccount = new BankAccount("a@b.com", -200); - assertEquals(-200, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -200)); //non-negative balance - bankAccount = new BankAccount("a@b.com", 0); + BankAccount bankAccount = new BankAccount("a@b.com", 0); assertEquals(0, bankAccount.getBalance()); //non-negative balance @@ -34,9 +33,9 @@ void withdrawTest() throws InsufficientFundsException { assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(Double.MIN_VALUE)); //non-negative amount greater than balance with two decimal places or less - assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.01)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(5432)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(3216.8)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(1000.01)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(5432)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(3216.8)); //non-negative amount greater than balance with more than two decimal places assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.001)); @@ -62,11 +61,9 @@ void withdrawTest() throws InsufficientFundsException { assertEquals(900, bankAccount.getBalance(), THRESHOLD); bankAccount.withdraw(0.01); assertEquals(899.99, bankAccount.getBalance(), THRESHOLD); - bankAccount.withdraw(0.99); - assertEquals(899, bankAccount.getBalance(), THRESHOLD); bankAccount.withdraw(898.99); - assertEquals(0.01, bankAccount.getBalance(), THRESHOLD); - bankAccount.withdraw(0.01); + assertEquals(1, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(1); assertEquals(0, bankAccount.getBalance(), THRESHOLD); } @@ -180,7 +177,5 @@ void constructorTest() { assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -369.333)); assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -Double.MAX_VALUE)); assertThrows(IllegalArgumentException.class, () -> new BankAccount("a@b.com", -Double.MIN_VALUE)); - } - } \ No newline at end of file From 3026fe6b805e2441d146e5297ba399969ba1c313 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 22:27:55 -0500 Subject: [PATCH 11/86] add deposit method header and comments and depositTest --- .../edu/ithaca/dragon/bank/BankAccount.java | 17 ++++++--- .../ithaca/dragon/bank/BankAccountTest.java | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 02c4665b..c8440ae0 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -9,7 +9,7 @@ public class BankAccount { private double balance; /** - * @throws IllegalArgumentException if email or startingBalance is invalid + * @throws IllegalArgumentException if email is invalid, or startingBalance is negative or has more than 2 decimal places */ public BankAccount(String email, double startingBalance) { if (!isEmailValid(email)) { @@ -31,12 +31,12 @@ public String getEmail(){ } /** - * reduces the balance by amount if amount is non-negative and smaller or equal to balance + * reduces the balance by amount if amount is non-negative, has 2 or fewer decimals and is smaller or equal to balance * @param amount quantity to reduce balance by - * @throws IllegalArgumentException if amount is negative + * @throws IllegalArgumentException if amount is negative or has more than 2 decimals * @throws InsufficientFundsException if amount is larger than balance */ - public void withdraw (double amount) throws InsufficientFundsException { + public void withdraw(double amount) throws InsufficientFundsException { if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot withdraw"); } else if (amount > balance) { @@ -46,6 +46,15 @@ public void withdraw (double amount) throws InsufficientFundsException { } } + /** + * increases the balance by amount if non-negative and has 2 or fewer decimals + * @param amount quantity to increase balance by + * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places + */ + public void depost(double amount) { + //TODO + } + public static boolean isEmailValid(String email) { String regex = "[\\w-]+(\\.[\\w]+)*(? bankAccount.depost(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(1010.101)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-8008.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-5000.125)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-Double.MAX_VALUE)); + + //non-negative amount with two decimal places or less + bankAccount.depost(0); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + bankAccount.depost(10); + assertEquals(10, bankAccount.getBalance(), THRESHOLD); + bankAccount.depost(0.01); + assertEquals(10.01, bankAccount.getBalance(), THRESHOLD); + bankAccount.depost(0.99); + assertEquals(11, bankAccount.getBalance(), THRESHOLD); + bankAccount.depost(419.5); + assertEquals(430.5, bankAccount.getBalance(), THRESHOLD); + } + @Test void isEmailValidTest() { //valid prefix and domain From 0927996f905b1e0d7a29f01e3fcaa8c49236d03e Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 22:29:22 -0500 Subject: [PATCH 12/86] added deposit implementation --- .../edu/ithaca/dragon/bank/BankAccount.java | 8 +++-- .../ithaca/dragon/bank/BankAccountTest.java | 36 +++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index c8440ae0..12cddd0e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -51,8 +51,12 @@ public void withdraw(double amount) throws InsufficientFundsException { * @param amount quantity to increase balance by * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places */ - public void depost(double amount) { - //TODO + public void deposit(double amount) { + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot deposit"); + } else { + balance += amount; + } } public static boolean isEmailValid(String email) { diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 548f6967..4c8bb343 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -72,34 +72,34 @@ void depositTest() { BankAccount bankAccount = new BankAccount("a@b.com", 0); //non-negative amount with more than two decimal places - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(0.001)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(0.9999)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(1010.101)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(Double.MIN_VALUE)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(1010.101)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MAX_VALUE)); //negative amount with two decimal places or less - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.01)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.99)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-8008.2)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-8008.2)); //negative amount with more than two decimal places - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.001)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-0.9999)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-5000.125)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-Double.MIN_VALUE)); - assertThrows(IllegalArgumentException.class, () -> bankAccount.depost(-Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-5000.125)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MAX_VALUE)); //non-negative amount with two decimal places or less - bankAccount.depost(0); + bankAccount.deposit(0); assertEquals(0, bankAccount.getBalance(), THRESHOLD); - bankAccount.depost(10); + bankAccount.deposit(10); assertEquals(10, bankAccount.getBalance(), THRESHOLD); - bankAccount.depost(0.01); + bankAccount.deposit(0.01); assertEquals(10.01, bankAccount.getBalance(), THRESHOLD); - bankAccount.depost(0.99); + bankAccount.deposit(0.99); assertEquals(11, bankAccount.getBalance(), THRESHOLD); - bankAccount.depost(419.5); + bankAccount.deposit(419.5); assertEquals(430.5, bankAccount.getBalance(), THRESHOLD); } From f16a70d4be35b487d4f8b9bd6c271f2a5ce4d19b Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 23:28:49 -0500 Subject: [PATCH 13/86] add transfer method header and comments, and transferTest --- .../edu/ithaca/dragon/bank/BankAccount.java | 11 ++++ .../ithaca/dragon/bank/BankAccountTest.java | 50 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 12cddd0e..ae0b2dcd 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -59,6 +59,17 @@ public void deposit(double amount) { } } + /** + * withdraws amount from balance and deposits it into to's balance + * @param to BankAccount who's balance will be deposited into + * @param amount quantity to withdraw from balance and deposit into to's balance + * @throws IllegalArgumentException if amount is negative or has more than 2 decimals + * @throws InsufficientFundsException if amount is larger than balance + */ + public void transfer(BankAccount to, double amount) throws InsufficientFundsException { + + } + public static boolean isEmailValid(String email) { String regex = "[\\w-]+(\\.[\\w]+)*(? a.transfer(b, 0.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 0.9999)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 999.999)); + + //non-negative amount greater than balance with two decimal places or less + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 1000.01)); + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 2500.5)); + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 1357)); + + //non-negative amount greater than balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 1000.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 6666.6666)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.01)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.99)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -607.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.9999)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -9876.54321)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -Double.MAX_VALUE)); + + //non-negative amount less than or equal to balance with two decimal places or less + a.transfer(b, 0); + assertEquals(1000, a.getBalance(), THRESHOLD); + assertEquals(0, b.getBalance(), THRESHOLD); + a.transfer(b, 0.01); + assertEquals(999.99, a.getBalance(), THRESHOLD); + assertEquals(0.01, b.getBalance(), THRESHOLD); + a.transfer(b, 500); + assertEquals(499.99, a.getBalance(), THRESHOLD); + assertEquals(500.01, b.getBalance(), THRESHOLD); + a.transfer(b, 499.98); + assertEquals(.01, a.getBalance(), THRESHOLD); + assertEquals(999.99, b.getBalance(), THRESHOLD); + a.transfer(b, .01); + assertEquals(0, a.getBalance(), THRESHOLD); + assertEquals(1000, b.getBalance(), THRESHOLD); + } + @Test void isEmailValidTest() { //valid prefix and domain From 932dd01bdbd5462de00be47724d039bcac0cdbfb Mon Sep 17 00:00:00 2001 From: eostendarp Date: Thu, 30 Jan 2020 23:49:05 -0500 Subject: [PATCH 14/86] implemented transfer and fixed incorrect tests --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 9 ++++++++- .../java/edu/ithaca/dragon/bank/BankAccountTest.java | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index ae0b2dcd..edd82d30 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -67,7 +67,14 @@ public void deposit(double amount) { * @throws InsufficientFundsException if amount is larger than balance */ public void transfer(BankAccount to, double amount) throws InsufficientFundsException { - + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot transfer"); + } else if (amount > balance) { + throw new InsufficientFundsException("Not enough money"); + } else { + withdraw(amount); + to.deposit(amount); + } } public static boolean isEmailValid(String email) { diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 5a13afb9..c95b85e6 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -145,10 +145,10 @@ void transferTest() throws InsufficientFundsException { a.transfer(b, 500); assertEquals(499.99, a.getBalance(), THRESHOLD); assertEquals(500.01, b.getBalance(), THRESHOLD); - a.transfer(b, 499.98); - assertEquals(.01, a.getBalance(), THRESHOLD); - assertEquals(999.99, b.getBalance(), THRESHOLD); - a.transfer(b, .01); + a.transfer(b, 498.99); + assertEquals(1, a.getBalance(), THRESHOLD); + assertEquals(999, b.getBalance(), THRESHOLD); + a.transfer(b, 1); assertEquals(0, a.getBalance(), THRESHOLD); assertEquals(1000, b.getBalance(), THRESHOLD); } From 27cc5137ebabf482829d37dfc93fe326aa1933ef Mon Sep 17 00:00:00 2001 From: eostendarp Date: Mon, 3 Feb 2020 14:46:19 -0500 Subject: [PATCH 15/86] added bank interface java files --- .../java/edu/ithaca/dragon/bank/AdminAPI.java | 15 +++++ .../edu/ithaca/dragon/bank/AdvancedAPI.java | 9 +++ .../java/edu/ithaca/dragon/bank/BasicAPI.java | 18 ++++++ .../edu/ithaca/dragon/bank/CentralBank.java | 63 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 src/main/java/edu/ithaca/dragon/bank/AdminAPI.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/BasicAPI.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/CentralBank.java 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..26253541 --- /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(String acctId, double startingBalance); + + public void closeAccount(String acctId); +} 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..bd65b941 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java @@ -0,0 +1,18 @@ +package edu.ithaca.dragon.bank; + +//API to be used by ATMs +public interface BasicAPI { + + boolean confirmCredentials(String acctId, 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; + + String 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..37508848 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -0,0 +1,63 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public class CentralBank implements AdvancedAPI, AdminAPI { + + //----------------- BasicAPI methods -------------------------// + + public boolean confirmCredentials(String acctId, String password) { + return false; + } + + public double checkBalance(String acctId) { + return 0; + } + + public void withdraw(String acctId, double amount) throws InsufficientFundsException { + + } + + public void deposit(String acctId, double amount) { + + } + + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + + } + + public String transactionHistory(String acctId) { + return null; + } + + + //----------------- AdvancedAPI methods -------------------------// + + public void createAccount(String acctId, double startingBalance) { + + } + + public void closeAccount(String acctId) { + + } + + + //------------------ AdminAPI methods -------------------------// + + public double checkTotalAssets() { + return 0; + } + + public Collection findAcctIdsWithSuspiciousActivity() { + return null; + } + + public void freezeAccount(String acctId) { + + } + + public void unfreezeAcct(String acctId) { + + } + +} From a225a5b02409bbf4d65a2f7d20eeaa1595936b45 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 4 Feb 2020 14:50:58 -0500 Subject: [PATCH 16/86] untracked .idea files and updated .gitignore --- .gitignore | 1 + .idea/compiler.xml | 13 ------------- .idea/encodings.xml | 6 ------ .idea/misc.xml | 17 ----------------- .idea/sbt.xml | 6 ------ .idea/vcs.xml | 6 ------ 6 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/sbt.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 4cc292d8..dd1e434a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +.idea/ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 28c6362f..00000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index b26911bd..00000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 50a7f10e..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/sbt.xml b/.idea/sbt.xml deleted file mode 100644 index 20187435..00000000 --- a/.idea/sbt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 15d0153d39af221f8b5c6837149f315d86390f93 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 4 Feb 2020 14:57:44 -0500 Subject: [PATCH 17/86] fixed typo checkTotalAssets to calcTotalAssets --- src/main/java/edu/ithaca/dragon/bank/CentralBank.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index 37508848..7f6eba4f 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -44,7 +44,7 @@ public void closeAccount(String acctId) { //------------------ AdminAPI methods -------------------------// - public double checkTotalAssets() { + public double calcTotalAssets() { return 0; } From 79f3d05601ec21ef2366da73f5fde1fd97e07f8f Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 4 Feb 2020 15:37:44 -0500 Subject: [PATCH 18/86] adding SoftwareEngineeringPractice.iml to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index dd1e434a..f1e7b433 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ target/ .idea/ +SoftwareEngineeringPractice.iml # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 From 2092222cc0e90bfcd014d0348939ddce1dd1228e Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 4 Feb 2020 15:38:47 -0500 Subject: [PATCH 19/86] remove SoftwareEngineeringPractive.iml --- SoftwareEngineeringPractice.iml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 SoftwareEngineeringPractice.iml 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 From 6568d75cf2147cf78e32fea6a2bd66fbb26f5f50 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Tue, 4 Feb 2020 21:23:43 -0500 Subject: [PATCH 20/86] Refactored code to follow class diagram --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 35 ++++++++++++ .../java/edu/ithaca/dragon/bank/Account.java | 33 +++++++++++ .../java/edu/ithaca/dragon/bank/Admin.java | 27 +++++++++ .../edu/ithaca/dragon/bank/CentralBank.java | 55 +++++-------------- .../ithaca/dragon/bank/CheckingAccount.java | 4 ++ .../ithaca/dragon/bank/SavingsAccount.java | 10 ++++ .../java/edu/ithaca/dragon/bank/Teller.java | 45 +++++++++++++++ .../java/edu/ithaca/dragon/bank/User.java | 7 +++ 8 files changed, 175 insertions(+), 41 deletions(-) create mode 100644 src/main/java/edu/ithaca/dragon/bank/ATM.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/Account.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/Admin.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/Teller.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/User.java 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..fa6313b1 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -0,0 +1,35 @@ +package edu.ithaca.dragon.bank; + +public class ATM implements BasicAPI { + + + @Override + public boolean confirmCredentials(String acctId, String password) { + return false; + } + + @Override + public double checkBalance(String acctId) { + return 0; + } + + @Override + public void withdraw(String acctId, double amount) throws InsufficientFundsException { + + } + + @Override + public void deposit(String acctId, double amount) { + + } + + @Override + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + + } + + @Override + public String transactionHistory(String acctId) { + return null; + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java new file mode 100644 index 00000000..44d68ad5 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -0,0 +1,33 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public abstract class Account { + private double balance; + private boolean isFrozen; + private Collection users; + + public void withdraw(double amount) { + + } + + public void deposit(double amount) { + + } + + public void transfer(Account toAccount, double amount) { + + } + + public String getCredentials() { + return ""; + } + + public double getBalance() { + return balance; + } + + public String getHistory() { + return ""; + } +} 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..a06c6d62 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -0,0 +1,27 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public class Admin implements AdminAPI { + + + @Override + public double calcTotalAssets() { + return 0; + } + + @Override + public Collection findAcctIdsWithSuspiciousActivity() { + return null; + } + + @Override + public void freezeAccount(String acctId) { + + } + + @Override + public void unfreezeAcct(String acctId) { + + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index 7f6eba4f..0802a2e3 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -2,62 +2,35 @@ import java.util.Collection; -public class CentralBank implements AdvancedAPI, AdminAPI { +public class CentralBank { - //----------------- BasicAPI methods -------------------------// + Collection atms; + Collection accounts; + Collection admins; + Collection users; - public boolean confirmCredentials(String acctId, String password) { - return false; - } - - public double checkBalance(String acctId) { - return 0; - } - - public void withdraw(String acctId, double amount) throws InsufficientFundsException { - - } - - public void deposit(String acctId, double amount) { - - } - - public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + public void withdraw(Account account, double amount) { } - public String transactionHistory(String acctId) { - return null; - } - - - //----------------- AdvancedAPI methods -------------------------// - - public void createAccount(String acctId, double startingBalance) { - - } - - public void closeAccount(String acctId) { + public void deposit(Account account, double amount) { } + public void transfer(Account fromAccount, Account toAccount, double amount) { - //------------------ AdminAPI methods -------------------------// - - public double calcTotalAssets() { - return 0; } - public Collection findAcctIdsWithSuspiciousActivity() { - return null; + public String getCredentials(Account account) { + return account.getCredentials(); } - public void freezeAccount(String acctId) { - + public double getBalance(Account account) { + return account.getBalance(); } - public void unfreezeAcct(String acctId) { - + public String getHistory(Account account) { + return account.getHistory(); } } 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..5649bc57 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -0,0 +1,4 @@ +package edu.ithaca.dragon.bank; + +public class CheckingAccount extends Account { +} 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..480d6ba8 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -0,0 +1,10 @@ +package edu.ithaca.dragon.bank; + +public class SavingsAccount extends Account { + private double interestRate; + private double maximumWithdrawal; + + public void calculateInterest() { + + } +} 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..4955c408 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -0,0 +1,45 @@ +package edu.ithaca.dragon.bank; + +public class Teller extends ATM implements AdvancedAPI { + + + @Override + public void createAccount(String acctId, double startingBalance) { + + } + + @Override + public void closeAccount(String acctId) { + + } + + @Override + public boolean confirmCredentials(String acctId, String password) { + return false; + } + + @Override + public double checkBalance(String acctId) { + return 0; + } + + @Override + public void withdraw(String acctId, double amount) throws InsufficientFundsException { + + } + + @Override + public void deposit(String acctId, double amount) { + + } + + @Override + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + + } + + @Override + public String transactionHistory(String acctId) { + return null; + } +} 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..372bf6d5 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/User.java @@ -0,0 +1,7 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public class User { + Collection accounts; +} From cbc60814f78c71bab92c5d36d3509e918eaa87e4 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Wed, 5 Feb 2020 14:20:56 -0500 Subject: [PATCH 21/86] Saul made me do so much extra work --- src/test/java/edu/ithaca/dragon/bank/AccountTest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/AccountTest.java diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java new file mode 100644 index 00000000..8b8de654 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -0,0 +1,4 @@ +package edu.ithaca.dragon.bank; + +public class AccountTest { +} From 3204e6d3de8c52f7dda92eb969e213821f1ff86d Mon Sep 17 00:00:00 2001 From: eostendarp Date: Wed, 5 Feb 2020 14:21:48 -0500 Subject: [PATCH 22/86] RE:Saul made me do so much extra work --- .../java/edu/ithaca/dragon/bank/Account.java | 19 +++++ .../ithaca/dragon/bank/CheckingAccount.java | 5 +- .../edu/ithaca/dragon/bank/AccountTest.java | 75 ++++++++++++++++++- 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 44d68ad5..536727f8 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -7,6 +7,14 @@ public abstract class Account { private boolean isFrozen; private Collection users; + public Account(double startingBalance) { + if (!isAmountValid(startingBalance)) { + throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); + } else { + this.balance = startingBalance; + } + } + public void withdraw(double amount) { } @@ -19,6 +27,17 @@ public void transfer(Account toAccount, double amount) { } + /** + * returns true if the amount is non-negative and has two decimal points or less, and false otherwise + * @param amount quantity to check + * @return true if the amount is non-negative and has two decimal points or less, and false otherwise + */ + public static boolean isAmountValid(double amount) { + String amountStr = String.valueOf(amount); + int charsAfterDec = amountStr.length() - amountStr.indexOf('.') - 1; + return amount >= 0 && charsAfterDec <= 2; + } + public String getCredentials() { return ""; } diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 5649bc57..62a4e8f2 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -1,4 +1,7 @@ package edu.ithaca.dragon.bank; public class CheckingAccount extends Account { -} + public CheckingAccount(double startingBalance) { + super(startingBalance); + } +} \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 8b8de654..0f1188ba 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -1,4 +1,75 @@ package edu.ithaca.dragon.bank; -public class AccountTest { -} +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class AccountTest { + + private static final double THRESHOLD = 0.001; + + @Test + void depositTest() { + Account account = new CheckingAccount(0); + + //non-negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> account.deposit(0.001)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(0.9999)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(1010.101)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> account.deposit(-0.01)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-0.99)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-8008.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> account.deposit(-0.001)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-5000.125)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> account.deposit(-Double.MAX_VALUE)); + + //non-negative amount with two decimal places or less + account.deposit(0); + assertEquals(0, account.getBalance(), THRESHOLD); + account.deposit(10); + assertEquals(10, account.getBalance(), THRESHOLD); + account.deposit(0.01); + assertEquals(10.01, account.getBalance(), THRESHOLD); + account.deposit(0.99); + assertEquals(11, account.getBalance(), THRESHOLD); + account.deposit(419.5); + assertEquals(430.5, account.getBalance(), THRESHOLD); + } + + @Test + void isAmountValidTest() { + //non-negative amount with two decimal points or less + assertTrue(BankAccount.isAmountValid(0)); + assertTrue(BankAccount.isAmountValid(0.01)); + assertTrue(BankAccount.isAmountValid(0.99)); + assertTrue(BankAccount.isAmountValid(250)); + assertTrue(BankAccount.isAmountValid(1234.50)); + + //non-negative amount with more than two decimal points + assertFalse(BankAccount.isAmountValid(0.001)); + assertFalse(BankAccount.isAmountValid(0.9999)); + assertFalse(BankAccount.isAmountValid(536.125)); + assertFalse(BankAccount.isAmountValid(Double.MIN_VALUE)); + assertFalse(BankAccount.isAmountValid(Double.MAX_VALUE)); + + //negative amount with two decimal points or less + assertFalse(BankAccount.isAmountValid(-0.01)); + assertFalse(BankAccount.isAmountValid(-0.99)); + assertFalse(BankAccount.isAmountValid(-120)); + assertFalse(BankAccount.isAmountValid(-946.5)); + + //negative amount with more than two decimal points + assertFalse(BankAccount.isAmountValid(-0.001)); + assertFalse(BankAccount.isAmountValid(-0.9999)); + assertFalse(BankAccount.isAmountValid(-Double.MIN_VALUE)); + assertFalse(BankAccount.isAmountValid(-Double.MAX_VALUE)); + } +} \ No newline at end of file From b2070dd95f6d495419d5aeb91f26e0418df90e71 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Wed, 5 Feb 2020 14:22:33 -0500 Subject: [PATCH 23/86] implemented Account.deposit --- src/main/java/edu/ithaca/dragon/bank/Account.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 536727f8..a85af227 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -19,8 +19,17 @@ public void withdraw(double amount) { } + /** + * increases the balance by amount if non-negative and has 2 or fewer decimals + * @param amount quantity to increase balance by + * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places + */ public void deposit(double amount) { - + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot deposit"); + } else { + balance += amount; + } } public void transfer(Account toAccount, double amount) { From 840db4e9574f2f66dc1d1a642a050374b9c14ff6 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Wed, 5 Feb 2020 14:24:25 -0500 Subject: [PATCH 24/86] Added tests for account.deposit --- .../java/edu/ithaca/dragon/bank/Account.java | 1 + .../ithaca/dragon/bank/CheckingAccount.java | 11 +++++ .../edu/ithaca/dragon/bank/AccountTest.java | 46 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/AccountTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 44d68ad5..d9a27bbd 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -7,6 +7,7 @@ public abstract class Account { private boolean isFrozen; private Collection users; + public void withdraw(double amount) { } diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 5649bc57..fe818a4c 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -1,4 +1,15 @@ package edu.ithaca.dragon.bank; +import java.util.Collection; + public class CheckingAccount extends Account { + private double balance; + private boolean isFrozen; + private Collection users; + + public CheckingAccount(double balance, Collection users){ + this.balance = balance; + this.users = users; + + } } diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java new file mode 100644 index 00000000..fb2951e5 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -0,0 +1,46 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class AccountTest { + private static final double THRESHOLD = 0.001; + + @Test + void depositTest() { + CheckingAccount bankAccount = new CheckingAccount(0, null); + + //non-negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(1010.101)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-8008.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-5000.125)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MAX_VALUE)); + + //non-negative amount with two decimal places or less + bankAccount.deposit(0); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(10); + assertEquals(10, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(0.01); + assertEquals(10.01, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(0.99); + assertEquals(11, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(419.5); + assertEquals(430.5, bankAccount.getBalance(), THRESHOLD); + } +} From 887bb5d3ed203ebdd7b79c64a26b40dcd6d69ab2 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Wed, 5 Feb 2020 14:27:44 -0500 Subject: [PATCH 25/86] Saul didn't finish implementing SavingAccount constructor so I need to do this in order to compile --- src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index 480d6ba8..54ef7cc8 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -4,6 +4,12 @@ public class SavingsAccount extends Account { private double interestRate; private double maximumWithdrawal; + public SavingsAccount(double startingBalance, double interestRate, double maximumWithdrawal) { + super(startingBalance); + this.interestRate = interestRate; + this.maximumWithdrawal = maximumWithdrawal; + } + public void calculateInterest() { } From efdce0d304120c9284657d0f0aaa90f5f755a754 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Wed, 5 Feb 2020 14:30:27 -0500 Subject: [PATCH 26/86] added tests for deposit, isEmailValid, and constructor --- .../java/edu/ithaca/dragon/bank/Account.java | 15 +++ .../ithaca/dragon/bank/CheckingAccount.java | 3 + .../ithaca/dragon/bank/SavingsAccount.java | 4 + .../edu/ithaca/dragon/bank/AccountTest.java | 116 ++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/AccountTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 44d68ad5..07c88a97 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -1,12 +1,16 @@ package edu.ithaca.dragon.bank; import java.util.Collection; +import java.util.regex.Pattern; public abstract class Account { private double balance; private boolean isFrozen; private Collection users; + public Account(double startingBalance) {} + + public void withdraw(double amount) { } @@ -30,4 +34,15 @@ public double getBalance() { public String getHistory() { return ""; } + + /** + * returns true if the amount is non-negative and has two decimal points or less, and false otherwise + * @param amount quantity to check + * @return true if the amount is non-negative and has two decimal points or less, and false otherwise + */ + public static boolean isAmountValid(double amount) { + String amountStr = String.valueOf(amount); + int charsAfterDec = amountStr.length() - amountStr.indexOf('.') - 1; + return amount >= 0 && charsAfterDec <= 2; + } } diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 5649bc57..149ae903 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -1,4 +1,7 @@ package edu.ithaca.dragon.bank; public class CheckingAccount extends Account { + public CheckingAccount(double startingBalance) { + super(startingBalance); + } } diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index 480d6ba8..78e8bc93 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -4,6 +4,10 @@ public class SavingsAccount extends Account { private double interestRate; private double maximumWithdrawal; + public SavingsAccount(double startingBalance) { + super(startingBalance); + } + public void calculateInterest() { } diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java new file mode 100644 index 00000000..d26f1db5 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -0,0 +1,116 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class AccountTest { + private static final double THRESHOLD = 0.001; + + @Test + void depositTest() { + Account bankAccount = new CheckingAccount( 0); + + //non-negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(1010.101)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-8008.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-5000.125)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(-Double.MAX_VALUE)); + + //non-negative amount with two decimal places or less + bankAccount.deposit(0); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(10); + assertEquals(10, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(0.01); + assertEquals(10.01, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(0.99); + assertEquals(11, bankAccount.getBalance(), THRESHOLD); + bankAccount.deposit(419.5); + assertEquals(430.5, bankAccount.getBalance(), THRESHOLD); + } + + @Test + void isAmountValidTest() { + //non-negative amount with two decimal points or less + assertTrue(Account.isAmountValid(0)); + assertTrue(Account.isAmountValid(0.01)); + assertTrue(Account.isAmountValid(0.99)); + assertTrue(Account.isAmountValid(250)); + assertTrue(Account.isAmountValid(1234.50)); + + //non-negative amount with more than two decimal points + assertFalse(Account.isAmountValid(0.001)); + assertFalse(Account.isAmountValid(0.9999)); + assertFalse(Account.isAmountValid(536.125)); + assertFalse(Account.isAmountValid(Double.MIN_VALUE)); + assertFalse(Account.isAmountValid(Double.MAX_VALUE)); + + //negative amount with two decimal points or less + assertFalse(Account.isAmountValid(-0.01)); + assertFalse(Account.isAmountValid(-0.99)); + assertFalse(Account.isAmountValid(-120)); + assertFalse(Account.isAmountValid(-946.5)); + + //negative amount with more than two decimal points + assertFalse(Account.isAmountValid(-0.001)); + assertFalse(Account.isAmountValid(-0.9999)); + assertFalse(Account.isAmountValid(-Double.MIN_VALUE)); + assertFalse(Account.isAmountValid(-Double.MAX_VALUE)); + } + + @Test + void constructorTest() { + Account bankAccount = new CheckingAccount( 200); + + assertEquals(200, bankAccount.getBalance()); + //check for exception thrown correctly + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 100)); + + //non-negative balance with two decimal places or less + bankAccount = new CheckingAccount( 0); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + bankAccount = new CheckingAccount( 0.01); + assertEquals(0.01, bankAccount.getBalance(), THRESHOLD); + bankAccount = new CheckingAccount( 0.99); + assertEquals(0.99, bankAccount.getBalance(), THRESHOLD); + bankAccount = new CheckingAccount( 9876.5); + assertEquals(9876.5, bankAccount.getBalance(), THRESHOLD); + bankAccount = new CheckingAccount(248); + assertEquals(248, bankAccount.getBalance(), THRESHOLD); + + //non-negative balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.001)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.9999)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 369.333)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MIN_VALUE)); + + //negative balance with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.01)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.99)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -10.2)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -125)); + + //negative balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.001)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.9999)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -369.333)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MIN_VALUE)); + } + +} From e70b0fa500c8cbdd58119828339f47796845d847 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Wed, 5 Feb 2020 14:33:58 -0500 Subject: [PATCH 27/86] implemented Account deposit and constructor --- .../java/edu/ithaca/dragon/bank/Account.java | 17 +++++++++++++++-- .../edu/ithaca/dragon/bank/AccountTest.java | 2 -- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 07c88a97..666bc288 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -8,15 +8,28 @@ public abstract class Account { private boolean isFrozen; private Collection users; - public Account(double startingBalance) {} + public Account(double startingBalance) { + if (!isAmountValid(startingBalance)) + throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); + balance = startingBalance; + } public void withdraw(double amount) { } + /** + * increases the balance by amount if non-negative and has 2 or fewer decimals + * @param amount quantity to increase balance by + * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places + */ public void deposit(double amount) { - + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot deposit"); + } else { + balance += amount; + } } public void transfer(Account toAccount, double amount) { diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index d26f1db5..44cfd59a 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -77,8 +77,6 @@ void constructorTest() { Account bankAccount = new CheckingAccount( 200); assertEquals(200, bankAccount.getBalance()); - //check for exception thrown correctly - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 100)); //non-negative balance with two decimal places or less bankAccount = new CheckingAccount( 0); From 996bd4b80b46e1fe4feed896d61ff935c9713fc5 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Wed, 5 Feb 2020 14:44:19 -0500 Subject: [PATCH 28/86] Implemented deposit --- src/main/java/edu/ithaca/dragon/bank/Account.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index d9a27bbd..bc5a0651 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -13,6 +13,17 @@ public void withdraw(double amount) { } public void deposit(double amount) { + String amountStr = String.valueOf(amount); + int charsAfterDec = amountStr.length() - amountStr.indexOf('.') - 1; + if (amount < 0){ + throw new IllegalArgumentException("Cannot deposit negative amount"); + } + else if (charsAfterDec > 2){ + throw new IllegalArgumentException("Too many decimal places"); + } + else{ + balance += amount; + } } From aa1cefe09fb232ab2299f507df44808302dfbb18 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Wed, 5 Feb 2020 18:39:30 -0500 Subject: [PATCH 29/86] Added use case diagram to README --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 87c23b2d..9def144c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # SoftwareEngineeringPractice -## grading - -To Do | correct ----|--- -at least 8 commits| -isEmailValid| -withdraw| -isamountValid| -constructor & withdraw fix| + +Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 + + + From 6019dbecd2b782ce67686196a326972fb39855d1 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 13:28:35 -0500 Subject: [PATCH 30/86] Added Admin constructor test, had to add a default false for isFrozen to account, as well as a basic getter for frozen status --- .../java/edu/ithaca/dragon/bank/Account.java | 5 +++ .../java/edu/ithaca/dragon/bank/Admin.java | 11 ++++++ .../edu/ithaca/dragon/bank/AdminTest.java | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/AdminTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index ecc2481a..3678f390 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -14,6 +14,7 @@ public Account(double startingBalance) { throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); } else { this.balance = startingBalance; + this.isFrozen = false; } } @@ -52,6 +53,10 @@ public String getHistory() { return ""; } + public boolean getFrozenStatus(){ + return isFrozen; + } + /** * returns true if the amount is non-negative and has two decimal points or less, and false otherwise * @param amount quantity to check diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index a06c6d62..810507a6 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -3,7 +3,14 @@ import java.util.Collection; public class Admin implements AdminAPI { + Collection accounts; + /** + * creates an Admin account that knows what accounts it controls + * @param accounts the accounts that Admin must act on + */ + public Admin(Collection accounts){ + } @Override public double calcTotalAssets() { @@ -24,4 +31,8 @@ public void freezeAccount(String acctId) { public void unfreezeAcct(String acctId) { } + + public Collection getAccounts(){ + return this.accounts; + } } diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java new file mode 100644 index 00000000..efe88558 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -0,0 +1,37 @@ +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 AdminTest { + + @Test + void constructorTest() { + Admin admin = new Admin(null); + assertEquals(null, admin.getAccounts()); + Collection testCollection = new ArrayList(); + testCollection.add(new CheckingAccount(50)); + testCollection.add(new CheckingAccount(100)); + admin = new Admin(testCollection); + assertEquals(testCollection,admin.getAccounts()); + + } + + @Test + //Incomplete, have to make admin constructor first + void freezeAccountTest() { + Account testAcc = new CheckingAccount(500); + assertEquals(false, testAcc.getFrozenStatus()); + + } + + + +} From b50ad7637c57825fab5974b7f0f744c269e41ebd Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 13:31:18 -0500 Subject: [PATCH 31/86] Implemented admin constructor --- src/main/java/edu/ithaca/dragon/bank/Admin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index 810507a6..c4593cc5 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -10,6 +10,7 @@ public class Admin implements AdminAPI { * @param accounts the accounts that Admin must act on */ public Admin(Collection accounts){ + this.accounts = accounts; } @Override From e7dd6aaad3aa8b06c997aa5190658619f5983338 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 13:50:00 -0500 Subject: [PATCH 32/86] Had to mess with Account constructor so they have IDs, updated constructorTest accordingly --- .../java/edu/ithaca/dragon/bank/Account.java | 7 ++- .../ithaca/dragon/bank/CheckingAccount.java | 4 +- .../ithaca/dragon/bank/SavingsAccount.java | 4 +- .../edu/ithaca/dragon/bank/AccountTest.java | 53 +++++++++++-------- .../edu/ithaca/dragon/bank/AdminTest.java | 13 +++-- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 3678f390..6d1ced4a 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -7,9 +7,10 @@ public abstract class Account { private double balance; private boolean isFrozen; private Collection users; + private String id; - public Account(double startingBalance) { + public Account(double startingBalance, String id) { if (!isAmountValid(startingBalance)) { throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); } else { @@ -57,6 +58,10 @@ public boolean getFrozenStatus(){ return isFrozen; } + public String getID(){ + return id; + } + /** * returns true if the amount is non-negative and has two decimal points or less, and false otherwise * @param amount quantity to check diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 441303c8..cb09b8cb 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -4,7 +4,7 @@ public class CheckingAccount extends Account { - public CheckingAccount(double startingBalance) { - super(startingBalance); + public CheckingAccount(double startingBalance, String id) { + super(startingBalance, id); } } diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index fb59835a..421eaf4e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -5,8 +5,8 @@ public class SavingsAccount extends Account { private double maximumWithdrawal; - public SavingsAccount(double startingBalance, double interestRate, double maximumWithdrawal) { - super(startingBalance); + public SavingsAccount(double startingBalance, double interestRate, double maximumWithdrawal, String id) { + super(startingBalance, id); this.interestRate = interestRate; this.maximumWithdrawal = maximumWithdrawal; } diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 9bcdc5a7..1793e928 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -12,7 +12,7 @@ public class AccountTest { @Test void depositTest() { - Account bankAccount = new CheckingAccount( 0); + Account bankAccount = new CheckingAccount( 0, "1"); //non-negative amount with more than two decimal places assertThrows(IllegalArgumentException.class, () -> bankAccount.deposit(0.001)); @@ -50,41 +50,52 @@ void depositTest() { @Test void constructorTest() { - Account bankAccount = new CheckingAccount( 200); + Account bankAccount = new CheckingAccount( 200, "1"); assertEquals(200, bankAccount.getBalance()); //non-negative balance with two decimal places or less - bankAccount = new CheckingAccount( 0); + bankAccount = new CheckingAccount( 0, "1"); assertEquals(0, bankAccount.getBalance(), THRESHOLD); - bankAccount = new CheckingAccount( 0.01); + bankAccount = new CheckingAccount( 0.01, "1"); assertEquals(0.01, bankAccount.getBalance(), THRESHOLD); - bankAccount = new CheckingAccount( 0.99); + bankAccount = new CheckingAccount( 0.99, "1"); assertEquals(0.99, bankAccount.getBalance(), THRESHOLD); - bankAccount = new CheckingAccount( 9876.5); + bankAccount = new CheckingAccount( 9876.5, "1"); assertEquals(9876.5, bankAccount.getBalance(), THRESHOLD); - bankAccount = new CheckingAccount(248); + bankAccount = new CheckingAccount(248, "1"); assertEquals(248, bankAccount.getBalance(), THRESHOLD); //non-negative balance with more than two decimal places - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.001)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.9999)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 369.333)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MAX_VALUE)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.001, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount(0.9999, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 369.333, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MAX_VALUE, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( Double.MIN_VALUE, "1")); //negative balance with two decimal places or less - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.01)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.99)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -10.2)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -125)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.01, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.99, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -10.2, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -125, "1")); //negative balance with more than two decimal places - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.001)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.9999)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -369.333)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MAX_VALUE)); - assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.001, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.9999, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -369.333, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MAX_VALUE, "1")); + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -Double.MIN_VALUE, "1")); + + //for now assuming any non-empty string is a valid id, may have to update these tests later + bankAccount = new CheckingAccount(50, "1"); + assertEquals("1", bankAccount.getID()); + bankAccount = new CheckingAccount(50, "abc"); + assertEquals("abc", bankAccount.getID()); + + //checking with emptyString, illegal argument for balance takes precedence + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( -0.001, ""));//Bad balance takes precedence + assertThrows(IllegalArgumentException.class, () -> new CheckingAccount( 50, "")); + } @Test diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index efe88558..bd5a608c 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -17,18 +17,23 @@ void constructorTest() { Admin admin = new Admin(null); assertEquals(null, admin.getAccounts()); Collection testCollection = new ArrayList(); - testCollection.add(new CheckingAccount(50)); - testCollection.add(new CheckingAccount(100)); + testCollection.add(new CheckingAccount(50, "1234")); + testCollection.add(new CheckingAccount(100,"123")); admin = new Admin(testCollection); assertEquals(testCollection,admin.getAccounts()); } @Test - //Incomplete, have to make admin constructor first + //Incomplete, have to make Account use ID first void freezeAccountTest() { - Account testAcc = new CheckingAccount(500); + Account testAcc = new CheckingAccount(500, "abc"); + Collection collection = new ArrayList(); + collection.add(testAcc); + Admin admin = new Admin(collection); assertEquals(false, testAcc.getFrozenStatus()); + admin.freezeAccount("id"); + } From 1ff1da3eae8e067d9846a3c0011ee0d53eefcc6d Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 13:51:33 -0500 Subject: [PATCH 33/86] Updated constructor for Account --- src/main/java/edu/ithaca/dragon/bank/Account.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 6d1ced4a..2bab4d45 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -13,9 +13,14 @@ public abstract class Account { public Account(double startingBalance, String id) { if (!isAmountValid(startingBalance)) { throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); - } else { + } + else if (id == ""){ + throw new IllegalArgumentException("ID cannot be an empty string"); + } + else { this.balance = startingBalance; this.isFrozen = false; + this.id = id; } } From 92059fb6a58979c7bcdefff4813b8059bbab84ec Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 14:01:26 -0500 Subject: [PATCH 34/86] Added freezeAccount tests --- .../java/edu/ithaca/dragon/bank/Admin.java | 4 +-- .../edu/ithaca/dragon/bank/AdminTest.java | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index c4593cc5..eec34956 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -24,12 +24,12 @@ public Collection findAcctIdsWithSuspiciousActivity() { } @Override - public void freezeAccount(String acctId) { + public void freezeAccount(String acctId) throws IllegalArgumentException { } @Override - public void unfreezeAcct(String acctId) { + public void unfreezeAcct(String acctId) throws IllegalArgumentException { } diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index bd5a608c..40ef2ef9 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -25,15 +25,30 @@ void constructorTest() { } @Test - //Incomplete, have to make Account use ID first void freezeAccountTest() { - Account testAcc = new CheckingAccount(500, "abc"); + Account abcAcc = new CheckingAccount(500, "abc"); + Account xyzAcc = new CheckingAccount(500, "xyz"); Collection collection = new ArrayList(); - collection.add(testAcc); + collection.add(abcAcc); + collection.add(xyzAcc); Admin admin = new Admin(collection); - assertEquals(false, testAcc.getFrozenStatus()); - admin.freezeAccount("id"); - + //Checking false frozen status after no change + assertEquals(false, abcAcc.getFrozenStatus()); + assertEquals(false, xyzAcc.getFrozenStatus()); + admin.freezeAccount("abc"); + //Checking for true after frozen, and that other account unaffected + assertEquals(true, abcAcc.getFrozenStatus()); + assertEquals(false, xyzAcc.getFrozenStatus()); + admin.freezeAccount("abc"); + //Checking still true if you attempt to freeze a frozen account + assertEquals(true, abcAcc.getFrozenStatus()); + //Checking freezing other account + admin.freezeAccount("xyz"); + assertEquals(true, xyzAcc.getFrozenStatus()); + //Checking with IDs not present in collection + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("123")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("")); + assertThrows(IllegalArgumentException.class, () -> admin.freezeAccount("abcd")); } From b0ed8b66e1051bea638bd3d9a6e3e28373df57cc Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 14:10:54 -0500 Subject: [PATCH 35/86] Freeze Account implemented, had to add a setter for frozen status in Account --- src/main/java/edu/ithaca/dragon/bank/Account.java | 4 ++++ src/main/java/edu/ithaca/dragon/bank/Admin.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 2bab4d45..d3b332b2 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -63,6 +63,10 @@ public boolean getFrozenStatus(){ return isFrozen; } + public void setFrozen(boolean frozenStatus){ + isFrozen = frozenStatus; + } + public String getID(){ return id; } diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index eec34956..94c6aed1 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -1,6 +1,7 @@ package edu.ithaca.dragon.bank; import java.util.Collection; +import java.util.Iterator; public class Admin implements AdminAPI { Collection accounts; @@ -25,6 +26,18 @@ public Collection findAcctIdsWithSuspiciousActivity() { @Override public void freezeAccount(String acctId) throws IllegalArgumentException { + boolean accountFound = false; + Iterator itr = this.accounts.iterator(); + while (itr.hasNext()){ + Account current = itr.next(); + if (current.getID()== acctId){ + accountFound = true; + current.setFrozen(true); + } + } + if (accountFound == false){ + throw new IllegalArgumentException("String not in collection"); + } } From 84a2ec43283f183d1ec1921a86ac2b08f1da9960 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 14:15:21 -0500 Subject: [PATCH 36/86] Added unfreeze tests --- .../edu/ithaca/dragon/bank/AdminTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 40ef2ef9..81b0fd46 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -52,6 +52,36 @@ void freezeAccountTest() { } + @Test + void unFreezeAccountTest() { + Account abcAcc = new CheckingAccount(500, "abc"); + Account xyzAcc = new CheckingAccount(500, "xyz"); + Collection collection = new ArrayList(); + collection.add(abcAcc); + collection.add(xyzAcc); + Admin admin = new Admin(collection); + //Checking true frozen status after change + abcAcc.setFrozen(true); + xyzAcc.setFrozen(true); + assertEquals(true, abcAcc.getFrozenStatus()); + assertEquals(true, xyzAcc.getFrozenStatus()); + //Checking only one acc gets changed + admin.unfreezeAcct("abc"); + assertEquals(false, abcAcc.getFrozenStatus()); + assertEquals(true, xyzAcc.getFrozenStatus()); + //Checking can unfreeze other acc + admin.unfreezeAcct("xyz"); + assertEquals(false, xyzAcc.getFrozenStatus()); + //Checking that unfreezing an unfrozen account remains false + admin.unfreezeAcct("xyz"); + assertEquals(false, xyzAcc.getFrozenStatus()); + //Checking with IDs not present in collection + assertThrows(IllegalArgumentException.class, () -> admin.unfreezeAcct("123")); + assertThrows(IllegalArgumentException.class, () -> admin.unfreezeAcct("")); + assertThrows(IllegalArgumentException.class, () -> admin.unfreezeAcct("abcd")); + + } + } From 24c27352d9be378e7992e137b9822cb221dc8465 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Fri, 7 Feb 2020 14:16:51 -0500 Subject: [PATCH 37/86] Implemented unfreeze --- src/main/java/edu/ithaca/dragon/bank/Admin.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index 94c6aed1..e420b88e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -43,6 +43,18 @@ public void freezeAccount(String acctId) throws IllegalArgumentException { @Override public void unfreezeAcct(String acctId) throws IllegalArgumentException { + boolean accountFound = false; + Iterator itr = this.accounts.iterator(); + while (itr.hasNext()){ + Account current = itr.next(); + if (current.getID()== acctId){ + accountFound = true; + current.setFrozen(false); + } + } + if (accountFound == false){ + throw new IllegalArgumentException("String not in collection"); + } } From d7359ba5be1e05cd5254b96633f61e422d6fd0d6 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 16:53:47 -0500 Subject: [PATCH 38/86] added withdraw tests --- .../java/edu/ithaca/dragon/bank/Account.java | 2 +- .../edu/ithaca/dragon/bank/AccountTest.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index d3b332b2..593a5509 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -14,7 +14,7 @@ public Account(double startingBalance, String id) { if (!isAmountValid(startingBalance)) { throw new IllegalArgumentException("Starting balance: " + startingBalance + " is invalid, cannot create account"); } - else if (id == ""){ + else if (id.equals("")){ throw new IllegalArgumentException("ID cannot be an empty string"); } else { diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 1793e928..0a2d3df9 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -9,6 +9,51 @@ public class AccountTest { private static final double THRESHOLD = 0.001; + @Test + void withdrawTest() { + Account bankAccount = new CheckingAccount(1000, "a@b.com"); + + //non-negative amount less than or equal to balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(3141.592)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(Double.MIN_VALUE)); + + //non-negative amount greater than balance with two decimal places or less + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(1000.01)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(5432)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(3216.8)); + + //non-negative amount greater than balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(9876.543)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.01)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.99)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-2718.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.001)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-0.9999)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-14850.607)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MAX_VALUE)); + + //non-negative amount less than or equal to balance with two decimal places or less + bankAccount.withdraw(0); + assertEquals(1000, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(100); + assertEquals(900, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(0.01); + assertEquals(899.99, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(898.99); + assertEquals(1, bankAccount.getBalance(), THRESHOLD); + bankAccount.withdraw(1); + assertEquals(0, bankAccount.getBalance(), THRESHOLD); + } + @Test void depositTest() { From 713e17d55571466d55a4b542046a700ec72c654d Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 16:55:35 -0500 Subject: [PATCH 39/86] implemented withdraw --- .../java/edu/ithaca/dragon/bank/Account.java | 17 ++++++++++++++--- .../edu/ithaca/dragon/bank/AccountTest.java | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 593a5509..8bcebe9e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -24,9 +24,20 @@ else if (id.equals("")){ } } - - public void withdraw(double amount) { - + /** + * reduces the balance by amount if amount is non-negative, has 2 or fewer decimals and is smaller or equal to balance + * @param amount quantity to reduce balance by + * @throws IllegalArgumentException if amount is negative or has more than 2 decimals + * @throws InsufficientFundsException if amount is larger than balance + */ + public void withdraw(double amount) throws InsufficientFundsException{ + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot withdraw"); + } else if (amount > balance) { + throw new InsufficientFundsException("Not enough money"); + } else { + balance -= amount; + } } /** diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 0a2d3df9..b8d2fa0c 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -10,7 +10,7 @@ public class AccountTest { private static final double THRESHOLD = 0.001; @Test - void withdrawTest() { + void withdrawTest() throws InsufficientFundsException{ Account bankAccount = new CheckingAccount(1000, "a@b.com"); //non-negative amount less than or equal to balance with more than two decimal places From a58ef55a27bcde154af20f022da2a98e0cf57606 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 16:58:16 -0500 Subject: [PATCH 40/86] added transfer tests --- .../edu/ithaca/dragon/bank/AccountTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index b8d2fa0c..ac539269 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -93,6 +93,56 @@ void depositTest() { } + @Test + void transferTest() throws InsufficientFundsException { + Account a = new CheckingAccount(1000, "a@b.com"); + Account b = new CheckingAccount(0, "a@b.com"); + + //non-negative amount less than or equal to balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 0.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 0.9999)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 999.999)); + + //non-negative amount greater than balance with two decimal places or less + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 1000.01)); + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 2500.5)); + assertThrows(InsufficientFundsException.class, () -> a.transfer(b, 1357)); + + //non-negative amount greater than balance with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 1000.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, 6666.6666)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, Double.MAX_VALUE)); + + //negative amount with two decimal places or less + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.01)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.99)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -607.2)); + + //negative amount with more than two decimal places + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.001)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -0.9999)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -9876.54321)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -Double.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> a.transfer(b, -Double.MAX_VALUE)); + + //non-negative amount less than or equal to balance with two decimal places or less + a.transfer(b, 0); + assertEquals(1000, a.getBalance(), THRESHOLD); + assertEquals(0, b.getBalance(), THRESHOLD); + a.transfer(b, 0.01); + assertEquals(999.99, a.getBalance(), THRESHOLD); + assertEquals(0.01, b.getBalance(), THRESHOLD); + a.transfer(b, 500); + assertEquals(499.99, a.getBalance(), THRESHOLD); + assertEquals(500.01, b.getBalance(), THRESHOLD); + a.transfer(b, 498.99); + assertEquals(1, a.getBalance(), THRESHOLD); + assertEquals(999, b.getBalance(), THRESHOLD); + a.transfer(b, 1); + assertEquals(0, a.getBalance(), THRESHOLD); + assertEquals(1000, b.getBalance(), THRESHOLD); + } + @Test void constructorTest() { Account bankAccount = new CheckingAccount( 200, "1"); From 8e048e6003a7cb8a70b5e145d653734b9085a32a Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 16:59:30 -0500 Subject: [PATCH 41/86] implemented account transfer --- .../java/edu/ithaca/dragon/bank/Account.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 8bcebe9e..4a43e1d4 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -54,8 +54,22 @@ public void deposit(double amount) { } } - public void transfer(Account toAccount, double amount) { - + /** + * withdraws amount from balance and deposits it into to's balance + * @param toAccount BankAccount who's balance will be deposited into + * @param amount quantity to withdraw from balance and deposit into to's balance + * @throws IllegalArgumentException if amount is negative or has more than 2 decimals + * @throws InsufficientFundsException if amount is larger than balance + */ + public void transfer(Account toAccount, double amount) throws InsufficientFundsException { + if (!isAmountValid(amount)) { + throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot transfer"); + } else if (amount > balance) { + throw new InsufficientFundsException("Not enough money"); + } else { + withdraw(amount); + toAccount.deposit(amount); + } } public String getCredentials() { From 9fb6dca5cea60621d669ec8ee78d9072e52c273c Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:09:41 -0500 Subject: [PATCH 42/86] Added SavingsAccount withdraw tests --- .../dragon/bank/SavingsAccountTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java diff --git a/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java new file mode 100644 index 00000000..83605a21 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java @@ -0,0 +1,23 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +public class SavingsAccountTest { + + + @Test + void withdrawTest() throws InsufficientFundsException{ + Account a = new SavingsAccount(30, 0.5, 20, "a@b.com"); + + a.withdraw(10); + assertEquals(20, a.getBalance()); + + assertThrows(IllegalArgumentException.class, () -> a.withdraw(50)); + a.withdraw(10); + assertThrows(InsufficientFundsException.class, () -> a.withdraw(15)); + + } + +} From de63c5eede75cde9d4a090b2dbf665c740f3a80e Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:11:19 -0500 Subject: [PATCH 43/86] implemented SavingsAccount withdraw --- src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index 421eaf4e..bb2a7875 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -11,6 +11,15 @@ public SavingsAccount(double startingBalance, double interestRate, double maximu this.maximumWithdrawal = maximumWithdrawal; } + @Override + public void withdraw(double amount) throws InsufficientFundsException { + if(amount <= maximumWithdrawal) { + super.withdraw(amount); + } else { + throw new IllegalArgumentException("Amount is greater than maximum withdrawal amount"); + } + } + public void calculateInterest() { } From c9bbd269295c4f01142af7db4305d8b0cf079c3c Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:14:38 -0500 Subject: [PATCH 44/86] Added SavingsAccount calcInterest tests --- .../java/edu/ithaca/dragon/bank/SavingsAccountTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java index 83605a21..a01a1c60 100644 --- a/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java @@ -20,4 +20,12 @@ void withdrawTest() throws InsufficientFundsException{ } + @Test + void calcInterestTest() { + SavingsAccount a = new SavingsAccount(100, 0.5, 20, "a@b.com"); + + a.calculateInterest(); + assertEquals(150, a.getBalance()); + } + } From cf22e06103fe544a4a2e973bd105bd566fda9bda Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:16:17 -0500 Subject: [PATCH 45/86] implemented SavingsAccount calcInterest --- src/main/java/edu/ithaca/dragon/bank/Account.java | 8 ++++---- src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 4a43e1d4..13f5f568 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -4,10 +4,10 @@ import java.util.regex.Pattern; public abstract class Account { - private double balance; - private boolean isFrozen; - private Collection users; - private String id; + protected double balance; + protected boolean isFrozen; + protected Collection users; + protected String id; public Account(double startingBalance, String id) { diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index bb2a7875..bf68fb4d 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -21,6 +21,6 @@ public void withdraw(double amount) throws InsufficientFundsException { } public void calculateInterest() { - + balance += balance * interestRate; } } From fef36472f386cbe7572c8de7b384e703ebd47a59 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:36:12 -0500 Subject: [PATCH 46/86] added tests for User AddAccount, RemoveAccount, and getAccount --- .../java/edu/ithaca/dragon/bank/User.java | 30 +++++++++++- .../java/edu/ithaca/dragon/bank/UserTest.java | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/java/edu/ithaca/dragon/bank/UserTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/User.java b/src/main/java/edu/ithaca/dragon/bank/User.java index 372bf6d5..eacfdd6d 100644 --- a/src/main/java/edu/ithaca/dragon/bank/User.java +++ b/src/main/java/edu/ithaca/dragon/bank/User.java @@ -3,5 +3,33 @@ import java.util.Collection; public class User { - Collection accounts; + private Collection accounts; + + public User() { + + } + + public void addAccount(Account accountToAdd) { + + } + + public void removeAccount(String id) { + + } + + public void withdraw(Account account, double amount) { + + } + + public void deposit(Account account, double amount) { + + } + + public void transfer(Account accountTo, Account accountFrom, double amount) { + + } + + public Account getAccount(String id) { + return null; + } } diff --git a/src/test/java/edu/ithaca/dragon/bank/UserTest.java b/src/test/java/edu/ithaca/dragon/bank/UserTest.java new file mode 100644 index 00000000..0f7c7070 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/UserTest.java @@ -0,0 +1,46 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +public class UserTest { + + @Test + void constructorTest() { + User u = new User(); + } + + @Test + void addAccountTest() { + Account a = new CheckingAccount(100, "a@b.com"); + User u = new User(); + + u.addAccount(a); + assertEquals(u.getAccount("a@b.com"), a); + } + + @Test + void removeAccountTest() { + Account a = new CheckingAccount(100, "a@b.com"); + User u = new User(); + + assertThrows(IllegalArgumentException.class, () -> u.getAccount("")); + + u.addAccount(a); + u.removeAccount("a@b.com"); + assertThrows(IllegalArgumentException.class, () -> u.getAccount("a@b.com")); + } + + @Test + void getAccountTest() { + Account a = new CheckingAccount(100, "a@b.com"); + User u = new User(); + + u.addAccount(a); + assertEquals(u.getAccount("a@b.com"), a); + + assertThrows(IllegalArgumentException.class, () -> u.getAccount("")); + } + +} From 96aa90d431c0b5a2a7bf462f581bd36d0b5705de Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Sun, 9 Feb 2020 17:57:00 -0500 Subject: [PATCH 47/86] implemented getAccount, addAccount, and removeAccount --- .../java/edu/ithaca/dragon/bank/User.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/User.java b/src/main/java/edu/ithaca/dragon/bank/User.java index eacfdd6d..8d6cfd02 100644 --- a/src/main/java/edu/ithaca/dragon/bank/User.java +++ b/src/main/java/edu/ithaca/dragon/bank/User.java @@ -1,20 +1,26 @@ package edu.ithaca.dragon.bank; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; public class User { - private Collection accounts; + private Map accounts; public User() { - + accounts = new HashMap(); } public void addAccount(Account accountToAdd) { - + accounts.put(accountToAdd.getID(), accountToAdd); } public void removeAccount(String id) { - + if(accounts.containsKey(id)) { + accounts.remove(id); + } else { + throw new IllegalArgumentException("User does not contain account with id: " + id); + } } public void withdraw(Account account, double amount) { @@ -30,6 +36,10 @@ public void transfer(Account accountTo, Account accountFrom, double amount) { } public Account getAccount(String id) { - return null; + if(accounts.containsKey(id)) { + return accounts.get(id); + } else { + throw new IllegalArgumentException("User does not contain account with id: " + id); + } } } From 79d1d7e44a46d77012420ba7976099dfdd2d663c Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Mon, 10 Feb 2020 11:09:14 -0500 Subject: [PATCH 48/86] added passing integration tests for User and Account --- .../java/edu/ithaca/dragon/bank/User.java | 12 ---------- .../java/edu/ithaca/dragon/bank/UserTest.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/User.java b/src/main/java/edu/ithaca/dragon/bank/User.java index 8d6cfd02..d96d35ee 100644 --- a/src/main/java/edu/ithaca/dragon/bank/User.java +++ b/src/main/java/edu/ithaca/dragon/bank/User.java @@ -23,18 +23,6 @@ public void removeAccount(String id) { } } - public void withdraw(Account account, double amount) { - - } - - public void deposit(Account account, double amount) { - - } - - public void transfer(Account accountTo, Account accountFrom, double amount) { - - } - public Account getAccount(String id) { if(accounts.containsKey(id)) { return accounts.get(id); diff --git a/src/test/java/edu/ithaca/dragon/bank/UserTest.java b/src/test/java/edu/ithaca/dragon/bank/UserTest.java index 0f7c7070..6d0d98b6 100644 --- a/src/test/java/edu/ithaca/dragon/bank/UserTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/UserTest.java @@ -43,4 +43,27 @@ void getAccountTest() { assertThrows(IllegalArgumentException.class, () -> u.getAccount("")); } + + //Tests adding account, getting account, and calling account methods by id + @Test + void IntegrationTest() throws InsufficientFundsException{ + String idA = "a@c.com"; + String idB = "b@c.com"; + Account a = new CheckingAccount(100, idA); + Account b = new CheckingAccount(200, idB); + User u = new User(); + + u.addAccount(a); + u.addAccount(b); + + u.getAccount(idA).withdraw(50); + assertEquals(50, u.getAccount(idA).getBalance()); + u.getAccount(idA).deposit(20); + assertEquals(70, u.getAccount(idA).getBalance()); + u.getAccount(idB).transfer(u.getAccount(idA), 100); + assertEquals(170, u.getAccount(idA).getBalance()); + assertEquals(100, u.getAccount(idB).getBalance()); + + } + } From 236c8733c7505388b4b79c81803122500b074a66 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Mon, 10 Feb 2020 11:19:03 -0500 Subject: [PATCH 49/86] added usecase diagram to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9def144c..25a168df 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,7 @@ Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 +Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing + From d0e6eb9603c79dfd31b6cb6ced8d0a692745aa92 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:02:26 -0500 Subject: [PATCH 50/86] Added AccountFrozenException and updated stubs --- src/main/java/edu/ithaca/dragon/bank/Account.java | 6 +++--- .../edu/ithaca/dragon/bank/AccountFrozenException.java | 9 +++++++++ src/test/java/edu/ithaca/dragon/bank/AccountTest.java | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/main/java/edu/ithaca/dragon/bank/AccountFrozenException.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 13f5f568..0cf0eab9 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -30,7 +30,7 @@ else if (id.equals("")){ * @throws IllegalArgumentException if amount is negative or has more than 2 decimals * @throws InsufficientFundsException if amount is larger than balance */ - public void withdraw(double amount) throws InsufficientFundsException{ + public void withdraw(double amount) throws InsufficientFundsException, AccountFrozenException{ if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot withdraw"); } else if (amount > balance) { @@ -45,7 +45,7 @@ public void withdraw(double amount) throws InsufficientFundsException{ * @param amount quantity to increase balance by * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places */ - public void deposit(double amount) { + public void deposit(double amount) throws AccountFrozenException{ if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot deposit"); @@ -61,7 +61,7 @@ public void deposit(double amount) { * @throws IllegalArgumentException if amount is negative or has more than 2 decimals * @throws InsufficientFundsException if amount is larger than balance */ - public void transfer(Account toAccount, double amount) throws InsufficientFundsException { + public void transfer(Account toAccount, double amount) throws InsufficientFundsException, AccountFrozenException { if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot transfer"); } else if (amount > balance) { diff --git a/src/main/java/edu/ithaca/dragon/bank/AccountFrozenException.java b/src/main/java/edu/ithaca/dragon/bank/AccountFrozenException.java new file mode 100644 index 00000000..57a7b7a4 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/AccountFrozenException.java @@ -0,0 +1,9 @@ +package edu.ithaca.dragon.bank; + +public class AccountFrozenException extends Exception{ + + public AccountFrozenException(String s){ + super(s); + } + +} \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index ac539269..9ec8de57 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -10,7 +10,7 @@ public class AccountTest { private static final double THRESHOLD = 0.001; @Test - void withdrawTest() throws InsufficientFundsException{ + void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ Account bankAccount = new CheckingAccount(1000, "a@b.com"); //non-negative amount less than or equal to balance with more than two decimal places @@ -55,7 +55,7 @@ void withdrawTest() throws InsufficientFundsException{ } @Test - void depositTest() { + void depositTest() throws AccountFrozenException { Account bankAccount = new CheckingAccount( 0, "1"); @@ -94,7 +94,7 @@ void depositTest() { } @Test - void transferTest() throws InsufficientFundsException { + void transferTest() throws InsufficientFundsException, AccountFrozenException { Account a = new CheckingAccount(1000, "a@b.com"); Account b = new CheckingAccount(0, "a@b.com"); From d9464a95e5801ecd53b8b73f3ed1d68434f60b5e Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:08:52 -0500 Subject: [PATCH 51/86] Updated withdrawTest to reflect AccountFrozenException --- .../edu/ithaca/dragon/bank/SavingsAccount.java | 2 +- .../java/edu/ithaca/dragon/bank/AccountTest.java | 15 +++++++++++++++ .../ithaca/dragon/bank/SavingsAccountTest.java | 2 +- .../java/edu/ithaca/dragon/bank/UserTest.java | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java index bf68fb4d..565fdf60 100644 --- a/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/SavingsAccount.java @@ -12,7 +12,7 @@ public SavingsAccount(double startingBalance, double interestRate, double maximu } @Override - public void withdraw(double amount) throws InsufficientFundsException { + public void withdraw(double amount) throws InsufficientFundsException, AccountFrozenException { if(amount <= maximumWithdrawal) { super.withdraw(amount); } else { diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 9ec8de57..add0b2c6 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -41,6 +41,21 @@ void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MIN_VALUE)); assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-Double.MAX_VALUE)); + bankAccount.setFrozen(true); + //Checking that you can't withdraw from frozen account + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(0)); + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(100)); + + //Check that AccountFrozen hsa higher priority than illegal argument and insufficient funds + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(5.1234)); + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(-50)); + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(1000.01)); + assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(2000.1234)); + + + + + //non-negative amount less than or equal to balance with two decimal places or less bankAccount.withdraw(0); assertEquals(1000, bankAccount.getBalance(), THRESHOLD); diff --git a/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java index a01a1c60..eda81d86 100644 --- a/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/SavingsAccountTest.java @@ -8,7 +8,7 @@ public class SavingsAccountTest { @Test - void withdrawTest() throws InsufficientFundsException{ + void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ Account a = new SavingsAccount(30, 0.5, 20, "a@b.com"); a.withdraw(10); diff --git a/src/test/java/edu/ithaca/dragon/bank/UserTest.java b/src/test/java/edu/ithaca/dragon/bank/UserTest.java index 6d0d98b6..06506469 100644 --- a/src/test/java/edu/ithaca/dragon/bank/UserTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/UserTest.java @@ -46,7 +46,7 @@ void getAccountTest() { //Tests adding account, getting account, and calling account methods by id @Test - void IntegrationTest() throws InsufficientFundsException{ + void IntegrationTest() throws InsufficientFundsException, AccountFrozenException{ String idA = "a@c.com"; String idB = "b@c.com"; Account a = new CheckingAccount(100, idA); From 91fe4a44dd2b99c7ee4236a03be5770f28f152ef Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:10:38 -0500 Subject: [PATCH 52/86] Implemented frozen account in withdraw --- src/main/java/edu/ithaca/dragon/bank/Account.java | 5 ++++- src/test/java/edu/ithaca/dragon/bank/AccountTest.java | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 0cf0eab9..b51d77a7 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -31,7 +31,10 @@ else if (id.equals("")){ * @throws InsufficientFundsException if amount is larger than balance */ public void withdraw(double amount) throws InsufficientFundsException, AccountFrozenException{ - if (!isAmountValid(amount)) { + if (isFrozen){ + throw new AccountFrozenException("Account is frozen"); + } + else if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot withdraw"); } else if (amount > balance) { throw new InsufficientFundsException("Not enough money"); diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index add0b2c6..c22f4e0e 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -46,7 +46,7 @@ void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(0)); assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(100)); - //Check that AccountFrozen hsa higher priority than illegal argument and insufficient funds + //Check that AccountFrozen has higher priority than illegal argument and insufficient funds assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(5.1234)); assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(-50)); assertThrows(AccountFrozenException.class, () -> bankAccount.withdraw(1000.01)); @@ -54,7 +54,7 @@ void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ - + bankAccount.setFrozen(false); //non-negative amount less than or equal to balance with two decimal places or less bankAccount.withdraw(0); From 21c89b138d55cf47a805ef2f0452bead90e3b962 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:13:16 -0500 Subject: [PATCH 53/86] Added account frozen to deposit tests --- .../java/edu/ithaca/dragon/bank/AccountTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index c22f4e0e..0acd1e15 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -105,6 +105,18 @@ void depositTest() throws AccountFrozenException { bankAccount.deposit(419.5); assertEquals(430.5, bankAccount.getBalance(), THRESHOLD); + bankAccount.setFrozen(true); + //Checking that account frozen gets thrown with basic deposits + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(0)); + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(100)); + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(50.53)); + + //Checking that account frozen has higher priority than IllegalArgument + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(-2)); + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(100.1234)); + assertThrows(AccountFrozenException.class, () -> bankAccount.deposit(-25.087)); + + } From 3f4fd0ea6040eb871bcb938b0cfc6317f707b4a4 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:14:30 -0500 Subject: [PATCH 54/86] Implemented deposit with frozen accounts --- src/main/java/edu/ithaca/dragon/bank/Account.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index b51d77a7..dcfd9145 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -49,8 +49,10 @@ else if (!isAmountValid(amount)) { * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places */ public void deposit(double amount) throws AccountFrozenException{ - - if (!isAmountValid(amount)) { + if (isFrozen){ + throw new AccountFrozenException("Account is frozen"); + } + else if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot deposit"); } else { balance += amount; From 07da95cb273e8b504acd864ec33fd83f1839cb2e Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:21:30 -0500 Subject: [PATCH 55/86] Added Account Frozen tests to AccountTest --- .../edu/ithaca/dragon/bank/AccountTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 0acd1e15..7635cd48 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -168,6 +168,29 @@ void transferTest() throws InsufficientFundsException, AccountFrozenException { a.transfer(b, 1); assertEquals(0, a.getBalance(), THRESHOLD); assertEquals(1000, b.getBalance(), THRESHOLD); + + //Setting a's balance back to 1000, and b's to 0 + b.transfer(a, 1000); + //checking with the sender frozen + a.setFrozen(true); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 5)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 10.45)); + //checking with both frozen + b.setFrozen(true); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 0)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 6.34)); + //checking with only the receiver frozen + a.setFrozen(false); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 20)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50.85)); + //Checking that Account Frozen has higher priority than other errors + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 1000.01)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50000)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, -30)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 0.12345)); + + + } @Test From 2bbb8c8c191da318e8d6d2809cfe3c3c1266c3e4 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:22:50 -0500 Subject: [PATCH 56/86] Added Account Frozen tests to AccountTest --- .../java/edu/ithaca/dragon/bank/AccountTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index 7635cd48..bf49c062 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -183,7 +183,18 @@ void transferTest() throws InsufficientFundsException, AccountFrozenException { a.setFrozen(false); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 20)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50.85)); - //Checking that Account Frozen has higher priority than other errors + //Checking that Account Frozen has higher priority than other errors, with reciever frozen + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 1000.01)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50000)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, -30)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 0.12345)); + //Checking that Account Frozen has higher priority than other errors with both frozen + a.setFrozen(true); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 1000.01)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50000)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, -30)); + assertThrows(AccountFrozenException.class, () -> a.transfer(b, 0.12345)); + //Checking that Account Frozen has higher priority than other errors with sender frozen assertThrows(AccountFrozenException.class, () -> a.transfer(b, 1000.01)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50000)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, -30)); From 7da4fd4b24ee1489295b2f0ffee07e59b4e9f331 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:24:09 -0500 Subject: [PATCH 57/86] Implemented transfer with AccountFrozenException --- src/main/java/edu/ithaca/dragon/bank/Account.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index dcfd9145..55fab9a3 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -67,7 +67,10 @@ else if (!isAmountValid(amount)) { * @throws InsufficientFundsException if amount is larger than balance */ public void transfer(Account toAccount, double amount) throws InsufficientFundsException, AccountFrozenException { - if (!isAmountValid(amount)) { + if (this.isFrozen || toAccount.isFrozen){ + throw new AccountFrozenException("Account is frozen"); + } + else if (!isAmountValid(amount)) { throw new IllegalArgumentException("Amount: " + amount + " is invalid, cannot transfer"); } else if (amount > balance) { throw new InsufficientFundsException("Not enough money"); From 8a3d4d75faa7525fdbcef073c78f0e3069cc3b3b Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 16:44:29 -0500 Subject: [PATCH 58/86] Refactored Admin to use CentralBank rather than a collection of Accounts --- src/main/java/edu/ithaca/dragon/bank/Admin.java | 16 ++++++++-------- .../edu/ithaca/dragon/bank/CentralBank.java | 9 +++++++++ .../java/edu/ithaca/dragon/bank/AdminTest.java | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index e420b88e..44fbb6a9 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -4,14 +4,14 @@ import java.util.Iterator; public class Admin implements AdminAPI { - Collection accounts; + CentralBank bank; /** * creates an Admin account that knows what accounts it controls - * @param accounts the accounts that Admin must act on + * @param bank the CentralBank that Admin must act on */ - public Admin(Collection accounts){ - this.accounts = accounts; + public Admin(CentralBank bank){ + this.bank = bank; } @Override @@ -27,7 +27,7 @@ public Collection findAcctIdsWithSuspiciousActivity() { @Override public void freezeAccount(String acctId) throws IllegalArgumentException { boolean accountFound = false; - Iterator itr = this.accounts.iterator(); + Iterator itr = this.bank.accounts.iterator(); while (itr.hasNext()){ Account current = itr.next(); if (current.getID()== acctId){ @@ -44,7 +44,7 @@ public void freezeAccount(String acctId) throws IllegalArgumentException { @Override public void unfreezeAcct(String acctId) throws IllegalArgumentException { boolean accountFound = false; - Iterator itr = this.accounts.iterator(); + Iterator itr = this.bank.accounts.iterator(); while (itr.hasNext()){ Account current = itr.next(); if (current.getID()== acctId){ @@ -58,7 +58,7 @@ public void unfreezeAcct(String acctId) throws IllegalArgumentException { } - public Collection getAccounts(){ - return this.accounts; + public CentralBank getBank(){ + return this.bank; } } diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index 0802a2e3..a77675a6 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -1,5 +1,6 @@ package edu.ithaca.dragon.bank; +import java.util.ArrayList; import java.util.Collection; public class CentralBank { @@ -9,6 +10,14 @@ public class CentralBank { Collection admins; Collection users; + public CentralBank(){ + atms = new ArrayList(); + accounts = new ArrayList(); + admins = new ArrayList(); + users = new ArrayList(); + } + + public void withdraw(Account account, double amount) { } diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 81b0fd46..9d5f5f07 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -15,12 +15,14 @@ public class AdminTest { @Test void constructorTest() { Admin admin = new Admin(null); - assertEquals(null, admin.getAccounts()); + assertEquals(null, admin.getBank()); Collection testCollection = new ArrayList(); testCollection.add(new CheckingAccount(50, "1234")); testCollection.add(new CheckingAccount(100,"123")); - admin = new Admin(testCollection); - assertEquals(testCollection,admin.getAccounts()); + CentralBank testBank = new CentralBank(); + testBank.accounts = testCollection; + admin = new Admin(testBank); + assertEquals(testBank, admin.getBank()); } @@ -31,7 +33,9 @@ void freezeAccountTest() { Collection collection = new ArrayList(); collection.add(abcAcc); collection.add(xyzAcc); - Admin admin = new Admin(collection); + CentralBank testBank = new CentralBank(); + testBank.accounts = collection; + Admin admin = new Admin(testBank); //Checking false frozen status after no change assertEquals(false, abcAcc.getFrozenStatus()); assertEquals(false, xyzAcc.getFrozenStatus()); @@ -59,7 +63,9 @@ void unFreezeAccountTest() { Collection collection = new ArrayList(); collection.add(abcAcc); collection.add(xyzAcc); - Admin admin = new Admin(collection); + CentralBank testBank = new CentralBank(); + testBank.accounts = collection; + Admin admin = new Admin(testBank); //Checking true frozen status after change abcAcc.setFrozen(true); xyzAcc.setFrozen(true); @@ -84,4 +90,5 @@ void unFreezeAccountTest() { + } From d29af73be4c99953b5cafba2522635117d117e25 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 17:19:08 -0500 Subject: [PATCH 59/86] Added calcTotalAssets tests --- .../java/edu/ithaca/dragon/bank/AdminTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 9d5f5f07..2c6540f4 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -88,6 +88,24 @@ void unFreezeAccountTest() { } + @Test + void calcTotalAssetsTest(){ + CentralBank testBank = new CentralBank(); + Admin admin = new Admin(testBank); + //Checking with no accounts + assertEquals(0, admin.calcTotalAssets()); + //Checking with one account + testBank.accounts.add(new CheckingAccount(100, "abc")); + assertEquals(100, admin.calcTotalAssets()); + //Checking with multiple accounts + testBank.accounts.add(new CheckingAccount(50.65, "xyz")); + testBank.accounts.add(new CheckingAccount(156, "def")); + assertEquals(306.65, admin.calcTotalAssets()); + //Check when there is an account with 0 assets + testBank.accounts.add(new CheckingAccount(0, "ghi")); + assertEquals(306.65, admin.calcTotalAssets()); + } + From 0fcd68f4ebad424890807756df95964cdf548130 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 17:25:18 -0500 Subject: [PATCH 60/86] Implemented calcTotalAssets --- src/main/java/edu/ithaca/dragon/bank/Admin.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index 44fbb6a9..87756ba9 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -16,7 +16,13 @@ public Admin(CentralBank bank){ @Override public double calcTotalAssets() { - return 0; + double total = 0; + Iterator itr = this.bank.accounts.iterator(); + while (itr.hasNext()){ + Account current = itr.next(); + total += current.getBalance(); + } + return total; } @Override From a45205f567f285d81fc25fed4d499ecac8a1fb0f Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 17:40:47 -0500 Subject: [PATCH 61/86] Added integration test for Admin --- .../edu/ithaca/dragon/bank/AdminTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 2c6540f4..14e2cd46 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -106,6 +106,34 @@ void calcTotalAssetsTest(){ assertEquals(306.65, admin.calcTotalAssets()); } + @Test + void integrationTest() throws InsufficientFundsException, AccountFrozenException{ + //Meant to test that freeze/unfreeze can work in conjunction, as well as calcTotalAssets working with the Account methods + Account abcAcc = new CheckingAccount(500, "abc"); + Account xyzAcc = new CheckingAccount(500, "xyz"); + Collection collection = new ArrayList(); + collection.add(abcAcc); + collection.add(xyzAcc); + CentralBank testBank = new CentralBank(); + testBank.accounts = collection; + Admin admin = new Admin(testBank); + assertEquals(1000, admin.calcTotalAssets()); + abcAcc.transfer(xyzAcc, 300); + assertEquals(1000, admin.calcTotalAssets()); + abcAcc.deposit(300); + assertEquals(1300, admin.calcTotalAssets()); + xyzAcc.withdraw(100.55); + assertEquals(1199.45, admin.calcTotalAssets()); + + admin.freezeAccount("abc"); + assertThrows(AccountFrozenException.class, ()->abcAcc.deposit(50)); + admin.unfreezeAcct("abc"); + abcAcc.deposit(50); + assertEquals(1249.45, admin.calcTotalAssets()); + + + } + From 27b3f9ea3dbe58848062bacad91e16bf11a12235 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Mon, 10 Feb 2020 18:02:00 -0500 Subject: [PATCH 62/86] Added sequence diagram to readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25a168df..4773e618 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 -Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing +Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing + +Sequence Diagram (Josh): Admin, Account https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing From d21c6e96fd2818faaf3a02a140ebc836f1bfabae Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 09:16:22 -0500 Subject: [PATCH 63/86] removed redundant Teller method headers --- .../java/edu/ithaca/dragon/bank/Teller.java | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 4955c408..2e10c717 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -1,8 +1,6 @@ package edu.ithaca.dragon.bank; public class Teller extends ATM implements AdvancedAPI { - - @Override public void createAccount(String acctId, double startingBalance) { @@ -12,34 +10,4 @@ public void createAccount(String acctId, double startingBalance) { public void closeAccount(String acctId) { } - - @Override - public boolean confirmCredentials(String acctId, String password) { - return false; - } - - @Override - public double checkBalance(String acctId) { - return 0; - } - - @Override - public void withdraw(String acctId, double amount) throws InsufficientFundsException { - - } - - @Override - public void deposit(String acctId, double amount) { - - } - - @Override - public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { - - } - - @Override - public String transactionHistory(String acctId) { - return null; - } } From d0ab882fa7cb988f8dd4b23110182f228f67b980 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 09:32:52 -0500 Subject: [PATCH 64/86] paused to refactor CentralBank --- .../java/edu/ithaca/dragon/bank/Teller.java | 1 + .../edu/ithaca/dragon/bank/TellerTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/java/edu/ithaca/dragon/bank/TellerTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 2e10c717..f29b23d0 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -1,6 +1,7 @@ package edu.ithaca.dragon.bank; public class Teller extends ATM implements AdvancedAPI { + @Override public void createAccount(String acctId, double startingBalance) { 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..40153381 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -0,0 +1,21 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class TellerTest { + + @Test + void createAccountTest() { + CentralBank centralBank = new CentralBank(); + Map accounts = new HashMap<>(); + centralBank.accounts = accounts; + + Teller teller = new Teller(); + teller.createAccount(); + + } +} From 30f9dd5a6a8a4c92d51cc6e7bc9f0fb00125ffbe Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 09:54:54 -0500 Subject: [PATCH 65/86] createAcountTest --- .../edu/ithaca/dragon/bank/TellerTest.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 40153381..f9f626b7 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -2,20 +2,27 @@ import org.junit.jupiter.api.Test; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.rmi.NoSuchObjectException; + +import static org.junit.jupiter.api.Assertions.*; public class TellerTest { @Test - void createAccountTest() { + void createAccountTest() throws NoSuchObjectException { CentralBank centralBank = new CentralBank(); - Map accounts = new HashMap<>(); - centralBank.accounts = accounts; - Teller teller = new Teller(); - teller.createAccount(); + teller.createAccount("0", 0); + boolean found = false; + for (Account account : centralBank.accounts) { + if (account.getID().equals("0")) { + assertEquals(account, new CheckingAccount(0, "0")); + found = true; + } + } + if (!found) { + throw new NoSuchObjectException("Account not found"); + } } } From 4ece389e6d0a1f4a16e36a055ed61b251447223d Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 09:56:53 -0500 Subject: [PATCH 66/86] updating ATM --- src/main/java/edu/ithaca/dragon/bank/Teller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index f29b23d0..a3295924 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -4,7 +4,7 @@ public class Teller extends ATM implements AdvancedAPI { @Override public void createAccount(String acctId, double startingBalance) { - + new CheckingAccount(startingBalance, acctId); } @Override From f744c1fe53adcd5eb014610187d0796d6c17b4df Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 09:58:03 -0500 Subject: [PATCH 67/86] ATM now has CentralBank --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java index fa6313b1..35dfa9fc 100644 --- a/src/main/java/edu/ithaca/dragon/bank/ATM.java +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -2,6 +2,7 @@ public class ATM implements BasicAPI { + CentralBank centralBank; @Override public boolean confirmCredentials(String acctId, String password) { From fb276036cdf09f2914e0e539f090c682ab5a11c8 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 10:01:52 -0500 Subject: [PATCH 68/86] add Account --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 2 +- src/main/java/edu/ithaca/dragon/bank/Teller.java | 2 +- src/test/java/edu/ithaca/dragon/bank/TellerTest.java | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java index 35dfa9fc..51e5ec15 100644 --- a/src/main/java/edu/ithaca/dragon/bank/ATM.java +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -2,7 +2,7 @@ public class ATM implements BasicAPI { - CentralBank centralBank; + CentralBank centralBank = new CentralBank(); @Override public boolean confirmCredentials(String acctId, String password) { diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index a3295924..1c671ee5 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -4,7 +4,7 @@ public class Teller extends ATM implements AdvancedAPI { @Override public void createAccount(String acctId, double startingBalance) { - new CheckingAccount(startingBalance, acctId); + centralBank.accounts.add(new CheckingAccount(startingBalance, acctId)); } @Override diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index f9f626b7..08e41fcd 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -13,16 +13,10 @@ void createAccountTest() throws NoSuchObjectException { CentralBank centralBank = new CentralBank(); Teller teller = new Teller(); teller.createAccount("0", 0); - boolean found = false; for (Account account : centralBank.accounts) { if (account.getID().equals("0")) { assertEquals(account, new CheckingAccount(0, "0")); - found = true; } } - - if (!found) { - throw new NoSuchObjectException("Account not found"); - } } } From b042dd1546b0e44f2ce524b6f5e594d0c9b70f9e Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Tue, 11 Feb 2020 12:20:09 -0500 Subject: [PATCH 69/86] Added system test with admin, rounding issue right now that needs to be fixed --- .../java/edu/ithaca/dragon/bank/AdminTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 14e2cd46..ec60d4bd 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -130,7 +130,24 @@ void integrationTest() throws InsufficientFundsException, AccountFrozenException admin.unfreezeAcct("abc"); abcAcc.deposit(50); assertEquals(1249.45, admin.calcTotalAssets()); + } + @Test + void systemTest() throws InsufficientFundsException, AccountFrozenException{ + //Going to test that teller and admin are working properly, use teller to create new accounts and admin to find the total balance + Teller teller = new Teller(); + Admin admin = new Admin(teller.centralBank); + assertEquals(0, admin.calcTotalAssets()); + teller.createAccount("abc", 150); + assertEquals(150, admin.calcTotalAssets()); + teller.createAccount("123", 20.45); + assertEquals(170.45, admin.calcTotalAssets()); + teller.createAccount("xyz", 0); + assertEquals(170.45, admin.calcTotalAssets()); + teller.createAccount("acc", 0.14); + assertEquals(170.59, admin.calcTotalAssets()); + assertThrows(IllegalArgumentException.class, ()->teller.createAccount("account", -50)); + assertThrows(IllegalArgumentException.class, ()->teller.createAccount("ghi", 100.505)); } From d7cf46f9692a4e501a00cf1d29707b36c7ec9473 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Tue, 11 Feb 2020 12:24:14 -0500 Subject: [PATCH 70/86] Fixed rounding error --- src/main/java/edu/ithaca/dragon/bank/Admin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index 87756ba9..4c31934f 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -2,8 +2,13 @@ import java.util.Collection; import java.util.Iterator; +import java.math.RoundingMode; +import java.text.DecimalFormat; + + public class Admin implements AdminAPI { + private static DecimalFormat twoDecimals = new DecimalFormat("0.00"); CentralBank bank; /** @@ -22,6 +27,8 @@ public double calcTotalAssets() { Account current = itr.next(); total += current.getBalance(); } + total = Double.valueOf(twoDecimals.format(total)); + return total; } From 3be9ec98c1b2b274f28722ee3fb4ebecb69d9bf0 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Tue, 11 Feb 2020 13:07:54 -0500 Subject: [PATCH 71/86] Added class diagram --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4773e618..bef1bdd7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 +Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R + Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing Sequence Diagram (Josh): Admin, Account https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing From cfe15d6096636a01ce89b999a54ea421106a9393 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Tue, 11 Feb 2020 13:24:16 -0500 Subject: [PATCH 72/86] refactored to use map --- .../java/edu/ithaca/dragon/bank/Admin.java | 36 +++++----------- .../edu/ithaca/dragon/bank/CentralBank.java | 20 ++++++--- .../java/edu/ithaca/dragon/bank/Teller.java | 2 +- .../edu/ithaca/dragon/bank/AdminTest.java | 42 ++++++++++--------- .../edu/ithaca/dragon/bank/TellerTest.java | 2 +- 5 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Admin.java b/src/main/java/edu/ithaca/dragon/bank/Admin.java index 4c31934f..da659ab6 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Admin.java +++ b/src/main/java/edu/ithaca/dragon/bank/Admin.java @@ -11,6 +11,7 @@ public class Admin implements AdminAPI { private static DecimalFormat twoDecimals = new DecimalFormat("0.00"); CentralBank bank; + /** * creates an Admin account that knows what accounts it controls * @param bank the CentralBank that Admin must act on @@ -22,7 +23,7 @@ public Admin(CentralBank bank){ @Override public double calcTotalAssets() { double total = 0; - Iterator itr = this.bank.accounts.iterator(); + Iterator itr = this.bank.getAccounts().values().iterator(); while (itr.hasNext()){ Account current = itr.next(); total += current.getBalance(); @@ -39,36 +40,21 @@ public Collection findAcctIdsWithSuspiciousActivity() { @Override public void freezeAccount(String acctId) throws IllegalArgumentException { - boolean accountFound = false; - Iterator itr = this.bank.accounts.iterator(); - while (itr.hasNext()){ - Account current = itr.next(); - if (current.getID()== acctId){ - accountFound = true; - current.setFrozen(true); - } - } - if (accountFound == false){ - throw new IllegalArgumentException("String not in collection"); - } - + setAcctFreezeStatus(acctId,true); } @Override public void unfreezeAcct(String acctId) throws IllegalArgumentException { - boolean accountFound = false; - Iterator itr = this.bank.accounts.iterator(); - while (itr.hasNext()){ - Account current = itr.next(); - if (current.getID()== acctId){ - accountFound = true; - current.setFrozen(false); - } - } - if (accountFound == false){ + setAcctFreezeStatus(acctId,false); + } + + public void setAcctFreezeStatus(String acctId, boolean isFrozen) { + boolean accountFound = (bank.getAccounts().containsKey(acctId)); + if(accountFound) { + bank.getAccounts().get(acctId).setFrozen(isFrozen); + } else { throw new IllegalArgumentException("String not in collection"); } - } public CentralBank getBank(){ diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index a77675a6..c3194022 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -2,17 +2,19 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; public class CentralBank { - Collection atms; - Collection accounts; - Collection admins; - Collection users; + private Collection atms; + private Map accounts; + private Collection admins; + private Collection users; public CentralBank(){ atms = new ArrayList(); - accounts = new ArrayList(); + accounts = new HashMap(); admins = new ArrayList(); users = new ArrayList(); } @@ -42,4 +44,12 @@ public String getHistory(Account account) { return account.getHistory(); } + public void setAccounts(Map newAccounts) { + accounts = newAccounts; + } + + public Map getAccounts() { + return accounts; + } + } diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 1c671ee5..1dd30e86 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -4,7 +4,7 @@ public class Teller extends ATM implements AdvancedAPI { @Override public void createAccount(String acctId, double startingBalance) { - centralBank.accounts.add(new CheckingAccount(startingBalance, acctId)); + centralBank.getAccounts().put(acctId, new CheckingAccount(startingBalance, acctId)); } @Override diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index ec60d4bd..f6a24af0 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import static org.junit.jupiter.api.Assertions.*; @@ -16,11 +18,11 @@ public class AdminTest { void constructorTest() { Admin admin = new Admin(null); assertEquals(null, admin.getBank()); - Collection testCollection = new ArrayList(); - testCollection.add(new CheckingAccount(50, "1234")); - testCollection.add(new CheckingAccount(100,"123")); + Map testCollection = new HashMap<>(); + testCollection.put("1234", new CheckingAccount(50, "1234")); + testCollection.put("123", new CheckingAccount(100,"123")); CentralBank testBank = new CentralBank(); - testBank.accounts = testCollection; + testBank.setAccounts(testCollection); admin = new Admin(testBank); assertEquals(testBank, admin.getBank()); @@ -30,11 +32,11 @@ void constructorTest() { void freezeAccountTest() { Account abcAcc = new CheckingAccount(500, "abc"); Account xyzAcc = new CheckingAccount(500, "xyz"); - Collection collection = new ArrayList(); - collection.add(abcAcc); - collection.add(xyzAcc); + Map collection = new HashMap<>(); + collection.put(abcAcc.getID(), abcAcc); + collection.put(xyzAcc.getID(), xyzAcc); CentralBank testBank = new CentralBank(); - testBank.accounts = collection; + testBank.setAccounts(collection); Admin admin = new Admin(testBank); //Checking false frozen status after no change assertEquals(false, abcAcc.getFrozenStatus()); @@ -60,11 +62,11 @@ void freezeAccountTest() { void unFreezeAccountTest() { Account abcAcc = new CheckingAccount(500, "abc"); Account xyzAcc = new CheckingAccount(500, "xyz"); - Collection collection = new ArrayList(); - collection.add(abcAcc); - collection.add(xyzAcc); + Map collection = new HashMap<>(); + collection.put(abcAcc.getID(), abcAcc); + collection.put(xyzAcc.getID(), xyzAcc); CentralBank testBank = new CentralBank(); - testBank.accounts = collection; + testBank.setAccounts(collection); Admin admin = new Admin(testBank); //Checking true frozen status after change abcAcc.setFrozen(true); @@ -95,14 +97,14 @@ void calcTotalAssetsTest(){ //Checking with no accounts assertEquals(0, admin.calcTotalAssets()); //Checking with one account - testBank.accounts.add(new CheckingAccount(100, "abc")); + testBank.getAccounts().put("abc", new CheckingAccount(100, "abc")); assertEquals(100, admin.calcTotalAssets()); //Checking with multiple accounts - testBank.accounts.add(new CheckingAccount(50.65, "xyz")); - testBank.accounts.add(new CheckingAccount(156, "def")); + testBank.getAccounts().put("xyz", new CheckingAccount(50.65, "xyz")); + testBank.getAccounts().put("def",new CheckingAccount(156, "def")); assertEquals(306.65, admin.calcTotalAssets()); //Check when there is an account with 0 assets - testBank.accounts.add(new CheckingAccount(0, "ghi")); + testBank.getAccounts().put("ghi", new CheckingAccount(0, "ghi")); assertEquals(306.65, admin.calcTotalAssets()); } @@ -111,11 +113,11 @@ void integrationTest() throws InsufficientFundsException, AccountFrozenException //Meant to test that freeze/unfreeze can work in conjunction, as well as calcTotalAssets working with the Account methods Account abcAcc = new CheckingAccount(500, "abc"); Account xyzAcc = new CheckingAccount(500, "xyz"); - Collection collection = new ArrayList(); - collection.add(abcAcc); - collection.add(xyzAcc); + Map collection = new HashMap<>(); + collection.put(abcAcc.getID(), abcAcc); + collection.put(xyzAcc.getID(), xyzAcc); CentralBank testBank = new CentralBank(); - testBank.accounts = collection; + testBank.setAccounts(collection); Admin admin = new Admin(testBank); assertEquals(1000, admin.calcTotalAssets()); abcAcc.transfer(xyzAcc, 300); diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 08e41fcd..09865565 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -13,7 +13,7 @@ void createAccountTest() throws NoSuchObjectException { CentralBank centralBank = new CentralBank(); Teller teller = new Teller(); teller.createAccount("0", 0); - for (Account account : centralBank.accounts) { + for (Account account : centralBank.getAccounts().values()) { if (account.getID().equals("0")) { assertEquals(account, new CheckingAccount(0, "0")); } From f4ceb2c1a337900c39522e7b80748d5170f43bc1 Mon Sep 17 00:00:00 2001 From: eostendarp <42873051+eostendarp@users.noreply.github.com> Date: Tue, 11 Feb 2020 13:42:23 -0500 Subject: [PATCH 73/86] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index bef1bdd7..cdd770ef 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,4 @@ Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1 Sequence Diagram (Josh): Admin, Account https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing - - +Sequence Diagram (Erich): https://drive.google.com/file/d/1tcE_ITNZHlpZ7IzYDILuwuuKqsxNMex5/view?usp=sharing From f69af25a96935fc1055d47566a986ec300b6e70d Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 13:44:51 -0500 Subject: [PATCH 74/86] removed depricated teller code --- src/main/java/edu/ithaca/dragon/bank/Teller.java | 1 - src/test/java/edu/ithaca/dragon/bank/TellerTest.java | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 1dd30e86..4a9ab0af 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -4,7 +4,6 @@ public class Teller extends ATM implements AdvancedAPI { @Override public void createAccount(String acctId, double startingBalance) { - centralBank.getAccounts().put(acctId, new CheckingAccount(startingBalance, acctId)); } @Override diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 09865565..1921dc07 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -2,21 +2,11 @@ import org.junit.jupiter.api.Test; -import java.rmi.NoSuchObjectException; - import static org.junit.jupiter.api.Assertions.*; public class TellerTest { @Test - void createAccountTest() throws NoSuchObjectException { - CentralBank centralBank = new CentralBank(); - Teller teller = new Teller(); - teller.createAccount("0", 0); - for (Account account : centralBank.getAccounts().values()) { - if (account.getID().equals("0")) { - assertEquals(account, new CheckingAccount(0, "0")); - } - } + void createAccountTest() { } } From a67c52e65618034b32c39eba008565a499114726 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 13:49:35 -0500 Subject: [PATCH 75/86] added createAccontTest --- src/test/java/edu/ithaca/dragon/bank/TellerTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 1921dc07..7a13ba79 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -8,5 +8,16 @@ public class TellerTest { @Test void createAccountTest() { + Teller teller = new Teller(); + teller.createAccount("0", 0); + + assertNotNull(teller.centralBank.getAccounts().get("0")); + + teller.createAccount("1", 10); + teller.createAccount("2", 20); + teller.createAccount("3", 150); + + assertNotNull(teller.centralBank.getAccounts().get("2")); + } } From acb043a97eacf29f6312f1ca6e3bae1b106bb7ff Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Tue, 11 Feb 2020 13:50:03 -0500 Subject: [PATCH 76/86] added ATM tests and probably caused a bunch of merge conflicts --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 10 ++- .../java/edu/ithaca/dragon/bank/Teller.java | 4 ++ .../java/edu/ithaca/dragon/bank/ATMTest.java | 67 +++++++++++++++++++ .../edu/ithaca/dragon/bank/AdminTest.java | 5 +- .../edu/ithaca/dragon/bank/TellerTest.java | 2 +- 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/test/java/edu/ithaca/dragon/bank/ATMTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java index 51e5ec15..811e3e58 100644 --- a/src/main/java/edu/ithaca/dragon/bank/ATM.java +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -2,7 +2,11 @@ public class ATM implements BasicAPI { - CentralBank centralBank = new CentralBank(); + protected CentralBank centralBank; + + public ATM(CentralBank bank) { + centralBank = bank; + } @Override public boolean confirmCredentials(String acctId, String password) { @@ -33,4 +37,8 @@ public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, doub public String transactionHistory(String acctId) { return null; } + + public CentralBank getCentralBank() { + return centralBank; + } } diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 1dd30e86..aac43129 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -2,6 +2,10 @@ public class Teller extends ATM implements AdvancedAPI { + public Teller(CentralBank bank) { + super(bank); + } + @Override public void createAccount(String acctId, double startingBalance) { centralBank.getAccounts().put(acctId, new CheckingAccount(startingBalance, acctId)); 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..c15235c9 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/ATMTest.java @@ -0,0 +1,67 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class ATMTest { + + @Test + void constructorTest() { + CentralBank bank = new CentralBank(); + ATM a = new ATM(bank); + + assertEquals(bank, a.getCentralBank()); + } + + @Test + void checkBalanceTest() { + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + ATM a = new ATM(bank); + + assertEquals(100, a.checkBalance("abc")); + } + + @Test + void withdrawTest() throws InsufficientFundsException{ + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + ATM a = new ATM(bank); + + a.withdraw("abc", 50); + assertEquals(50, a.checkBalance("abc")); + assertThrows(InsufficientFundsException.class, () -> a.withdraw("abc", 100)); + assertThrows(IllegalArgumentException.class, () -> a.withdraw( "help", 100)); + + } + + @Test + void depositTest() { + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + ATM a = new ATM(bank); + + a.deposit("abc", 100); + assertEquals(200, a.checkBalance("abc")); + assertThrows(IllegalArgumentException.class, () -> a.deposit( "help", 100)); + + } + + @Test + void transferTest() throws InsufficientFundsException{ + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + bank.getAccounts().put("def", new CheckingAccount(100, "abc")); + ATM a = new ATM(bank); + + a.transfer("abc", "def", 50); + assertEquals(50, a.checkBalance("abc")); + assertEquals(150, a.checkBalance("def")); + + assertThrows(InsufficientFundsException.class, () -> a.transfer("abc", "def", 200)); + assertThrows(IllegalArgumentException.class, () -> a.transfer("abc", "help", 100)); + } + + + +} diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index f6a24af0..15dd7f72 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -137,8 +137,9 @@ void integrationTest() throws InsufficientFundsException, AccountFrozenException @Test void systemTest() throws InsufficientFundsException, AccountFrozenException{ //Going to test that teller and admin are working properly, use teller to create new accounts and admin to find the total balance - Teller teller = new Teller(); - Admin admin = new Admin(teller.centralBank); + CentralBank bank = new CentralBank(); + Teller teller = new Teller(bank); + Admin admin = new Admin(bank); assertEquals(0, admin.calcTotalAssets()); teller.createAccount("abc", 150); assertEquals(150, admin.calcTotalAssets()); diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 09865565..0b78d3b5 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -11,7 +11,7 @@ public class TellerTest { @Test void createAccountTest() throws NoSuchObjectException { CentralBank centralBank = new CentralBank(); - Teller teller = new Teller(); + Teller teller = new Teller(centralBank); teller.createAccount("0", 0); for (Account account : centralBank.getAccounts().values()) { if (account.getID().equals("0")) { From 90789381163625e37351a141815b7b4a22b86dd4 Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 13:51:04 -0500 Subject: [PATCH 77/86] implemented createAccount --- src/main/java/edu/ithaca/dragon/bank/Teller.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 4a9ab0af..1dd30e86 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -4,6 +4,7 @@ public class Teller extends ATM implements AdvancedAPI { @Override public void createAccount(String acctId, double startingBalance) { + centralBank.getAccounts().put(acctId, new CheckingAccount(startingBalance, acctId)); } @Override From 2fa409290cfdbb4bcd879b3dbb100abcf5c9b4a4 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Tue, 11 Feb 2020 13:59:01 -0500 Subject: [PATCH 78/86] added central bank tests --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 3 +- .../edu/ithaca/dragon/bank/CentralBank.java | 18 +++--- .../ithaca/dragon/bank/CentralBankTest.java | 55 +++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java index 811e3e58..31b10696 100644 --- a/src/main/java/edu/ithaca/dragon/bank/ATM.java +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -15,7 +15,8 @@ public boolean confirmCredentials(String acctId, String password) { @Override public double checkBalance(String acctId) { - return 0; + + return centralBank.checkBalance(acctId); } @Override diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index c3194022..83a2eb1f 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -20,28 +20,28 @@ public CentralBank(){ } - public void withdraw(Account account, double amount) { + public void withdraw(String account, double amount) { } - public void deposit(Account account, double amount) { + public void deposit(String account, double amount) { } - public void transfer(Account fromAccount, Account toAccount, double amount) { + public void transfer(String fromAccount, String toAccount, double amount) { } - public String getCredentials(Account account) { - return account.getCredentials(); + public String getCredentials(String account) { + return accounts.get(account).getCredentials(); } - public double getBalance(Account account) { - return account.getBalance(); + public double checkBalance(String account) { + return accounts.get(account).getBalance(); } - public String getHistory(Account account) { - return account.getHistory(); + public String getHistory(String account) { + return accounts.get(account).getHistory(); } public void setAccounts(Map newAccounts) { 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..a2b271b2 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java @@ -0,0 +1,55 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class CentralBankTest { + + @Test + void constructorTest() { + CentralBank bank = new CentralBank(); + + assertEquals(0, bank.getAccounts().size()); + } + + + @Test + void withdrawTest() throws InsufficientFundsException{ + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + + bank.withdraw("abc", 50); + assertEquals(50, bank.checkBalance("abc")); + assertThrows(InsufficientFundsException.class, () -> bank.withdraw("abc", 100)); + assertThrows(IllegalArgumentException.class, () -> bank.withdraw( "help", 100)); + + } + + @Test + void depositTest() { + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + + + bank.deposit("abc", 100); + assertEquals(200, bank.checkBalance("abc")); + assertThrows(IllegalArgumentException.class, () -> bank.deposit( "help", 100)); + + } + + @Test + void transferTest() throws InsufficientFundsException{ + CentralBank bank = new CentralBank(); + bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); + bank.getAccounts().put("def", new CheckingAccount(100, "abc")); + + bank.transfer("abc", "def", 50); + assertEquals(50, bank.checkBalance("abc")); + assertEquals(150, bank.checkBalance("def")); + + assertThrows(InsufficientFundsException.class, () -> bank.transfer("abc", "def", 200)); + assertThrows(IllegalArgumentException.class, () -> bank.transfer("abc", "help", 100)); + } + +} From eb7f0b3d665647b66f3fe856400633bdda95369d Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 13:59:47 -0500 Subject: [PATCH 79/86] added closeAccountTest --- .../edu/ithaca/dragon/bank/TellerTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java index 7a13ba79..914d5601 100644 --- a/src/test/java/edu/ithaca/dragon/bank/TellerTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/TellerTest.java @@ -2,6 +2,8 @@ import org.junit.jupiter.api.Test; +import java.util.NoSuchElementException; + import static org.junit.jupiter.api.Assertions.*; public class TellerTest { @@ -18,6 +20,28 @@ void createAccountTest() { teller.createAccount("3", 150); assertNotNull(teller.centralBank.getAccounts().get("2")); + } + + @Test + void closeAccountTest() { + Teller teller = new Teller(); + + assertThrows(NoSuchElementException.class, () -> teller.closeAccount("0")); + + teller.createAccount("0", 0); + + assertThrows(NoSuchElementException.class, () -> teller.closeAccount("1")); + + teller.createAccount("1", 123); + teller.createAccount("2", 967); + + teller.closeAccount("0"); + assertNull(teller.centralBank.getAccounts().get("0")); + + teller.closeAccount("1"); + assertNull(teller.centralBank.getAccounts().get("1")); + teller.closeAccount("2"); + assertNull(teller.centralBank.getAccounts().get("2")); } } From 732274ac58cbddf14b84d871514ea81de054870e Mon Sep 17 00:00:00 2001 From: eostendarp Date: Tue, 11 Feb 2020 14:04:33 -0500 Subject: [PATCH 80/86] implemented closeAccount --- src/main/java/edu/ithaca/dragon/bank/Teller.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Teller.java b/src/main/java/edu/ithaca/dragon/bank/Teller.java index 1dd30e86..6fda4934 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Teller.java +++ b/src/main/java/edu/ithaca/dragon/bank/Teller.java @@ -1,5 +1,8 @@ package edu.ithaca.dragon.bank; +import java.rmi.NoSuchObjectException; +import java.util.NoSuchElementException; + public class Teller extends ATM implements AdvancedAPI { @Override @@ -9,6 +12,9 @@ public void createAccount(String acctId, double startingBalance) { @Override public void closeAccount(String acctId) { - + Account account = centralBank.getAccounts().remove(acctId); + if (account == null) { + throw new NoSuchElementException("That account does not exist"); + } } } From 21d50daae27f6b86198b5ad10d7120320858c7a4 Mon Sep 17 00:00:00 2001 From: Blarfnip Date: Tue, 11 Feb 2020 14:11:20 -0500 Subject: [PATCH 81/86] implemented ATM and CentralBank with basic tests --- src/main/java/edu/ithaca/dragon/bank/ATM.java | 12 +++++------ .../java/edu/ithaca/dragon/bank/BasicAPI.java | 6 +++--- .../edu/ithaca/dragon/bank/CentralBank.java | 15 +++++++++----- .../java/edu/ithaca/dragon/bank/ATMTest.java | 6 +++--- .../ithaca/dragon/bank/CentralBankTest.java | 20 +++++++++++++++---- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/ATM.java b/src/main/java/edu/ithaca/dragon/bank/ATM.java index 31b10696..6e21a09b 100644 --- a/src/main/java/edu/ithaca/dragon/bank/ATM.java +++ b/src/main/java/edu/ithaca/dragon/bank/ATM.java @@ -20,18 +20,18 @@ public double checkBalance(String acctId) { } @Override - public void withdraw(String acctId, double amount) throws InsufficientFundsException { - + public void withdraw(String acctId, double amount) throws AccountFrozenException, InsufficientFundsException { + centralBank.withdraw(acctId, amount); } @Override - public void deposit(String acctId, double amount) { - + public void deposit(String acctId, double amount) throws AccountFrozenException { + centralBank.deposit(acctId, amount); } @Override - public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { - + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException, AccountFrozenException { + centralBank.transfer(acctIdToWithdrawFrom, acctIdToDepositTo, amount); } @Override diff --git a/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java index bd65b941..9231b8ce 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java +++ b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java @@ -7,11 +7,11 @@ public interface BasicAPI { double checkBalance(String acctId); - void withdraw(String acctId, double amount) throws InsufficientFundsException; + void withdraw(String acctId, double amount) throws InsufficientFundsException, AccountFrozenException; - void deposit(String acctId, double amount); + void deposit(String acctId, double amount) throws AccountFrozenException; - void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException; + void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException, AccountFrozenException; String 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 index 83a2eb1f..4ba330d3 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -20,16 +20,21 @@ public CentralBank(){ } - public void withdraw(String account, double amount) { - + public void withdraw(String account, double amount) throws InsufficientFundsException, AccountFrozenException{ + if(!accounts.containsKey(account)) throw new IllegalArgumentException("No Account with ID: " + account); + accounts.get(account).withdraw(amount); } - public void deposit(String account, double amount) { - + public void deposit(String account, double amount) throws AccountFrozenException{ + if(!accounts.containsKey(account)) throw new IllegalArgumentException("No Account with ID: " + account); + accounts.get(account).deposit(amount); } - public void transfer(String fromAccount, String toAccount, double amount) { + public void transfer(String fromAccount, String toAccount, double amount) throws InsufficientFundsException, AccountFrozenException{ + if(!accounts.containsKey(fromAccount)) throw new IllegalArgumentException("No Account with ID: " + fromAccount); + if(!accounts.containsKey(toAccount)) throw new IllegalArgumentException("No Account with ID: " + toAccount); + accounts.get(fromAccount).transfer(accounts.get(toAccount), amount); } public String getCredentials(String account) { diff --git a/src/test/java/edu/ithaca/dragon/bank/ATMTest.java b/src/test/java/edu/ithaca/dragon/bank/ATMTest.java index c15235c9..3e608e54 100644 --- a/src/test/java/edu/ithaca/dragon/bank/ATMTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/ATMTest.java @@ -23,7 +23,7 @@ void checkBalanceTest() { } @Test - void withdrawTest() throws InsufficientFundsException{ + void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); ATM a = new ATM(bank); @@ -36,7 +36,7 @@ void withdrawTest() throws InsufficientFundsException{ } @Test - void depositTest() { + void depositTest() throws AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); ATM a = new ATM(bank); @@ -48,7 +48,7 @@ void depositTest() { } @Test - void transferTest() throws InsufficientFundsException{ + void transferTest() throws InsufficientFundsException, AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); bank.getAccounts().put("def", new CheckingAccount(100, "abc")); diff --git a/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java index a2b271b2..2e9cb45d 100644 --- a/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java @@ -15,7 +15,7 @@ void constructorTest() { @Test - void withdrawTest() throws InsufficientFundsException{ + void withdrawTest() throws InsufficientFundsException, AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); @@ -23,11 +23,13 @@ void withdrawTest() throws InsufficientFundsException{ assertEquals(50, bank.checkBalance("abc")); assertThrows(InsufficientFundsException.class, () -> bank.withdraw("abc", 100)); assertThrows(IllegalArgumentException.class, () -> bank.withdraw( "help", 100)); + bank.getAccounts().get("abc").setFrozen(true); + assertThrows(AccountFrozenException.class, () -> bank.withdraw( "abc", 100)); } @Test - void depositTest() { + void depositTest() throws AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); @@ -35,19 +37,29 @@ void depositTest() { bank.deposit("abc", 100); assertEquals(200, bank.checkBalance("abc")); assertThrows(IllegalArgumentException.class, () -> bank.deposit( "help", 100)); + bank.getAccounts().get("abc").setFrozen(true); + assertThrows(AccountFrozenException.class, () -> bank.deposit( "abc", 100)); } @Test - void transferTest() throws InsufficientFundsException{ + void transferTest() throws InsufficientFundsException, AccountFrozenException{ CentralBank bank = new CentralBank(); bank.getAccounts().put("abc", new CheckingAccount(100, "abc")); - bank.getAccounts().put("def", new CheckingAccount(100, "abc")); + bank.getAccounts().put("def", new CheckingAccount(100, "def")); bank.transfer("abc", "def", 50); assertEquals(50, bank.checkBalance("abc")); assertEquals(150, bank.checkBalance("def")); + bank.getAccounts().get("abc").setFrozen(true); + assertThrows(AccountFrozenException.class, () -> bank.transfer( "abc", "def", 100)); + bank.getAccounts().get("abc").setFrozen(false); + bank.getAccounts().get("def").setFrozen(true); + assertThrows(AccountFrozenException.class, () -> bank.transfer( "abc", "def", 100)); + bank.getAccounts().get("def").setFrozen(false); + + assertThrows(InsufficientFundsException.class, () -> bank.transfer("abc", "def", 200)); assertThrows(IllegalArgumentException.class, () -> bank.transfer("abc", "help", 100)); } From 18de704a696981117110a8dfe593321713ebee92 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Tue, 11 Feb 2020 15:23:31 -0500 Subject: [PATCH 82/86] Refactored Admin's system test, labeled old system test as an integration test --- README.md | 2 +- .../edu/ithaca/dragon/bank/AdminTest.java | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index cdd770ef..52aee11f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,6 @@ Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing -Sequence Diagram (Josh): Admin, Account https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing +Sequence Diagram (Josh): Admin, Account, CentralBank https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing Sequence Diagram (Erich): https://drive.google.com/file/d/1tcE_ITNZHlpZ7IzYDILuwuuKqsxNMex5/view?usp=sharing diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 15dd7f72..98c96666 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -108,34 +108,10 @@ void calcTotalAssetsTest(){ assertEquals(306.65, admin.calcTotalAssets()); } - @Test - void integrationTest() throws InsufficientFundsException, AccountFrozenException{ - //Meant to test that freeze/unfreeze can work in conjunction, as well as calcTotalAssets working with the Account methods - Account abcAcc = new CheckingAccount(500, "abc"); - Account xyzAcc = new CheckingAccount(500, "xyz"); - Map collection = new HashMap<>(); - collection.put(abcAcc.getID(), abcAcc); - collection.put(xyzAcc.getID(), xyzAcc); - CentralBank testBank = new CentralBank(); - testBank.setAccounts(collection); - Admin admin = new Admin(testBank); - assertEquals(1000, admin.calcTotalAssets()); - abcAcc.transfer(xyzAcc, 300); - assertEquals(1000, admin.calcTotalAssets()); - abcAcc.deposit(300); - assertEquals(1300, admin.calcTotalAssets()); - xyzAcc.withdraw(100.55); - assertEquals(1199.45, admin.calcTotalAssets()); - admin.freezeAccount("abc"); - assertThrows(AccountFrozenException.class, ()->abcAcc.deposit(50)); - admin.unfreezeAcct("abc"); - abcAcc.deposit(50); - assertEquals(1249.45, admin.calcTotalAssets()); - } @Test - void systemTest() throws InsufficientFundsException, AccountFrozenException{ + void integrationTest() throws InsufficientFundsException, AccountFrozenException{ //Going to test that teller and admin are working properly, use teller to create new accounts and admin to find the total balance CentralBank bank = new CentralBank(); Teller teller = new Teller(bank); @@ -154,6 +130,34 @@ void systemTest() throws InsufficientFundsException, AccountFrozenException{ } + @Test + void systemTest() throws InsufficientFundsException, AccountFrozenException{ + //Meant to test that freeze/unfreeze can work in conjunction, as well as calcTotalAssets working with the Account methods + CentralBank testBank = new CentralBank(); + Teller teller = new Teller(testBank); + teller.createAccount("abc", 500); + teller.createAccount("xyz", 500); + Admin admin = new Admin(testBank); + assertEquals(1000, admin.calcTotalAssets()); + teller.transfer("abc", "xyz", 200); + assertEquals(1000, admin.calcTotalAssets()); + teller.deposit("abc",300); + assertEquals(1300, admin.calcTotalAssets()); + teller.withdraw("xyz",100.55); + assertEquals(1199.45, admin.calcTotalAssets()); + + admin.freezeAccount("abc"); + assertThrows(AccountFrozenException.class, ()->teller.deposit("abc", 50)); + //Checking that a frozen account is still counted in banks assets + assertEquals(1199.45, admin.calcTotalAssets()); + assertThrows(AccountFrozenException.class, ()->teller.withdraw("abc", 50)); + assertThrows(AccountFrozenException.class, ()->teller.transfer("abc", "xyz",50)); + assertThrows(AccountFrozenException.class, ()->teller.transfer("xyz", "abc",50)); + teller.deposit("xyz", 0.13); + assertEquals(1199.58, admin.calcTotalAssets()); + + } + From 4039fbc83a205fac9beff65baa574a70d6718057 Mon Sep 17 00:00:00 2001 From: eostendarp <42873051+eostendarp@users.noreply.github.com> Date: Wed, 12 Feb 2020 14:13:46 -0500 Subject: [PATCH 83/86] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52aee11f..dbd9620e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 -Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R +Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R (Consider removing User class and adding property to Account) Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing From 89fdec6703080ab27f7caaba527d9be8a33beaaa Mon Sep 17 00:00:00 2001 From: eostendarp <42873051+eostendarp@users.noreply.github.com> Date: Wed, 12 Feb 2020 14:45:34 -0500 Subject: [PATCH 84/86] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbd9620e..52aee11f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Use Case Diagram: https://www.lucidchart.com/invitations/accept/4307fa3a-0405-408d-ba36-95b8793790b6 -Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R (Consider removing User class and adding property to Account) +Class Diagram: https://www.draw.io/#G14lOqCFtOO7uEm51Zpj4FGR7ti2bjM54R Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1OXqnUsb1rqihpPv-qyBwDjLqungH4SJd/view?usp=sharing From 140eaa04287c470dfcb56698023d7854666a6505 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Wed, 12 Feb 2020 14:47:30 -0500 Subject: [PATCH 85/86] Updated readme post code review --- README.md | 3 +++ src/test/java/edu/ithaca/dragon/bank/AccountTest.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52aee11f..38d52c6e 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,6 @@ Sequence Diagram (Saul): Teller, User, Account https://drive.google.com/file/d/1 Sequence Diagram (Josh): Admin, Account, CentralBank https://drive.google.com/file/d/1hWu4E4gvjYxcYmPHV18QAMbwkdUuo9Hd/view?usp=sharing Sequence Diagram (Erich): https://drive.google.com/file/d/1tcE_ITNZHlpZ7IzYDILuwuuKqsxNMex5/view?usp=sharing + +Code Review Notes: Need to update class diagram to no longer have user. Update use case diagram to be more readable. +Generally we want to update tests, Josh will update Admin system test to test for more than two accounts. Saul will make sure method names match the diagram. Eric will update some other tests. diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java index bf49c062..0a8414a4 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -183,7 +183,7 @@ void transferTest() throws InsufficientFundsException, AccountFrozenException { a.setFrozen(false); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 20)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50.85)); - //Checking that Account Frozen has higher priority than other errors, with reciever frozen + //Checking that Account Frozen has higher priority than other errors, with receiver frozen assertThrows(AccountFrozenException.class, () -> a.transfer(b, 1000.01)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, 50000)); assertThrows(AccountFrozenException.class, () -> a.transfer(b, -30)); From e7b9ade4a59d56be66db3d02ba032df5138225a3 Mon Sep 17 00:00:00 2001 From: JoshHayden Date: Thu, 13 Feb 2020 12:13:48 -0500 Subject: [PATCH 86/86] Updated system test to include a third account and test for unfreezeAccount --- .../java/edu/ithaca/dragon/bank/AdminTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java index 98c96666..21ad94b5 100644 --- a/src/test/java/edu/ithaca/dragon/bank/AdminTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/AdminTest.java @@ -156,6 +156,21 @@ void systemTest() throws InsufficientFundsException, AccountFrozenException{ teller.deposit("xyz", 0.13); assertEquals(1199.58, admin.calcTotalAssets()); + //Going to add a new account and make sure unfreeze account works as expected + + teller.createAccount("new", 300.42); + assertEquals(1500, admin.calcTotalAssets()); + assertThrows(AccountFrozenException.class, ()->teller.transfer("abc", "new",50)); + assertThrows(AccountFrozenException.class, ()->teller.transfer("new", "abc",50)); + admin.unfreezeAcct("abc"); + teller.transfer("abc", "new", 100); + assertEquals(1500, admin.calcTotalAssets()); + teller.deposit("abc", 150); + assertEquals(1650, admin.calcTotalAssets()); + teller.withdraw("abc", 200); + assertEquals(1450, admin.calcTotalAssets()); + + }