diff --git a/.gitignore b/.gitignore index 3c8b8dd5..44927002 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff +target/ .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml diff --git a/SoftwareEngineeringPractice.iml b/.idea/SoftwareEngineeringPractice.iml similarity index 100% rename from SoftwareEngineeringPractice.iml rename to .idea/SoftwareEngineeringPractice.iml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 28c6362f..edefae33 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index b26911bd..fade66b8 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d87af9ac..5d282d4d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + + - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SoftwareEngineeringPracticeBank.iml b/SoftwareEngineeringPracticeBank.iml new file mode 100644 index 00000000..74f3f131 --- /dev/null +++ b/SoftwareEngineeringPracticeBank.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file 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..858eb254 --- /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, String email, String password, double startingBalance); + + public void closeAccount(String acctId); +} diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index e340e0ea..7c2a19dc 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,17 +1,34 @@ package edu.ithaca.dragon.bank; +import java.util.regex.Pattern; + public class BankAccount { private String email; private double balance; + private String password; + private String acctId; + + + + public BankAccount(String email, double startingBalance) { + this("", email, "", startingBalance); + } /** * @throws IllegalArgumentException if email is invalid */ - public BankAccount(String email, double startingBalance){ + public BankAccount(String acctId, String email, String password, double startingBalance){ if (isEmailValid(email)){ - this.email = email; - this.balance = startingBalance; + if(isAmountValid(startingBalance)){ + this.acctId = acctId; + this.email = email; + this.balance = startingBalance; + this.password = password; + } + else{ + throw new IllegalArgumentException("starting Balance of " + startingBalance + "is an invalid amount to add"); + } } else { throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); @@ -28,19 +45,67 @@ public String getEmail(){ /** * @post reduces the balance by amount if amount is non-negative and smaller than balance + * throws InsufficientFundsException if the amount is larger than the balance + * If balance is negative or has more than 2 decimal places, throws IllegalArgumentException */ - public void withdraw (double amount) { - balance -= amount; + public void withdraw (double amount) throws InsufficientFundsException, IllegalArgumentException { + if(!isAmountValid(amount)){ + throw new IllegalArgumentException("Amount must have 2 decimal places and must be positive "); + } + if (balance >= amount && amount >= 0) { + balance -= amount; + } + else{ + throw new InsufficientFundsException("Amount requested is more than in your account by " + (amount - balance)); + } } - - public static boolean isEmailValid(String email){ - if (email.indexOf('@') == -1){ - return false; + /** + * @post adds to the balance by amount if amount is non-negative and has 2 or less decimal places + * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places + */ + public void deposit(double amount) throws IllegalArgumentException{ + if(!isAmountValid(amount)){ + throw new IllegalArgumentException("Amount must have 2 or less decimal places and must be positive"); } - else { - return true; + balance += amount; + } + + /** + * @post transfers funds from one bank account to the one passed in, as long as amount is non-negative and has 2 or less decimal places + * @throws IllegalArgumentException if amount is negative or has more than 2 decimal places, or if bankAccount to transfer to is the current one + * @throws InsufficientFundsException if amount is larger than current bank account balance + */ + public void transfer(double amount, BankAccount toTransfer) throws InsufficientFundsException, IllegalArgumentException{ + if(!isAmountValid(amount) || toTransfer == this){ + throw new IllegalArgumentException("Amount must be positive, have 2 decimals or less, and transfer to a new bank account"); + } + this.withdraw(amount); + toTransfer.deposit(amount); + } + + /** + * @post checks to see if a double is a valid input to be withdrawn + * Returns false if double has more than 2 decimal places, or is negative + */ + public static boolean isAmountValid(double amount){ + double positiveRoundOff = Math.abs(Math.round(amount * 100.0) / 100.0); + if(amount != positiveRoundOff){ + + String doubleCheck = Double.toString(Math.abs(amount)); + int integerPlaces = doubleCheck.indexOf('.'); + int decimalPlaces = doubleCheck.length() - integerPlaces - 1; + return (decimalPlaces <= 2 || doubleCheck.indexOf('E') != -1) && !(amount < 0); } + return true; + } + + public static boolean isEmailValid(String email){ + return email.matches("(\\w)+((_|\\.|-)+\\w+)*@(\\w)+((-)?\\w+)*\\.\\w{2,}$"); + } + + public String getPassword() { + return password; } } 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..bde440c0 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java @@ -0,0 +1,20 @@ +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..c4aa13bd --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -0,0 +1,95 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class CentralBank implements AdvancedAPI, AdminAPI { + + //----------------- BasicAPI methods -------------------------// + + + public MapaccountMap = new HashMap<>(); + + + + + public boolean confirmCredentials(String acctId, String password){ + if(accountMap.containsKey(acctId)){ + return accountMap.get(acctId).getPassword().equals(password); + } + + + + return false; + } + + + public double checkBalance(String acctId) { + return 0; + } + + public void withdraw(String acctId, double amount) throws InsufficientFundsException { + + } + + @Override + public double calcTotalAssets() { + return 0; + } + + 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, String email, String password, double startingBalance) { + BankAccount account = new BankAccount(acctId, email, password, startingBalance); + accountMap.put(acctId, account); + + } + + + + + public void closeAccount(String acctId) { +// CentralBank bank = new CentralBank(); +// +// bank.accountMap.remove(acctId); + + + + + + } + + + //------------------ AdminAPI methods -------------------------// + + public double checkTotalAssets() { + return 0; + } + + public Collection findAcctIdsWithSuspiciousActivity() { + return null; + } + + public void freezeAccount(String acctId) { + + } + + public void unfreezeAcct(String acctId) { + + } + +} diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index d19ecb02..4cbece9d 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -6,25 +6,164 @@ class BankAccountTest { + + @Test - void getBalanceTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); + void createAccountTest(){ + CentralBank bankAccount = new CentralBank(); + bankAccount.createAccount("1245", "a1@hello.com", "testpassword", 500); + assertNull( bankAccount.accountMap.get("12466")); + assertEquals(500, bankAccount.accountMap.get("1245").getBalance()); + assertEquals("a1@hello.com", bankAccount.accountMap.get("1245").getEmail()); + assertEquals("testpassword", bankAccount.accountMap.get("1245").getPassword()); + + CentralBank bankAccount2 = new CentralBank(); + bankAccount2.createAccount("BH8525", "atest3@gmail.com", "funny", 1000); + assertNull(bankAccount2.accountMap.get("BH85425")); + assertEquals(1000, bankAccount2.accountMap.get("BH8525").getBalance()); + assertEquals("atest3@gmail.com", bankAccount2.accountMap.get("BH8525").getEmail()); + assertEquals("funny", bankAccount2.accountMap.get("BH8525").getPassword()); - assertEquals(200, bankAccount.getBalance()); } + @Test - void withdrawTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); + void closeAccountTest(){ + CentralBank bankAccount = new CentralBank(); + bankAccount.createAccount("1245", "a1@hello.com", "testpassword", 500); + assertEquals("a1@hello.com",bankAccount.accountMap.get("1245").getEmail()); + bankAccount.closeAccount("1245"); + assertEquals(null, bankAccount.accountMap.get("1245").getEmail()); + + CentralBank bankAccount2 = new CentralBank(); + bankAccount2.createAccount("BH8525", "atest3@gmail.com", "funny", 1000); + + + + + } + + @Test + void confirmCredentialsTest(){ + + CentralBank bankAccount = new CentralBank(); + CentralBank bankAccount2 = new CentralBank(); + bankAccount.createAccount("11212", "a@b.com", "testingPassword", 500); + bankAccount2.createAccount("11BFWGG", "tester@gmail.com", "singleLetter", 1000); + + assertFalse(bankAccount.confirmCredentials("11212", "test")); + assertFalse( bankAccount.confirmCredentials("112", "testingPassword")); + assertTrue( bankAccount.confirmCredentials("11212", "testingPassword")); + + assertFalse(bankAccount2.confirmCredentials("11bfwgg", "singleLetter")); + assertFalse(bankAccount2.confirmCredentials("11bfwgg", "SingleLetter")); + assertTrue(bankAccount2.confirmCredentials("11BFWGG", "singleLetter")); + + + + + } + + @Test + void getBalanceTest() throws InsufficientFundsException, IllegalArgumentException { + //classes - fresh account, after withdrawal, after unsuccessful withdrawal + BankAccount bankAccount = new BankAccount("a@b.com", 1000); + + //fresh account + assertEquals(1000, bankAccount.getBalance()); //equivalence class starting balance and not border cas + //after withdrawal + bankAccount.withdraw(100); + assertEquals(900, bankAccount.getBalance()); //equivalence class of less than and not border case + bankAccount.withdraw(500); + assertEquals(400, bankAccount.getBalance()); //equivalence class of more than and not border case + bankAccount.withdraw(400); + assertEquals(0, bankAccount.getBalance()); //equivalence class of zero and border case + + //after unsuccessful withdrawal + BankAccount unsuccessful = new BankAccount("a@b.com",1000); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(1100)); //equivalence class of greater than and border case + assertEquals(1000, unsuccessful.getBalance()); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(2000)); //equivalence class of middle value and not border case + assertEquals(1000, unsuccessful.getBalance()); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(Integer.MAX_VALUE)); //equivalence class of Max Value and border case + assertEquals(1000, unsuccessful.getBalance()); + } + + @Test + void withdrawTest() throws InsufficientFundsException, IllegalArgumentException{ + //classes - sufficient funds, insufficient funds, negative funds + BankAccount bankAccount = new BankAccount("a@b.com", 1000); + //sufficient funds + bankAccount.withdraw(0); + assertEquals(1000, bankAccount.getBalance()); bankAccount.withdraw(100); + assertEquals(900, bankAccount.getBalance()); //equivalence class of less than and not border case + bankAccount.withdraw(500); + assertEquals(400, bankAccount.getBalance()); //equivalence class of more than and not border case + bankAccount.withdraw(400); + assertEquals(0, bankAccount.getBalance()); //equivalence class of zero and border case + //insufficient funds + int min = Integer.MIN_VALUE; + int max = Integer.MAX_VALUE; + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(300)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(max)); + assertThrows(InsufficientFundsException.class, () -> bankAccount.withdraw(1)); + //negative numbers + BankAccount negative = new BankAccount("a@b.com", 1000); + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-500)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and not border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(min)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + //numbers with more than 2 decimals + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(300.001)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(1000.04940)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and not border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(50.1029384958674950)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + //negative numbers with more than 2 decimals + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100.001)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100.10239485)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and not border case + assertThrows(IllegalArgumentException.class, () -> bankAccount.withdraw(-100.1029384758493815)); + assertEquals(1000, negative.getBalance()); //equivalence class of negative balance and border case + + + - assertEquals(100, bankAccount.getBalance()); } @Test void isEmailValidTest(){ - assertTrue(BankAccount.isEmailValid( "a@b.com")); - assertFalse( BankAccount.isEmailValid("")); + //one @ symbol class + assertTrue(BankAccount.isEmailValid( "a.b.c@b.com")); //equivalence class of one @ and not border case + assertFalse(BankAccount.isEmailValid("abc@def@mail.com")); //equivalence class of multiple @ and border case + assertFalse(BankAccount.isEmailValid("abc@d@ef@mail.com")); //equivalence class of multiple @ and border case + assertFalse(BankAccount.isEmailValid("abc@d@ef@ma@il.com")); //equivalence class of multiple @ and border case + assertFalse( BankAccount.isEmailValid("")); //equivalence class of one no @ and border case + //valid special characters in prefix + assertFalse(BankAccount.isEmailValid("abc-@mail.com")); //equivalence class of one valid special characters and not border case + assertFalse(BankAccount.isEmailValid("abc..@mail.com")); //equivalence class of two valid special characters and not border case + assertFalse(BankAccount.isEmailValid(".abc@mail.com")); //equivalence class of valid special characters and not border case + //invalid characters in prefix + assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); //equivalence class of one invalid characters and border case + assertFalse(BankAccount.isEmailValid("abc#de!f@mail.com")); //equivalence class of two invalid characters and border case + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); //equivalence class of one invalid characters and not border case + //invalid suffix characters + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); //equivalence class of invalid suffix characters and border case + assertFalse(BankAccount.isEmailValid("abc.def@mail!ar%chive.com")); //equivalence class of invalid suffix characters and border case + assertFalse(BankAccount.isEmailValid("abc.def@mail!ar%chi.ve.com")); //equivalence class of invalid suffix characters and border case + assertFalse(BankAccount.isEmailValid("abc.def@mail--archive.com")); //equivalence class of invalid suffix characters and border case + assertFalse(BankAccount.isEmailValid("abc.def@mail-arc!h.ive.com")); //equivalence class of invalid suffix characters and border case + //valid domain + assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); //equivalence class of invalid domain and not border case + assertFalse(BankAccount.isEmailValid("abc.def@mail")); //equivalence class of no domain and border case + assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); //equivalence class of two . in domain and border case + assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); //equivalence class of invalid domain and not border case + } @Test @@ -33,8 +172,196 @@ void constructorTest() { assertEquals("a@b.com", bankAccount.getEmail()); assertEquals(200, bankAccount.getBalance()); - //check for exception thrown correctly + //check for exception thrown correctly for email assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); + //checks if it throws an argument for negative numbers + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -1)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -150)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -10000000)); + //checks if it throws an argument for numbers with more than 2 decimal places + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 100.001)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 150.01020495)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -123.1029384758495837)); + //checks if it throws an argument for numbers that are negative and have more than 2 decimal places + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -1.001)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -120.123453)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", -100.102938456744854)); + } + + @Test + void isAmountValidTest(){ + //valid number, no decimals + assertTrue(BankAccount.isAmountValid(0)); + assertTrue(BankAccount.isAmountValid(1)); + assertTrue(BankAccount.isAmountValid(500)); + assertTrue(BankAccount.isAmountValid(678)); + assertTrue(BankAccount.isAmountValid(Integer.MAX_VALUE)); + //valid number, 1 decimal + assertTrue(BankAccount.isAmountValid(500.0)); + assertTrue(BankAccount.isAmountValid(500.1)); + assertTrue(BankAccount.isAmountValid(500.5)); + assertTrue(BankAccount.isAmountValid(500.9)); + //valid number, 2 decimals + assertTrue(BankAccount.isAmountValid(500.00)); + assertTrue(BankAccount.isAmountValid(500.01)); + assertTrue(BankAccount.isAmountValid(500.10)); + assertTrue(BankAccount.isAmountValid(500.62)); + assertTrue(BankAccount.isAmountValid(500.99)); + //invalid number, more than 2 decimals + assertTrue(BankAccount.isAmountValid(500.00000000)); + assertFalse(BankAccount.isAmountValid(500.001)); + assertFalse(BankAccount.isAmountValid(500.597)); + assertFalse(BankAccount.isAmountValid(500.56690930452)); + assertFalse(BankAccount.isAmountValid(500.999)); + assertFalse(BankAccount.isAmountValid(500.2048675849586746)); + //invalid number, negative with 0 decimals + assertFalse(BankAccount.isAmountValid(-1)); + assertFalse(BankAccount.isAmountValid(-100)); + assertFalse(BankAccount.isAmountValid(Integer.MIN_VALUE)); + //invalid number, negative with 1 decimal + assertFalse(BankAccount.isAmountValid(-1.0)); + assertFalse(BankAccount.isAmountValid(-100.7)); + assertFalse(BankAccount.isAmountValid(-999999.9)); + //invalid number, negative with 2 decimals + assertFalse(BankAccount.isAmountValid(-1.00)); + assertFalse(BankAccount.isAmountValid(-100.59)); + assertFalse(BankAccount.isAmountValid(-999999999999.99)); + //invalid number, negative with more than 2 decimals + assertFalse(BankAccount.isAmountValid(-100.001)); + assertFalse(BankAccount.isAmountValid(-100.5689)); + assertFalse(BankAccount.isAmountValid(-100.5784939576859)); + assertFalse(BankAccount.isAmountValid(-999.9999999999999999)); + + } + + @Test + void depositTest(){ + BankAccount bankAccount = new BankAccount("a@b.com", 1000); + //deposit valid integer + bankAccount.deposit(1); + assertEquals(1001, bankAccount.getBalance()); + bankAccount.deposit(100); + assertEquals(1101, bankAccount.getBalance()); + bankAccount.deposit(10000); + assertEquals(11101, bankAccount.getBalance()); + //deposit valid double with < 1 decimal + bankAccount.deposit(1.1); + assertEquals(11102.1, bankAccount.getBalance()); + bankAccount.deposit(10.5); + assertEquals(11112.6, bankAccount.getBalance()); + bankAccount.deposit(10.9); + assertEquals(11123.5, bankAccount.getBalance()); + //deposit valid with 2 decimals + bankAccount.deposit(1.00); + assertEquals(11124.50, bankAccount.getBalance()); + bankAccount.deposit(1.11); + assertEquals(11125.61, bankAccount.getBalance()); + bankAccount.deposit(1.57); + assertEquals(11127.18, bankAccount.getBalance()); + bankAccount.deposit(1.99); + assertEquals(11129.17, bankAccount.getBalance()); + //invalid number, negative + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-500)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(Integer.MIN_VALUE)); + assertEquals(11129.17, bankAccount.getBalance()); + //invalid number, negative, one decimal + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.1)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.5)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.9)); + assertEquals(11129.17, bankAccount.getBalance()); + //invalid number, negative, 2 decimals + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.00)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.57)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.99)); + assertEquals(11129.17, bankAccount.getBalance()); + //invalid number, more than 2 decimals + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(1.001)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.585976)); + assertEquals(11129.17, bankAccount.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(50.102938475960794)); + assertEquals(11129.17, bankAccount.getBalance()); + + + } + + @Test + void transferTest() throws InsufficientFundsException,IllegalArgumentException{ + BankAccount bankAccount1 = new BankAccount("a@b.com", 1000); + BankAccount bankAccount2 = new BankAccount("b@a.com", 0); + //checking initial balances + assertEquals(1000, bankAccount1.getBalance()); + assertEquals(0, bankAccount2.getBalance()); + //transfer from 1 to 2, integers, valid amount + bankAccount1.transfer(1, bankAccount2); + assertEquals(999, bankAccount1.getBalance()); + assertEquals(1, bankAccount2.getBalance()); + bankAccount1.transfer(99, bankAccount2); + assertEquals(900, bankAccount1.getBalance()); + assertEquals(100, bankAccount2.getBalance()); + bankAccount1.transfer(900, bankAccount2); + assertEquals(0, bankAccount1.getBalance()); + assertEquals(1000, bankAccount2.getBalance()); + //transfer from 2 to 1, 1 decimal, valid amount + bankAccount2.transfer(0.1, bankAccount1); + assertEquals(0.1, bankAccount1.getBalance()); + assertEquals(999.9, bankAccount2.getBalance()); + bankAccount2.transfer(99.5, bankAccount1); + assertEquals(99.6, bankAccount1.getBalance()); + assertEquals(900.4, bankAccount2.getBalance()); + //transfer from 2 to 1, 2 decimals, valid amount + bankAccount2.transfer(50.41, bankAccount1); + assertEquals(150.01, bankAccount1.getBalance()); + assertEquals(849.99, bankAccount2.getBalance()); + bankAccount2.transfer(50.11, bankAccount1); + assertEquals(200.12, bankAccount1.getBalance()); + assertEquals(799.88, bankAccount2.getBalance()); + bankAccount2.transfer(50.99, bankAccount1); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + //invalid transfer, same bank + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(50, bankAccount1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount2.transfer(50, bankAccount2)); + //invalid transfer, negative numbers + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(-1, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(-50.8, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(-500.99, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + //invalid transfer, 3 or more decimals + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(50.001, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(50.9484930, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + assertThrows(IllegalArgumentException.class, ()-> bankAccount1.transfer(-50.102938495869503, bankAccount2)); + assertEquals(251.11, bankAccount1.getBalance()); + assertEquals(748.89, bankAccount2.getBalance()); + //invalid transfer, insufficient funds + bankAccount1.transfer(251.11, bankAccount2); + + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.transfer(1, bankAccount2)); + assertEquals(0, bankAccount1.getBalance()); + assertEquals(1000, bankAccount2.getBalance()); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.transfer(246, bankAccount2)); + assertEquals(0, bankAccount1.getBalance()); + assertEquals(1000, bankAccount2.getBalance()); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.transfer(Integer.MAX_VALUE, bankAccount2)); + assertEquals(0, bankAccount1.getBalance()); + assertEquals(1000, bankAccount2.getBalance()); + } } \ No newline at end of file