Leon 5 年前
父节点
当前提交
dd7477ec5d

+ 26
- 0
src/test/java/rocks/zipcode/quiz5/collections/bank/RemoveBankAccountByIndexTest.java 查看文件

@@ -41,4 +41,30 @@ public class RemoveBankAccountByIndexTest {
41 41
         Assert.assertTrue(bank.containsBankAccount(bankAccount1));
42 42
         Assert.assertFalse(bank.containsBankAccount(bankAccount2));
43 43
     }
44
+
45
+
46
+    @Test
47
+    public void test3() {
48
+        // given
49
+        Bank bank = new Bank();
50
+        BankAccount bankAccount1 = new BankAccount();
51
+        BankAccount bankAccount2 = new BankAccount();
52
+        BankAccount bankAccount3= new BankAccount();
53
+
54
+        bank.addBankAccount(bankAccount1);
55
+        bank.addBankAccount(bankAccount2);
56
+        bank.addBankAccount(bankAccount3);
57
+
58
+        Assert.assertTrue(bank.containsBankAccount(bankAccount1));
59
+        Assert.assertTrue(bank.containsBankAccount(bankAccount2));
60
+        Assert.assertTrue(bank.containsBankAccount(bankAccount3));
61
+
62
+        // when
63
+        bank.removeBankAccountByIndex(2);
64
+
65
+        // then
66
+        Assert.assertTrue(bank.containsBankAccount(bankAccount1));
67
+        Assert.assertTrue(bank.containsBankAccount(bankAccount2));
68
+        Assert.assertFalse(bank.containsBankAccount(bankAccount3));
69
+    }
44 70
 }

+ 0
- 7
src/test/java/rocks/zipcode/quiz5/collections/food/ApplyCondimentTest.java 查看文件

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz5.collections.food;
2
-
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
6
-public class ApplyCondimentTest {
7
-}

+ 0
- 7
src/test/java/rocks/zipcode/quiz5/collections/food/ApplySpiceTest.java 查看文件

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz5.collections.food;
2
-
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
6
-public class ApplySpiceTest {
7
-}

+ 0
- 7
src/test/java/rocks/zipcode/quiz5/collections/food/GetAllCondimentsTest.java 查看文件

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz5.collections.food;
2
-
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
6
-public class GetAllCondimentsTest {
7
-}

+ 78
- 3
src/test/java/rocks/zipcode/quiz5/collections/food/GetAllSpicesTest.java 查看文件

@@ -1,7 +1,82 @@
1 1
 package rocks.zipcode.quiz5.collections.food;
2 2
 
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz5.collections.Food;
6
+import rocks.zipcode.quiz5.objectorientation.Curry;
7
+import rocks.zipcode.quiz5.objectorientation.Ginger;
8
+import rocks.zipcode.quiz5.objectorientation.Pepper;
9
+import rocks.zipcode.quiz5.objectorientation.Spice;
10
+
11
+import java.util.Arrays;
12
+import java.util.List;
13
+import java.util.function.Supplier;
14
+
6 15
 public class GetAllSpicesTest {
16
+    @Test
17
+    public void test1() {
18
+        // given
19
+        test(() -> Arrays.asList(
20
+                (Spice) new Pepper(),
21
+                (Spice) new Ginger(),
22
+                (Spice) new Curry()));
23
+    }
24
+
25
+    @Test
26
+    public void test2() {
27
+        // given
28
+        test(() -> Arrays.asList(
29
+                (Spice) new Pepper(),
30
+                (Spice) new Pepper(),
31
+                (Spice) new Ginger(),
32
+                (Spice) new Curry()));
33
+    }
34
+
35
+
36
+    @Test
37
+    public void test3() {
38
+        // given
39
+        test(() -> Arrays.asList(
40
+                (Spice) new Pepper(),
41
+                (Spice) new Pepper(),
42
+                (Spice) new Ginger(),
43
+                (Spice) new Ginger(),
44
+                (Spice) new Curry()));
45
+    }
46
+
47
+
48
+    @Test
49
+    public void test4() {
50
+        // given
51
+        test(() -> Arrays.asList((Spice) new Curry()));
52
+    }
53
+
54
+    @Test
55
+    public void test5() {
56
+        // given
57
+        test(() -> Arrays.asList((Spice) new Ginger()));
58
+    }
59
+
60
+    @Test
61
+    public void test6() {
62
+        // given
63
+        test(() -> Arrays.asList((Spice) new Pepper()));
64
+    }
65
+
66
+    private void test(Supplier<List<Spice>> listSupplier) {
67
+        // given there is some food
68
+        Food food = new Food();
69
+
70
+        // given there is a list of spices to apply
71
+        List<Spice> expected = listSupplier.get();
72
+
73
+        // given spices are applied to the food
74
+        expected.forEach(spice -> food.applySpice(spice));
75
+
76
+        // when spice on food is evaluated
77
+        List<Spice> actual = food.getAllSpices();
78
+
79
+        // then
80
+        Assert.assertEquals(expected, actual);
81
+    }
7 82
 }

+ 0
- 7
src/test/java/rocks/zipcode/quiz5/collections/food/GetCondimentCountTest.java 查看文件

@@ -1,7 +0,0 @@
1
-package rocks.zipcode.quiz5.collections.food;
2
-
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
6
-public class GetCondimentCountTest {
7
-}

+ 67
- 3
src/test/java/rocks/zipcode/quiz5/collections/food/GetSpiceCountTest.java 查看文件

@@ -1,7 +1,71 @@
1 1
 package rocks.zipcode.quiz5.collections.food;
2 2
 
3
-/**
4
- * @author leon on 01/01/2019.
5
- */
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz5.collections.Food;
6
+import rocks.zipcode.quiz5.objectorientation.Curry;
7
+import rocks.zipcode.quiz5.objectorientation.Ginger;
8
+import rocks.zipcode.quiz5.objectorientation.Pepper;
9
+import rocks.zipcode.quiz5.objectorientation.Spice;
10
+
11
+import java.util.Map;
12
+import java.util.function.Supplier;
13
+
6 14
 public class GetSpiceCountTest {
15
+    @Test
16
+    public void test1() {
17
+        test(5, Pepper::new);
18
+    }
19
+
20
+    @Test
21
+    public void test2() {
22
+        test(10, Pepper::new);
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        test(3, Curry::new);
28
+    }
29
+
30
+
31
+    @Test
32
+    public void test4() {
33
+        test(6, Curry::new);
34
+    }
35
+
36
+    @Test
37
+    public void test5() {
38
+        test(2, Ginger::new);
39
+    }
40
+
41
+    @Test
42
+    public void test6() {
43
+        test(4, Ginger::new);
44
+    }
45
+
46
+    public void test(Integer amountOfIngredients, Supplier<?> ingredientSupplier) {
47
+        // we should expect `amountOfIngredients` to be fetched from mapping
48
+        Integer expected = amountOfIngredients;
49
+
50
+        // given there is some food
51
+        Food food = new Food();
52
+
53
+        // given there is a potential for existence of spice
54
+        Spice spice = null;
55
+
56
+        // given food spice is applied to food
57
+        for (int i = 0; i < amountOfIngredients; i++) {
58
+            spice = (Spice) ingredientSupplier.get();
59
+            food.applySpice(spice);
60
+        }
61
+
62
+        // when mapping is created
63
+        Map<Class<? extends Spice>, Integer> amountOfPeppers = food.getSpiceCount();
64
+
65
+        // when mapping is evaluated
66
+        Integer actual = amountOfPeppers.get(spice.getClass());
67
+
68
+        // then
69
+        Assert.assertEquals(expected, actual);
70
+    }
7 71
 }

+ 16
- 8
src/test/java/rocks/zipcode/quiz5/objectorientation/bankaccount/DepositNegativeTest.java 查看文件

@@ -10,27 +10,35 @@ import rocks.zipcode.quiz5.objectorientation.account.Transactable;
10 10
  */
11 11
 @SuppressWarnings("all")
12 12
 public class DepositNegativeTest {
13
-
14
-
15
-    @Test(expected = IllegalArgumentException.class)
13
+    @Test
16 14
     public void test1() {
17
-        test(100.0, -1.0);
15
+        test(100.0, 80.0);
18 16
     }
19 17
 
20
-    @Test(expected = IllegalArgumentException.class)
18
+    @Test
21 19
     public void test2() {
20
+        test(150.0, 70.0);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        test(100.0, 180.0);
26
+    }
27
+
28
+    @Test
29
+    public void test4() {
22 30
         test(10.0, 50.0);
23 31
     }
24 32
 
25
-    public void test(Double initialBalance, Double witdrawalAmount) {
33
+    public void test(Double initialBalance, Double depositAmount) {
26 34
         // given
27
-        Double expected = initialBalance + witdrawalAmount;
35
+        Double expected = initialBalance + depositAmount;
28 36
         BankAccount bankAccount = new BankAccount();
29 37
         Transactable transactable = (Transactable)bankAccount;
30 38
         bankAccount.setBalance(initialBalance);
31 39
 
32 40
         // when
33
-        transactable.deposit(witdrawalAmount);
41
+        transactable.deposit(depositAmount);
34 42
         Double actual = transactable.getBalance();
35 43
 
36 44
         // then

+ 0
- 46
src/test/java/rocks/zipcode/quiz5/objectorientation/bankaccount/DepositTest.java 查看文件

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

+ 8
- 0
src/test/java/rocks/zipcode/quiz5/objectorientation/employee/SetBankAccountTest.java 查看文件

@@ -36,6 +36,14 @@ public class SetBankAccountTest {
36 36
     }
37 37
 
38 38
 
39
+
40
+
41
+    @Test
42
+    public void tes4() {
43
+        test(20.0);
44
+    }
45
+
46
+
39 47
     public void test(Double expectedBalance) {
40 48
         // given
41 49
         Employee employee = new Employee();

+ 0
- 79
src/test/java/rocks/zipcode/quiz5/objectorientation/food/GetAllSpicesTest.java 查看文件

@@ -1,79 +0,0 @@
1
-package rocks.zipcode.quiz5.objectorientation.food;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-import rocks.zipcode.quiz5.collections.Food;
6
-import rocks.zipcode.quiz5.objectorientation.Curry;
7
-import rocks.zipcode.quiz5.objectorientation.Ginger;
8
-import rocks.zipcode.quiz5.objectorientation.Pepper;
9
-import rocks.zipcode.quiz5.objectorientation.Spice;
10
-
11
-import java.util.Arrays;
12
-import java.util.List;
13
-import java.util.function.Supplier;
14
-
15
-public class GetAllSpicesTest {
16
-    @Test
17
-    public void test1() {
18
-        // given
19
-        test(() -> Arrays.asList(
20
-                (Spice) new Pepper(),
21
-                (Spice) new Ginger(),
22
-                (Spice) new Curry()));
23
-    }
24
-
25
-    @Test
26
-    public void test2() {
27
-        // given
28
-        test(() -> Arrays.asList(
29
-                (Spice) new Pepper(),
30
-                (Spice) new Pepper(),
31
-                (Spice) new Ginger(),
32
-                (Spice) new Curry()));
33
-    }
34
-
35
-
36
-    @Test
37
-    public void test3() {
38
-        // given
39
-        test(() -> Arrays.asList(
40
-                (Spice) new Pepper(),
41
-                (Spice) new Pepper(),
42
-                (Spice) new Ginger(),
43
-                (Spice) new Ginger(),
44
-                (Spice) new Curry()));
45
-    }
46
-
47
-
48
-    @Test
49
-    public void test4() {
50
-        // given
51
-        test(() -> Arrays.asList((Spice) new Curry()));
52
-    }
53
-
54
-    @Test
55
-    public void test5() {
56
-        // given
57
-        test(() -> Arrays.asList((Spice) new Ginger()));
58
-    }
59
-
60
-    @Test
61
-    public void test6() {
62
-        // given
63
-        test(() -> Arrays.asList((Spice) new Pepper()));
64
-    }
65
-
66
-    private void test(Supplier<List<Spice>> listSupplier) {
67
-        List<Spice> expected = listSupplier.get();
68
-        Food food = new Food();
69
-        for (Spice spice : expected) {
70
-            food.applySpice(spice);
71
-        }
72
-
73
-        // when
74
-        List<Spice> actual = food.getAllSpices();
75
-
76
-        // then
77
-        Assert.assertEquals(expected, actual);
78
-    }
79
-}

+ 0
- 63
src/test/java/rocks/zipcode/quiz5/objectorientation/food/GetSpiceCountTest.java 查看文件

@@ -1,63 +0,0 @@
1
-package rocks.zipcode.quiz5.objectorientation.food;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-import rocks.zipcode.quiz5.collections.Food;
6
-import rocks.zipcode.quiz5.objectorientation.Curry;
7
-import rocks.zipcode.quiz5.objectorientation.Ginger;
8
-import rocks.zipcode.quiz5.objectorientation.Pepper;
9
-import rocks.zipcode.quiz5.objectorientation.Spice;
10
-
11
-import java.util.Map;
12
-import java.util.function.Supplier;
13
-
14
-public class GetSpiceCountTest {
15
-    @Test
16
-    public void test1() {
17
-        test(5, Pepper::new);
18
-    }
19
-
20
-    @Test
21
-    public void test2() {
22
-        test(10, Pepper::new);
23
-    }
24
-
25
-    @Test
26
-    public void test3() {
27
-        test(3, Curry::new);
28
-    }
29
-
30
-
31
-    @Test
32
-    public void test4() {
33
-        test(6, Curry::new);
34
-    }
35
-
36
-    @Test
37
-    public void test5() {
38
-        test(2, Ginger::new);
39
-    }
40
-
41
-    @Test
42
-    public void test6() {
43
-        test(4, Ginger::new);
44
-    }
45
-
46
-    public void test(Integer amountOfIngredients, Supplier<?> ingredientConstructor) {
47
-        // given
48
-        Integer expected = amountOfIngredients;
49
-        Food food = new Food();
50
-        Spice pepper = null;
51
-        for (int i = 0; i < amountOfIngredients; i++) {
52
-            pepper = (Spice) ingredientConstructor.get();
53
-            food.applySpice(pepper);
54
-        }
55
-
56
-        // when
57
-        Map<Class<? extends Spice>, Integer> amountOfPeppers = food.getSpiceCount();
58
-        Integer actual = amountOfPeppers.get(pepper.getClass());
59
-
60
-        // then
61
-        Assert.assertEquals(expected, actual);
62
-    }
63
-}