Leon Hunter 5 years ago
parent
commit
29948c3bc4

+ 5
- 2
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java View File

@@ -4,15 +4,18 @@ package rocks.zipcode.quiz3a.objectorientation.account;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public class BankAccount {
7
-    public void increaseBalance(Double amountToIncreaseBy) {
7
+    public void deposit(Double amountToIncreaseBy) {
8 8
 
9 9
     }
10 10
 
11
-    public void decreaseBalance(Double amountToIncreaseBy) {
11
+    public void withdrawal(Double amountToDecreaseBy) {
12 12
 
13 13
     }
14 14
 
15 15
     public Double getBalance() {
16 16
         return null;
17 17
     }
18
+
19
+    public void setBalance(Double val) {
20
+    }
18 21
 }

+ 0
- 7
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DecreaseBalanceTest.java View File

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
-
3
-/**
4
- * @author leon on 30/12/2018.
5
- */
6
-public class DecreaseBalanceTest {
7
-}

+ 44
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java View File

@@ -0,0 +1,44 @@
1
+package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+
7
+/**
8
+ * @author leon on 30/12/2018.
9
+ */
10
+public class DepositTest {
11
+    @Test
12
+    public void test1() {
13
+        test(100.0, 80.0);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test(150.0, 70.0);
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test(100.0, 180.0);
24
+    }
25
+
26
+    @Test
27
+    public void test4() {
28
+        test(10.0, 50.0);
29
+    }
30
+
31
+    public void test(Double initialBalance, Double withdrawalAmount) {
32
+        // given
33
+        Double expected = initialBalance + withdrawalAmount;
34
+        BankAccount bankAccount = new BankAccount();
35
+        bankAccount.setBalance(initialBalance);
36
+
37
+        // when
38
+        bankAccount.withdrawal(withdrawalAmount);
39
+        Double actual = bankAccount.getBalance();
40
+
41
+        // then
42
+        Assert.assertEquals(expected, actual);
43
+    }
44
+}

+ 0
- 7
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/IncreaseBalanceTest.java View File

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
-
3
-/**
4
- * @author leon on 30/12/2018.
5
- */
6
-public class IncreaseBalanceTest {
7
-}

+ 44
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalTest.java View File

@@ -0,0 +1,44 @@
1
+package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+
7
+/**
8
+ * @author leon on 30/12/2018.
9
+ */
10
+public class WithdrawalTest {
11
+    @Test
12
+    public void test1() {
13
+        test(100.0, 80.0);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test(150.0, 70.0);
19
+    }
20
+
21
+    @Test(expected = IllegalArgumentException.class)
22
+    public void test3() {
23
+        test(100.0, 180.0);
24
+    }
25
+
26
+    @Test(expected = IllegalArgumentException.class)
27
+    public void test4() {
28
+        test(10.0, 50.0);
29
+    }
30
+
31
+    public void test(Double initialBalance, Double withdrawalAmount) {
32
+        // given
33
+        Double expected = initialBalance - withdrawalAmount;
34
+        BankAccount bankAccount = new BankAccount();
35
+        bankAccount.setBalance(initialBalance);
36
+
37
+        // when
38
+        bankAccount.withdrawal(withdrawalAmount);
39
+        Double actual = bankAccount.getBalance();
40
+
41
+        // then
42
+        Assert.assertEquals(expected, actual);
43
+    }
44
+}

+ 1
- 1
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java View File

@@ -39,7 +39,7 @@ public class EmployeeConstructorTest {
39 39
         Double expectedBankAccountBalance = expectedBalance;
40 40
         Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
41 41
         BankAccount bankAccount = new BankAccount();
42
-        bankAccount.increaseBalance(expectedBankAccountBalance);
42
+        bankAccount.setBalance(expectedBankAccountBalance);
43 43
 
44 44
         // when
45 45
         Employee employee = new Employee(bankAccount);