diff --git a/.gitignore b/.gitignore
index 3c8b8dd5..fd0406a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+target/
# User-specific stuff
.idea/**/workspace.xml
diff --git a/.idea/SoftwareEngineeringPractice.iml b/.idea/SoftwareEngineeringPractice.iml
new file mode 100644
index 00000000..78b2cc53
--- /dev/null
+++ b/.idea/SoftwareEngineeringPractice.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/TobySoftwareEngineeringPractice.iml b/.idea/TobySoftwareEngineeringPractice.iml
new file mode 100644
index 00000000..78b2cc53
--- /dev/null
+++ b/.idea/TobySoftwareEngineeringPractice.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 28c6362f..4e2bf249 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,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/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/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java
index e340e0ea..a146b4b6 100644
--- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java
+++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java
@@ -1,14 +1,40 @@
package edu.ithaca.dragon.bank;
+import java.util.HashSet;
+
public class BankAccount {
- private String email;
- private double balance;
+ public String email;
+ public double balance;
+
+ /**
+ * @throws IllegalArgumentException if amount to be withdrawn is invalid
+ * Returns a boolean
+ */
+ private boolean isAmountValid(double amount) throws IllegalArgumentException{
+ String numString = Double.toString(amount);
+ int length = numString.length();
+
+ if (length > 3){ //only runs this test if amount has more than 3 chars
+ int period = numString.lastIndexOf(".");
+ if (length > (period + 3)) throw new IllegalArgumentException("The amount you entered " + amount + " is invalid because it has more than three decimal places.");
+ }
+
+ else if (amount < 0){ //checks ifd the number is negative
+ throw new IllegalArgumentException("The amount you entered " + amount + " is invalid because it is negative");
+ }
+
+ return true; // returns true if amount is valid
+ }
/**
* @throws IllegalArgumentException if email is invalid
*/
public BankAccount(String email, double startingBalance){
+
+ if (isAmountValid(startingBalance) == false){
+ throw new IllegalArgumentException("Starting balance is an invalid balance because it is negative or has too many decimal places");
+ }
if (isEmailValid(email)){
this.email = email;
this.balance = startingBalance;
@@ -16,6 +42,7 @@ public BankAccount(String email, double startingBalance){
else {
throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account");
}
+
}
public double getBalance(){
@@ -26,21 +53,253 @@ public String getEmail(){
return email;
}
+ /**
+ * @post transfers an amount from one account to the other.
+ * parameters: bankaccount1, bankaccount2, transfer amount
+ * @throws IllegalArgumentException if deposit amount is invalid
+ *
+ */
+ public void transfer ( BankAccount bankAccountTrasferringTo, double amount) throws InsufficientFundsException, IllegalArgumentException{
+ if (isAmountValid(amount) != true){
+ throw new IllegalArgumentException ("The amount you entered: "+ amount + " is not a valid amount");
+ }
+
+ else if (balance < amount){
+ throw new InsufficientFundsException("You do not have enough money in your account to make this transfer");
+ }
+ else if (amount == 0 || amount < 0){
+ throw new IllegalArgumentException("You cannot transfer $0 or less");
+ }
+
+ else {
+ balance -= amount;
+ bankAccountTrasferringTo.balance += amount;
+ }
+ }
+
+ /**
+ * @post increases the balance by the amount deposited
+ * parameters: deposit amount
+ * @throws IllegalArgumentException if deposit amount is invalid
+ *
+ */
+
+ public void deposit (double amount) throws IllegalArgumentException {
+ if (isAmountValid(amount) == false){
+ throw new IllegalArgumentException("The amount you entered " + amount + " is invalid");
+ }
+ else if (amount == 0){
+ throw new IllegalArgumentException("You cannot deposit $0");
+ }
+ else {
+ balance += amount;
+ }
+ }
+
/**
* @post reduces the balance by amount if amount is non-negative and smaller than balance
+ * throws IllegalArgument if the amount is more than the balance
+ * for negative numbers return the unchanged balance
+ * returns the balance if the withdraw amount is less than your balance and a positive number.
*/
- public void withdraw (double amount) {
- balance -= amount;
+ public void withdraw (double amount) throws InsufficientFundsException {
+ if (isAmountValid(amount) == false){
+ throw new IllegalArgumentException("The amount you entered " + amount + " is invalid");
+ }
+
+ if (amount < .01)
+ throw new IllegalArgumentException("Cannot withdraw $0 or less");
+
+ else if (balance >= amount)
+ balance -= amount;
+
+ else if (balance < amount)
+ throw new InsufficientFundsException("Cannot draw more than account balance.");
}
+ /**
+ * returns true if email follows correct conventions.
+ */
+
+ public static boolean isEmailValid(String email) {
- public static boolean isEmailValid(String email){
- if (email.indexOf('@') == -1){
+ //declares a variable with the locations of the @ signs in the email.
+ int atSign = email.indexOf('@');
+ int lastAtSign = email.lastIndexOf('@');
+
+ //makes sure that an @ sign is in the email.
+ if (atSign == -1)
+ return false;
+
+ //makes sure that there is only one @ sign.
+ if (atSign != lastAtSign)
+ return false;
+
+ //Makes sure that a special character is not followed by a "@"
+ if (email.charAt(lastAtSign-1) == '.')
+ return false;
+
+ if (email.charAt(lastAtSign-1) == '_')
+ return false;
+
+ if (email.charAt(lastAtSign-1) == '-')
+ return false;
+
+ //declares a variable with the location of the last "." in the email
+ int lastPeriodSign = email.lastIndexOf('.');
+
+
+ //makes sure that there is a '.' in the email.
+ if (lastPeriodSign == -1)
+ return false;
+
+ //makes sure that there is a period after @
+ if (email.charAt(lastAtSign) < email.charAt(lastPeriodSign))
return false;
+
+ //makes sure that there is not two periods, dashes, or underscores back to back in the email
+ int x = 0;
+ int lengthOfEmail = email.length();
+
+ int locationOfLastPeriod = -1000;
+ int locationOfCurrentPeriod;
+
+ int locationOfLastDash = -2;
+ int locationOfCurrentDash;
+
+ int locationOfLastUnderscore = -2;
+ int locationOfCurrentUnderscore;
+
+ //makes sure the period follows a .com or .cc or .org or .edu etc...
+ if (lastPeriodSign != lengthOfEmail - 3 && lastPeriodSign != lengthOfEmail - 4)
+ return false;
+
+ while (x < (email.length()-1)){
+
+ //checks to make sure the email does not start with a period
+ if(email.charAt(x) == '.' && x == 0)
+ return false;
+ //checks for double periods
+ if (email.charAt(x) =='.' && x == (locationOfLastPeriod+1))
+ return false;
+ if(email.charAt(x) =='.')
+ locationOfLastPeriod = x;
+
+ //checks for double underscores
+ if(email.charAt(x) == '_' && x == 0)
+ return false;
+ if (email.charAt(x) == locationOfLastUnderscore)
+ return false;
+ else if(email.charAt(x) =='_')
+ locationOfLastUnderscore = x;
+
+ //checks for double dashes
+ if(email.charAt(x) == '-' && x == 0)
+ return false;
+ if (email.charAt(x) == locationOfLastDash)
+ return false;
+ else if(email.charAt(x) =='-')
+ locationOfLastDash = x;
+
+ x++;
}
- else {
- return true;
+
+
+
+ //makes sure there is not an invalid character
+ int j = 0;
+ HashSet validCharSet = getValidCharSet();
+ while (j < lengthOfEmail) {
+
+
+ if (!validCharSet.contains(email.charAt(j))) return false;
+
+
+ if (isSpecialChar(email.charAt(j))){
+ //if leading or last character is special, return false
+ if (j == 0 || j == lengthOfEmail - 1) return false;
+ //makes sure theres no double special characters
+ if (isSpecialChar(email.charAt(j + 1))) return false;
+ }
+ //go back one letter
+ j++;
}
+
+ return true;
+
+ }
+ private static boolean isSpecialChar(char c) { return c == '.' || c == '-' || c == '_' || c == '@'; }
+
+ private static HashSet getValidCharSet(){
+ HashSet validCharSet = new HashSet<>();
+ validCharSet.add('@');
+ validCharSet.add('.');
+ validCharSet.add('_');
+ validCharSet.add('-');
+ validCharSet.add('q');
+ validCharSet.add('w');
+ validCharSet.add('e');
+ validCharSet.add('r');
+ validCharSet.add('t');
+ validCharSet.add('y');
+ validCharSet.add('u');
+ validCharSet.add('i');
+ validCharSet.add('o');
+ validCharSet.add('p');
+ validCharSet.add('a');
+ validCharSet.add('s');
+ validCharSet.add('d');
+ validCharSet.add('f');
+ validCharSet.add('g');
+ validCharSet.add('h');
+ validCharSet.add('j');
+ validCharSet.add('k');
+ validCharSet.add('l');
+ validCharSet.add('z');
+ validCharSet.add('x');
+ validCharSet.add('c');
+ validCharSet.add('v');
+ validCharSet.add('b');
+ validCharSet.add('n');
+ validCharSet.add('m');
+ validCharSet.add('Q');
+ validCharSet.add('W');
+ validCharSet.add('E');
+ validCharSet.add('R');
+ validCharSet.add('T');
+ validCharSet.add('Y');
+ validCharSet.add('U');
+ validCharSet.add('I');
+ validCharSet.add('O');
+ validCharSet.add('P');
+ validCharSet.add('A');
+ validCharSet.add('S');
+ validCharSet.add('D');
+ validCharSet.add('F');
+ validCharSet.add('G');
+ validCharSet.add('H');
+ validCharSet.add('J');
+ validCharSet.add('K');
+ validCharSet.add('L');
+ validCharSet.add('Z');
+ validCharSet.add('X');
+ validCharSet.add('C');
+ validCharSet.add('V');
+ validCharSet.add('B');
+ validCharSet.add('N');
+ validCharSet.add('M');
+ validCharSet.add('1');
+ validCharSet.add('2');
+ validCharSet.add('3');
+ validCharSet.add('4');
+ validCharSet.add('5');
+ validCharSet.add('6');
+ validCharSet.add('7');
+ validCharSet.add('8');
+ validCharSet.add('9');
+ validCharSet.add('0');
+
+ return validCharSet;
}
}
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..e23a2adf
--- /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, BankAccount[] customerCollection);
+
+ 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..13f2f5fd
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java
@@ -0,0 +1,79 @@
+package edu.ithaca.dragon.bank;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+
+public class CentralBank implements AdvancedAPI, AdminAPI {
+
+ public CentralBank (){
+ BankAccount customerCollection[]= new BankAccount[1];
+ customerCollection[0] = new BankAccount("a@b.com",305);
+ }
+
+ //----------------- BasicAPI methods -------------------------//
+
+ public boolean confirmCredentials(String acctId, String password) {
+ return false;
+ }
+
+
+ public double checkBalance(String acctId, BankAccount[] customerCollection) throws IllegalArgumentException {
+ int length = customerCollection.length;
+ for(int i =0; i < length; i++){
+ if (acctId == customerCollection[i].email)
+ return customerCollection[i].getBalance();
+ }
+ throw new IllegalArgumentException("The account ID you entered is not in the system");
+ }
+
+ 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 double calcTotalAssets() {
+ 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..acf4be2c 100644
--- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java
+++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java
@@ -1,3 +1,4 @@
+
package edu.ithaca.dragon.bank;
import org.junit.jupiter.api.Test;
@@ -6,35 +7,233 @@
class BankAccountTest {
+ @Test
+ void transferTest() throws InsufficientFundsException {
+ BankAccount bankAccount = new BankAccount("abg@g.com",100); //tests for a valid transfer
+ BankAccount bankAccount1 = new BankAccount("a@b.com",100);
+ bankAccount.transfer(bankAccount1,80);
+ assertEquals(180,bankAccount1.getBalance());
+ assertEquals(20, bankAccount.getBalance());
+
+ BankAccount bankAccount2 = new BankAccount("abg@g.com",100); // tests for a valid withdraw at the boundary of your balance
+ BankAccount bankAccount3 = new BankAccount("a@b.com",100);
+ bankAccount2.transfer(bankAccount3,100);
+ assertEquals(200,bankAccount3.getBalance());
+ assertEquals(0, bankAccount2.getBalance());
+
+ BankAccount bankAccount4 = new BankAccount("abg@g.com",30); //tests for a valid transfer at the boundary of the smallest amount
+ BankAccount bankAccount5 = new BankAccount("a@b.com",50);
+ bankAccount4.transfer(bankAccount5,0.01);
+ assertEquals(29.99,bankAccount4.getBalance());
+ assertEquals(50.01, bankAccount5.getBalance());
+
+ BankAccount bankAccount6 = new BankAccount("abg@g.com",900); //tests for an invalid transfer of 0
+ BankAccount bankAccount7 = new BankAccount("a@b.com",1000);
+ assertThrows(IllegalArgumentException.class, () -> bankAccount6.transfer(bankAccount7,0));
+ assertEquals(900,bankAccount6.getBalance());
+ assertEquals(1000, bankAccount7.getBalance());
+
+ BankAccount bankAccount8 = new BankAccount("abg@g.com",700); //tests for an invalid transfer of an amount larger than your balance
+ BankAccount bankAccount9 = new BankAccount("a@b.com",654.60);
+ assertThrows(InsufficientFundsException.class, () -> bankAccount8.transfer(bankAccount9,701));
+ assertEquals(700,bankAccount8.getBalance());
+ assertEquals(654.60, bankAccount9.getBalance());
+
+ BankAccount bankAccount10 = new BankAccount("abg@g.com",600); //tests for an invalid transfer of a negative number
+ BankAccount bankAccount11 = new BankAccount("a@b.com",600);
+ assertThrows(IllegalArgumentException.class, () -> bankAccount10.transfer(bankAccount11,-600));
+ assertEquals(600,bankAccount10.getBalance());
+ assertEquals(600, bankAccount11.getBalance());
+
+ BankAccount bankAccount12 = new BankAccount("abg@g.com",600); //tests for an invalid transfer of a negative number and an amount too large
+ BankAccount bankAccount13 = new BankAccount("a@b.com",600);
+ assertThrows(IllegalArgumentException.class, () -> bankAccount12.transfer(bankAccount13,-700));
+ assertEquals(600,bankAccount12.getBalance());
+ assertEquals(600, bankAccount13.getBalance());
+
+
+
+
+
+
+
+ }
+
+ //need to tests for deposit of 0
+
+ @Test
+ void depositTest() throws IllegalArgumentException{
+
+ BankAccount bankAccount = new BankAccount("abg@g.com",0); //tests for a valid deposit
+ bankAccount.deposit(100);
+ assertEquals(100,bankAccount.getBalance());
+
+ BankAccount bankAccount2 = new BankAccount("abg@g.com",5); //tests for a valid deposit with two decimal places
+ bankAccount2.deposit(100.50);
+ assertEquals(105.50,bankAccount2.getBalance());
+
+ BankAccount bankAccount3 = new BankAccount("abg@g.com",20); //tests for an invalid deposit with more than two decimal places
+ assertThrows(IllegalArgumentException.class, () -> bankAccount3.deposit(100.5080));
+ assertEquals(20,bankAccount3.getBalance());
+
+ BankAccount bankAccount4 = new BankAccount("abg@g.com",50); //tests for an invalid deposit with a negative number
+ assertThrows(IllegalArgumentException.class, () -> bankAccount4.deposit(-10000000));
+ assertEquals(50,bankAccount4.getBalance());
+
+ BankAccount bankAccount5 = new BankAccount("abg@g.com",75); //tests for an invalid deposit with a negative number and more than 2 decimal places
+ assertThrows(IllegalArgumentException.class, () -> bankAccount5.deposit(-10000000.9874));
+ assertEquals(75,bankAccount5.getBalance());
+
+ BankAccount bankAccount6 = new BankAccount("abg@g.com",75); //tests for an invalid deposit of 0.
+ assertThrows(IllegalArgumentException.class, () -> bankAccount5.deposit(0));
+ assertEquals(75,bankAccount5.getBalance());
+
+
+
+
+ }
+
+ @Test
+ void isAmountValidTest() throws InsufficientFundsException {
+
+ BankAccount bankAccount = new BankAccount("ak3@g.com",9000);//gets a postive number with 2 decimal points. Should pass
+ bankAccount.withdraw(123.45);
+ assertEquals(8876.55, bankAccount.getBalance());
+
+ BankAccount bankAccount3 = new BankAccount("ak@g.com",45);//gets a postive number with 1 decimal point. Should pass
+ bankAccount3.withdraw(20.5);
+ assertEquals(24.5, bankAccount3.getBalance());
+
+ BankAccount bankAccount2 = new BankAccount("a@b.com", 200); //checks to make sure a positive number with 3 decimal places is invalid
+ assertThrows(IllegalArgumentException.class, () -> bankAccount2.withdraw(123.546));
+ assertEquals(200,bankAccount2.getBalance());
+
+ BankAccount bankAccount1 = new BankAccount("a@b.com", 300); //checks to make sure a negative number with 4 decimal places is invalid
+ assertThrows(IllegalArgumentException.class, () -> bankAccount1.withdraw(25.5566));
+ assertEquals(300,bankAccount1.getBalance());
+
+ }
+
@Test
void getBalanceTest() {
- BankAccount bankAccount = new BankAccount("a@b.com", 200);
+ //correctly gives you the balance when you have a valid email
+ BankAccount bankAccount = new BankAccount("a@b.com", 200);
assertEquals(200, bankAccount.getBalance());
+
+ //gives you your balance when your balance is 0. Valid email.
+ BankAccount bankAccount1 = new BankAccount("abc-d@mail.com", 0);
+ assertEquals(0, bankAccount1.getBalance());
+
+ //returns your balance when it is negative. Valid email.
+ BankAccount bankAccount2 = new BankAccount("abc-d@mail.com", -10);
+ assertEquals(-10, bankAccount2.getBalance());
+
+ //correctly gives you the balance when you have a valid email
+ BankAccount bankAccount3 = new BankAccount("a@b.com", 800.67);
+ assertEquals(800.67, bankAccount3.getBalance());
+
+
+
}
@Test
- void withdrawTest() {
+ void withdrawTest() throws InsufficientFundsException {
+
+ //tests for a valid withdrawal that will leave you with a half balance. Valid email is provided.
BankAccount bankAccount = new BankAccount("a@b.com", 200);
bankAccount.withdraw(100);
-
assertEquals(100, bankAccount.getBalance());
+
+ //tests for a valid withdrawal that will leave you with no money left in the account. Valid Email.
+ BankAccount bankAccount1 = new BankAccount("abc-d@mail.com", 100);
+ bankAccount.withdraw(100);
+ assertEquals(0, bankAccount.getBalance());
+
+ //tests for an invalid withdrawal of $0 that will leave you with the same balance no matter what it is. Valid email.
+ BankAccount bankAccount2 = new BankAccount("abc-d@mail.com", 100);
+ assertThrows(IllegalArgumentException.class, ()-> bankAccount2.withdraw(0));
+ assertEquals(100,bankAccount2.getBalance());
+
+ //tests for an invalid withdrawal that is more than your current balance. valid email.
+ BankAccount bankAccount3 = new BankAccount("abc-d@mail.com", 348.08);
+ assertThrows(InsufficientFundsException.class, ()-> bankAccount3.withdraw(349));
+ assertEquals(348.08,bankAccount3.getBalance());
+
+ //tests for an invalid withdrawal that is a negative number. Valid email.
+ BankAccount bankAccount4 = new BankAccount("abc-d@mail.com", 590.02);
+ assertThrows(IllegalArgumentException.class, ()-> bankAccount4.withdraw(-20));
+ assertEquals(590.02,bankAccount4.getBalance());
+
+ //tests for an invalid withdrawal that is a fraction of a penny. Should return an illegal argument exception
+ BankAccount bankAccount5 = new BankAccount("abc-d@mail.com", 300.50);
+ assertThrows(IllegalArgumentException.class, ()-> bankAccount4.withdraw(20.567));
+ assertEquals(300.50,bankAccount5.getBalance());
+
}
@Test
void isEmailValidTest(){
- assertTrue(BankAccount.isEmailValid( "a@b.com"));
- assertFalse( BankAccount.isEmailValid(""));
+
+
+ assertTrue(BankAccount.isEmailValid("a@b.com"));
+ assertTrue(BankAccount.isEmailValid("abc-d@mail.com"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail.com"));
+ assertTrue(BankAccount.isEmailValid("abc@mail.com"));
+ assertTrue(BankAccount.isEmailValid("abc_def@mail.com"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail.cc"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail.org"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail.com"));
+ assertTrue(BankAccount.isEmailValid("abc.def@mail.archive.com"));
+
+ //tests the equivalence class for no period.
+ assertFalse(BankAccount.isEmailValid("a@b"));
+ //tests for no domain after @ sign
+ assertFalse(BankAccount.isEmailValid("ab.com@j"));
+ //Tests for an invalid domain because it is too short
+ assertFalse(BankAccount.isEmailValid("ab@j.c"));
+ //tests for a domain that is invalid because it is too long.
+ assertFalse(BankAccount.isEmailValid("ab@domain.c"));
+ //Tests for a domain that comes before the @ sign and not after
+ assertFalse(BankAccount.isEmailValid("ab.com@j"));
+ //Tests for an email without an @ sign
+ assertFalse(BankAccount.isEmailValid("ab#c#domain.com"));
+ //Tests for an email that has a special character before the @ sign.
+ assertFalse(BankAccount.isEmailValid("abc-@mail.com"));
+ //tests for a an email that has double special characters
+ assertFalse(BankAccount.isEmailValid("abc..def@mail.com"));
+ //tests for an email that starts with a special character
+ assertFalse(BankAccount.isEmailValid(".abc@mail.com"));
+ //tests for an email that has an invalid character.
+ assertFalse(BankAccount.isEmailValid("abc$def@mail.com"));
+ //tests for an email that has invalid domain after the period because it is too short
+ assertFalse(BankAccount.isEmailValid("abc.def@mail.c"));
+ //tests for an email that has an invalid character after the @ sign.
+ assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com"));
+ //tests for an email that has no period after the @ sign
+ assertFalse(BankAccount.isEmailValid("abc.def@mail"));
+ //tets for an email that has double special characters after the @ sign
+ assertFalse(BankAccount.isEmailValid("abc.def@mail..com"));
+ //tests for a special character at the end of the email.
+ assertFalse(BankAccount.isEmailValid("abc@def.co-"));
+
+
}
@Test
void constructorTest() {
BankAccount bankAccount = new BankAccount("a@b.com", 200);
-
assertEquals("a@b.com", bankAccount.getEmail());
assertEquals(200, bankAccount.getBalance());
//check for exception thrown correctly
assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100));
+
+ assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100.908)); //no email inputed and invalid starting balance
+
+ assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@b.com", 10.804)); //throws exception for illegal starting balance
+
}
-}
\ No newline at end of file
+}
+
diff --git a/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java
new file mode 100644
index 00000000..cf805fae
--- /dev/null
+++ b/src/test/java/edu/ithaca/dragon/bank/CentralBankTest.java
@@ -0,0 +1,29 @@
+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 CentralBankTest {
+
+
+
+ @Test
+ void checkBalance() {
+ BankAccount customerCollection[]= new BankAccount[1];
+ customerCollection[0] = new BankAccount("a@b.com",305);
+
+ //checks the balance of an account in the collection
+ BankAccount bankAccount = new BankAccount("a@b.com",305);
+ CentralBank cb = new CentralBank();
+ assertEquals(305, cb.checkBalance("a@b.com",customerCollection));
+
+ //asks for the balance of an account not in the collection
+ assertThrows(IllegalArgumentException.class, ()-> cb.checkBalance("ab@c.com",customerCollection));
+
+
+
+ }
+ }
+