From 7c7e011ff1231a7dfd757117a65100e5f13a3d4f Mon Sep 17 00:00:00 2001 From: "L. Dolio Durant" Date: Fri, 26 Apr 2024 09:08:06 -0400 Subject: [PATCH] Initial commit --- .gitignore | 158 ++++++++++++++++++ README.md | 78 +++++++++ pom.xml | 32 ++++ .../objectorientation/account/Account.java | 13 ++ .../quiz4/objectorientation/account/Bank.java | 17 ++ .../account/BankAccount.java | 9 + .../objectorientation/account/Employee.java | 20 +++ .../account/Transactable.java | 10 ++ .../objectorientation/account/Worker.java | 11 ++ .../account/AccountPolymorphismTest.java | 20 +++ .../account/AccountSetIdTest.java | 38 +++++ .../bank/AddBankAccountTest.java | 22 +++ .../bank/RemoveBankAccountByIndexTest.java | 70 ++++++++ .../BankAccountPolymorphismTest.java | 24 +++ .../bankaccount/DepositNegativeTest.java | 47 ++++++ .../bankaccount/DepositPositiveTest.java | 47 ++++++ .../bankaccount/WithdrawalNegativeTest.java | 53 ++++++ .../bankaccount/WithdrawalPositiveTest.java | 53 ++++++ .../employee/EmployeeConstructorTest.java | 83 +++++++++ .../employee/EmployeeDepositTest.java | 59 +++++++ .../employee/EmployeePolymorphismTest.java | 29 ++++ .../employee/IncreaseHoursWorkedTest.java | 57 +++++++ .../employee/SetBankAccountTest.java | 62 +++++++ 23 files changed, 1012 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/Transactable.java create mode 100644 src/main/java/rocks/zipcode/quiz4/objectorientation/account/Worker.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountPolymorphismTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountSetIdTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bank/AddBankAccountTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bank/RemoveBankAccountByIndexTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/BankAccountPolymorphismTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositNegativeTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositPositiveTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalNegativeTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalPositiveTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeConstructorTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeDepositTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeePolymorphismTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/employee/IncreaseHoursWorkedTest.java create mode 100644 src/test/java/rocks/zipcode/quiz4/objectorientation/employee/SetBankAccountTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bad79fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,158 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +*.iml +.idea/** +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +.project +.classpath +.settings + + +#maven build target +target/ + +.DS_Store +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6166cf4 --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +# Quiz 9-5 + +## Overview +* This quiz will measure your understanding of Object Orientation: + 1. object orientation - (complete the following) + * `Account` + * `BankAccount` + * `Bank` + * `Transactable` + * `Employee` + * `Worker` + + + +
+
+ +## Object Orientation +### Account +* **Description** + * The purpose of this class is to create a model of an `Account`. +* **Methods to Complete** + * `Long getId()` + * `void setId(Long id)` + + + +### BankAccount +* **Description** + * The purpose of this class is to create a subclass of an `Account` which implements `Transactable`. +* **Methods to Complete** + * `void setBalance(Double double)` + + + +### Bank +* **Description** + * The purpose of this class is to create an encapsulation of a `Collection` of `BankAccount` objects. +* **Methods to Complete** + * `BankAccount removeBankAccountByIndex(Integer indexNumber)` + * `void addBankAccount(BankAccount bankAccount)` + * `Boolean containsBankAccount(BankAccount bankAccount)` + + + +### Employee +* **Description** + * The purpose of this class is to create an implementation of a `Worker` and `Transactable` which can `deposit`, `withdrawal`, and `getBalance`, of its composite `BankAccount`. +* **Methods to Complete** + * `BankAccount getBankAccount()` + * `void setBankAccount(BankAccount bankAccount)` + + +### Transactable +* **Description** + * The purpose of this interface is to ensure a class can `deposit`, `withdrawal`, and `getBalance`. +* **Methods to Complete** + * `void deposit(Double amountToIncreaseBy)` + * `void withdrawal(Double amountToDecreaseBy)` + * `Double getBalance()` + +### Worker +* **Description** + * The purpose of this interface is to ensure a class has `BankAccount` +* **Methods to Complete** + * `BankAccount getBankAccount()` + * `void setBankAccount(BankAccount bankAccount)` + + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1ba358f --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + rocks.zipcode + quiz4 + 1.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + junit + junit + 4.12 + test + + + + + diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java new file mode 100644 index 0000000..40eb4a8 --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java @@ -0,0 +1,13 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 30/12/2018. + */ +public class Account extends BankAccount { + public Long getId() { + return null; + } + + public void setId(Long id) { + } +} diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java new file mode 100644 index 0000000..0dd4183 --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java @@ -0,0 +1,17 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 27/12/2018. + */ +public class Bank { + public BankAccount removeBankAccountByIndex(Integer indexNumber) { + return null; + } + + public void addBankAccount(BankAccount bankAccount) { + } + + public Boolean containsBankAccount(BankAccount bankAccount) { + throw new UnsupportedOperationException("Method not yet implemented"); + } +} diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java new file mode 100644 index 0000000..70ccb74 --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java @@ -0,0 +1,9 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 27/12/2018. + */ +public class BankAccount { + public void setBalance(Double val) { + } +} diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java new file mode 100644 index 0000000..8407f1a --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java @@ -0,0 +1,20 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 30/12/2018. + */ +public class Employee { + public Employee() { + } + + public Employee(BankAccount bankAccount) { + } + + public BankAccount getBankAccount() { + return null; + } + + public void setBankAccount(BankAccount bankAccount) { + + } +} diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Transactable.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Transactable.java new file mode 100644 index 0000000..98a3dde --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Transactable.java @@ -0,0 +1,10 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 30/12/2018. + */ +public interface Transactable { + void deposit(Double amountToIncreaseBy); + void withdrawal(Double amountToDecreaseBy); + Double getBalance(); +} diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Worker.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Worker.java new file mode 100644 index 0000000..0f05f7e --- /dev/null +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Worker.java @@ -0,0 +1,11 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +/** + * @author leon on 30/12/2018. + */ +public interface Worker { + void increaseHoursWorked(Double numberOfHours); + Double getHoursWorked(); + Double getHourlyWage(); + Double getMoneyEarned(); +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountPolymorphismTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountPolymorphismTest.java new file mode 100644 index 0000000..95bdbeb --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountPolymorphismTest.java @@ -0,0 +1,20 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author leon on 30/12/2018. + */ +public class AccountPolymorphismTest { + private Object account = new Account(); + @Test + public void test1() { + Assert.assertFalse(account instanceof Transactable); + } + + @Test + public void test2() { + Assert.assertFalse(account instanceof BankAccount); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountSetIdTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountSetIdTest.java new file mode 100644 index 0000000..24b4c6c --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/account/AccountSetIdTest.java @@ -0,0 +1,38 @@ +package rocks.zipcode.quiz4.objectorientation.account; + +import org.junit.Assert; +import org.junit.Test; + +public class AccountSetIdTest { + + private void test(Long expectedId) { + // given + Account account = new Account(); + + // when + account.setId(expectedId); + + // then + Assert.assertEquals(expectedId, account.getId()); + } + + @Test + public void test1() { + test(0L); + } + + @Test + public void test2() { + test(10L); + } + + @Test + public void test3() { + test(Long.MAX_VALUE); + } + + @Test + public void test4() { + test(Long.MIN_VALUE); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/AddBankAccountTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/AddBankAccountTest.java new file mode 100644 index 0000000..b580ed0 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/AddBankAccountTest.java @@ -0,0 +1,22 @@ +package rocks.zipcode.quiz4.objectorientation.bank; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.Bank; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; + +public class AddBankAccountTest { + @Test + public void test1() { + // given + Bank bank = new Bank(); + BankAccount bankAccount = new BankAccount(); + Assert.assertFalse(bank.containsBankAccount(bankAccount)); + + // when + bank.addBankAccount(bankAccount); + + // then + Assert.assertTrue(bank.containsBankAccount(bankAccount)); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/RemoveBankAccountByIndexTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/RemoveBankAccountByIndexTest.java new file mode 100644 index 0000000..7398c9b --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bank/RemoveBankAccountByIndexTest.java @@ -0,0 +1,70 @@ +package rocks.zipcode.quiz4.objectorientation.bank; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.Bank; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; + +public class RemoveBankAccountByIndexTest { + @Test + public void test1() { + // given + Bank bank = new Bank(); + BankAccount bankAccount = new BankAccount(); + bank.addBankAccount(bankAccount); + Assert.assertTrue(bank.containsBankAccount(bankAccount)); + + // when + bank.removeBankAccountByIndex(0); + + // then + Assert.assertFalse(bank.containsBankAccount(bankAccount)); + } + + @Test + public void test2() { + // given + Bank bank = new Bank(); + BankAccount bankAccount1 = new BankAccount(); + BankAccount bankAccount2 = new BankAccount(); + + bank.addBankAccount(bankAccount1); + bank.addBankAccount(bankAccount2); + + Assert.assertTrue(bank.containsBankAccount(bankAccount1)); + Assert.assertTrue(bank.containsBankAccount(bankAccount2)); + + // when + bank.removeBankAccountByIndex(1); + + // then + Assert.assertTrue(bank.containsBankAccount(bankAccount1)); + Assert.assertFalse(bank.containsBankAccount(bankAccount2)); + } + + + @Test + public void test3() { + // given + Bank bank = new Bank(); + BankAccount bankAccount1 = new BankAccount(); + BankAccount bankAccount2 = new BankAccount(); + BankAccount bankAccount3= new BankAccount(); + + bank.addBankAccount(bankAccount1); + bank.addBankAccount(bankAccount2); + bank.addBankAccount(bankAccount3); + + Assert.assertTrue(bank.containsBankAccount(bankAccount1)); + Assert.assertTrue(bank.containsBankAccount(bankAccount2)); + Assert.assertTrue(bank.containsBankAccount(bankAccount3)); + + // when + bank.removeBankAccountByIndex(2); + + // then + Assert.assertTrue(bank.containsBankAccount(bankAccount1)); + Assert.assertTrue(bank.containsBankAccount(bankAccount2)); + Assert.assertFalse(bank.containsBankAccount(bankAccount3)); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/BankAccountPolymorphismTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/BankAccountPolymorphismTest.java new file mode 100644 index 0000000..ae22e44 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/BankAccountPolymorphismTest.java @@ -0,0 +1,24 @@ +package rocks.zipcode.quiz4.objectorientation.bankaccount; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.Account; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 30/12/2018. + */ +public class BankAccountPolymorphismTest { + Object bankAccount = new BankAccount(); + + @Test + public void test1() { + Assert.assertTrue(bankAccount instanceof Transactable); + } + + @Test + public void test2() { + Assert.assertTrue(bankAccount instanceof Account); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositNegativeTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositNegativeTest.java new file mode 100644 index 0000000..fdabb3d --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositNegativeTest.java @@ -0,0 +1,47 @@ +package rocks.zipcode.quiz4.objectorientation.bankaccount; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 02/01/2019. + */ +@SuppressWarnings("all") +public class DepositNegativeTest { + @Test + public void test1() { + test(100.0, 80.0); + } + + @Test + public void test2() { + test(150.0, 70.0); + } + + @Test + public void test3() { + test(100.0, 180.0); + } + + @Test + public void test4() { + test(10.0, 50.0); + } + + public void test(Double initialBalance, Double depositAmount) { + // given + Double expected = initialBalance + depositAmount; + BankAccount bankAccount = new BankAccount(); + Transactable transactable = (Transactable)bankAccount; + bankAccount.setBalance(initialBalance); + + // when + transactable.deposit(depositAmount); + Double actual = transactable.getBalance(); + + // then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositPositiveTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositPositiveTest.java new file mode 100644 index 0000000..10bf550 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/DepositPositiveTest.java @@ -0,0 +1,47 @@ +package rocks.zipcode.quiz4.objectorientation.bankaccount; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 02/01/2019. + */ +@SuppressWarnings("all") +public class DepositPositiveTest { + @Test(expected = IllegalArgumentException.class) + public void test1() { + test(100.0, -1.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test2() { + test(10.0, -50.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test3() { + test(55.0, -500.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test4() { + test(78.0, -90.0); + } + + public void test(Double initialBalance, Double depositAmount) { + // given + Double expected = initialBalance + depositAmount; + BankAccount bankAccount = new BankAccount(); + Transactable transactable = (Transactable)bankAccount; + bankAccount.setBalance(initialBalance); + + // when + transactable.deposit(depositAmount); + Double actual = transactable.getBalance(); + + // then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalNegativeTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalNegativeTest.java new file mode 100644 index 0000000..b369f56 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalNegativeTest.java @@ -0,0 +1,53 @@ +package rocks.zipcode.quiz4.objectorientation.bankaccount; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 30/12/2018. + */ +@SuppressWarnings("all") +public class WithdrawalNegativeTest { + + @Test(expected = IllegalArgumentException.class) + public void test1() { + test(0.0, 1.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test2() { + test(10.0, 50.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test3() { + test(10.0, -50.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test4() { + test(00.0, -50.0); + } + + @Test(expected = IllegalArgumentException.class) + public void test5() { + test(00.0, 0.01); + } + + private void test(Double initialBalance, Double withdrawalAmount) { + // given + Double expected = initialBalance - withdrawalAmount; + BankAccount bankAccount = new BankAccount(); + Transactable transactable = (Transactable)bankAccount; + bankAccount.setBalance(initialBalance); + + // when + transactable.withdrawal(withdrawalAmount); + Double actual = transactable.getBalance(); + + // then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalPositiveTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalPositiveTest.java new file mode 100644 index 0000000..b72a6b2 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/bankaccount/WithdrawalPositiveTest.java @@ -0,0 +1,53 @@ +package rocks.zipcode.quiz4.objectorientation.bankaccount; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 02/01/2019. + */ +@SuppressWarnings("all") +public class WithdrawalPositiveTest { + @Test + public void test1() { + test(100.0, 80.0); + } + + @Test + public void test2() { + test(150.0, 70.0); + } + + + @Test + public void test3() { + test(150.0, 150.0); + } + + @Test + public void test4() { + test(150.0, 100.0); + } + + @Test + public void test5() { + test(150.0, 50.0); + } + + public void test(Double initialBalance, Double withdrawalAmount) { + // given + Double expected = initialBalance - withdrawalAmount; + BankAccount bankAccount = new BankAccount(); + Transactable transactable = (Transactable)bankAccount; + bankAccount.setBalance(initialBalance); + + // when + transactable.withdrawal(withdrawalAmount); + Double actual = transactable.getBalance(); + + // then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeConstructorTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeConstructorTest.java new file mode 100644 index 0000000..67787a4 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeConstructorTest.java @@ -0,0 +1,83 @@ +package rocks.zipcode.quiz4.objectorientation.employee; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Employee; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; +import rocks.zipcode.quiz4.objectorientation.account.Worker; + +/** + * @author leon on 30/12/2018. + */ +public class EmployeeConstructorTest { + @Test + public void testNullaryConstructor() { + // Given : + // given default values are + Double expectedHourlyWage = 35.0; + Double expectedHoursWorked = 0.0; + Double expectedBalance = 0.0; + Double expectedBankAccountBalance = 0.0; + + + + // When : + // when an employee is constructed via nullary constructor + Employee employee = new Employee(); + + // and employee is a `Worker` + Worker workerEmployee = (Worker) employee; + + // and employee is a `Transactable` + Transactable transactableEmployee = (Transactable) employee; + + // and `BankAccount` is `Transactable` + Transactable bankAccount = (Transactable) employee.getBankAccount(); + + + + // Then : + // then the account shouldn't be null + Assert.assertNotNull(employee.getBankAccount()); + + // then their hourly wage should be set to the expected default value + Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage()); + + // then their expected hours worked should be set to the expected default value + Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked()); + + // then their expected balance should be set to the expected default value + Assert.assertEquals(expectedBalance, transactableEmployee.getBalance()); + + // then their expected hours worked should be set to the expected default value + Assert.assertEquals(expectedBankAccountBalance, bankAccount.getBalance()); + } + + @Test + public void testNonNullaryConstructor() { + // given + Double expectedHourlyWage = 35.0; + Double expectedHoursWorked = 0.0; + Double expectedBalance = 15.0; + Double expectedBankAccountBalance = expectedBalance; + Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked; + BankAccount bankAccount = new BankAccount(); + bankAccount.setBalance(expectedBankAccountBalance); + Transactable transactableBankAccount = (Transactable)bankAccount; + + // when + Employee employee = new Employee(bankAccount); + Worker workerEmployee = (Worker) employee; + Transactable transactableEmployee = (Transactable) employee; + + // then + Assert.assertNotNull(employee.getBankAccount()); + Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage()); + Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked()); + Assert.assertEquals(expectedBalance, transactableEmployee.getBalance()); + Assert.assertEquals(expectedMoneyEarned, expectedMoneyEarned); + Assert.assertEquals(expectedBankAccountBalance, transactableBankAccount.getBalance()); + } + +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeDepositTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeDepositTest.java new file mode 100644 index 0000000..323b3f8 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeeDepositTest.java @@ -0,0 +1,59 @@ +package rocks.zipcode.quiz4.objectorientation.employee; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Employee; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 30/12/2018. + */ +public class EmployeeDepositTest { + @Test + public void test1() { + test(0.0, 10.0); + } + + @Test + public void test2() { + test(0.0, 20.0); + } + + @Test + public void test3() { + test(10.0, 100.0); + } + + @Test + public void test4() { + test(20.0, 300.0); + } + + @Test + public void test5() { + test(0.0, 400.0); + } + + + private void test(Double preDepositBalance, Double amountToDeposit) { + // given + Employee employee = new Employee(); + BankAccount bankAccount = employee.getBankAccount(); + Transactable employeeAsTransactable = (Transactable) employee; + + employeeAsTransactable.deposit(preDepositBalance); + Double expectedEmployeeBalance = preDepositBalance + amountToDeposit; + + + // when + employeeAsTransactable.deposit(amountToDeposit); + Double actualEmployeeBalance = employeeAsTransactable.getBalance(); + Double actualBankAccountBalance = ((Transactable)bankAccount).getBalance(); + + + // then + Assert.assertEquals(expectedEmployeeBalance, actualEmployeeBalance); + Assert.assertEquals(expectedEmployeeBalance, actualBankAccountBalance); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeePolymorphismTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeePolymorphismTest.java new file mode 100644 index 0000000..ffc4422 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/EmployeePolymorphismTest.java @@ -0,0 +1,29 @@ +package rocks.zipcode.quiz4.objectorientation.employee; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.Account; +import rocks.zipcode.quiz4.objectorientation.account.Employee; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; +import rocks.zipcode.quiz4.objectorientation.account.Worker; + +/** + * @author leon on 30/12/2018. + */ +public class EmployeePolymorphismTest { + private Object employee = new Employee(); + + @Test + public void test1() { + Assert.assertTrue(employee instanceof Transactable); + } + + @Test + public void test2() { + Assert.assertTrue(employee instanceof Worker); + } + + public void test3() { + Assert.assertFalse(employee instanceof Account); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/IncreaseHoursWorkedTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/IncreaseHoursWorkedTest.java new file mode 100644 index 0000000..2d44dd6 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/IncreaseHoursWorkedTest.java @@ -0,0 +1,57 @@ +package rocks.zipcode.quiz4.objectorientation.employee; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.Employee; +import rocks.zipcode.quiz4.objectorientation.account.Worker; + +/** + * @author leon on 30/12/2018. + */ +public class IncreaseHoursWorkedTest { + + @Test + public void test1() { + // given + test(0.0, 1.0); + } + + @Test + public void test2() { + // given + test(0.0, 5.0); + } + + + @Test + public void test4() { + // given + test(1.0, 10.0); + } + + + @Test + public void test5() { + // given + test(2.0, 2.0); + } + + + private void test(Double numberOfHoursWorkedSoFar, Double numberOfHoursToWork) { + // given + Employee employee = new Employee(); + Worker employeeAsWorker = (Worker) employee; + + employeeAsWorker.increaseHoursWorked(numberOfHoursWorkedSoFar); + Double expected = numberOfHoursWorkedSoFar + numberOfHoursToWork; + + + // when + employeeAsWorker.increaseHoursWorked(numberOfHoursToWork); + Double actual = employeeAsWorker.getHoursWorked(); + + + // then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/SetBankAccountTest.java b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/SetBankAccountTest.java new file mode 100644 index 0000000..f894b31 --- /dev/null +++ b/src/test/java/rocks/zipcode/quiz4/objectorientation/employee/SetBankAccountTest.java @@ -0,0 +1,62 @@ +package rocks.zipcode.quiz4.objectorientation.employee; + +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcode.quiz4.objectorientation.account.BankAccount; +import rocks.zipcode.quiz4.objectorientation.account.Employee; +import rocks.zipcode.quiz4.objectorientation.account.Transactable; + +/** + * @author leon on 30/12/2018. + */ +public class SetBankAccountTest { + @Test + public void test1() { + // given + Employee employee = new Employee(); + BankAccount expected = new BankAccount(); + + // when + employee.setBankAccount(expected); + BankAccount actual = employee.getBankAccount(); + + // then + Assert.assertEquals(expected, actual); + } + + @Test + public void test2() { + test(10.0); + } + + + @Test + public void test3() { + test(15.0); + } + + + + + @Test + public void tes4() { + test(20.0); + } + + + public void test(Double expectedBalance) { + // given + Employee employee = new Employee(); + BankAccount expected = new BankAccount(); + ((Transactable)expected).deposit(expectedBalance); + + // when + employee.setBankAccount(expected); + BankAccount actual = employee.getBankAccount(); + Double actualBalance = ((Transactable)employee).getBalance(); + + // then + Assert.assertEquals(expected, actual); + Assert.assertEquals(expectedBalance, actualBalance); + } +}