Leon 5 jaren geleden
bovenliggende
commit
bc1fe915e7
24 gewijzigde bestanden met toevoegingen van 448 en 140 verwijderingen
  1. 1
    1
      src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java
  2. 1
    1
      src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java
  3. 0
    12
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java
  4. 0
    4
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java
  5. 18
    15
      src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/GetMiddleElementTest.java
  6. 18
    16
      src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/RemoveMiddleCharacterTest.java
  7. 4
    4
      src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java
  8. 4
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/CapitalizeMiddleCharacterTest.java
  9. 22
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/GetMiddleCharacterTest.java
  10. 5
    5
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateConsecutiveCharactersTest.java
  11. 53
    0
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramNegativeTest.java
  12. 16
    5
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramPositiveTest.java
  13. 21
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/LowerCaseMiddleCharacterTest.java
  14. 0
    33
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateCharactersTest.java
  15. 54
    0
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateConsecutiveCharactersTest.java
  16. 39
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositNegativeTest.java
  17. 47
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositPositiveTest.java
  18. 4
    2
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java
  19. 53
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalNegativeTest.java
  20. 17
    8
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalPositiveTest.java
  21. 16
    12
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java
  22. 1
    1
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java
  23. 48
    3
      src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetAllSpicesTest.java
  24. 6
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/spice/SpicePolymorphismTest.java

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java Bestand weergeven

11
     public static String[] removeMiddleElement(String[] values) {
11
     public static String[] removeMiddleElement(String[] values) {
12
         return null;
12
         return null;
13
     }
13
     }
14
-}
14
+}

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java Bestand weergeven

20
         return null;
20
         return null;
21
     }
21
     }
22
 
22
 
23
-    public static Boolean hasDuplicateCharacters(String str) {
23
+    public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24
         return null;
24
         return null;
25
     }
25
     }
26
 
26
 

+ 0
- 12
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java Bestand weergeven

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

+ 0
- 4
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java Bestand weergeven

17
     public void setBankAccount(BankAccount bankAccount) {
17
     public void setBankAccount(BankAccount bankAccount) {
18
 
18
 
19
     }
19
     }
20
-
21
-    public String getName() {
22
-        return null;
23
-    }
24
 }
20
 }

+ 18
- 15
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/GetMiddleElementTest.java Bestand weergeven

9
     public void test1() {
9
     public void test1() {
10
         // given
10
         // given
11
         String expected = "Quick";
11
         String expected = "Quick";
12
-        String[] strings = {"The", expected, "Brown"};
12
+        String[] input = {"The", expected, "Brown"};
13
+        test(expected, input);
13
 
14
 
14
-        // when
15
-        String actual = ArrayUtils.getMiddleElement(strings);
16
-
17
-        //then
18
-        Assert.assertEquals(expected, actual);
19
     }
15
     }
20
 
16
 
21
     @Test
17
     @Test
22
     public void test2() {
18
     public void test2() {
23
         // given
19
         // given
24
         String expected = "Brown";
20
         String expected = "Brown";
25
-        String[] strings = {"The", "Quick", expected, "Fox", "Jumps"};
21
+        String[] input = {"The", "Quick", expected, "Fox", "Jumps"};
22
+        test(expected, input);
26
 
23
 
27
-        // when
28
-        String actual = ArrayUtils.getMiddleElement(strings);
29
-
30
-        //then
31
-        Assert.assertEquals(expected, actual);
32
     }
24
     }
33
 
25
 
34
-
35
     @Test
26
     @Test
36
     public void test3() {
27
     public void test3() {
37
         // given
28
         // given
38
         String expected = "Fox";
29
         String expected = "Fox";
39
-        String[] strings = {"The", "Quick", "Brown", expected, "Jumps", "Over", "The"};
30
+        String[] input = {"The", "Quick", "Brown", expected, "Jumps", "Over", "The"};
31
+        test(expected, input);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void test4() {
37
+        // given
38
+        String expected = "Jumps";
39
+        String[] input = {"The", "Quick", "Brown", "Fox", expected, "Over", "The", "Lazy", "Dog"};
40
+        test(expected, input);
41
+    }
40
 
42
 
43
+    private void test(String expected, String[] input) {
41
         // when
44
         // when
42
-        String actual = ArrayUtils.getMiddleElement(strings);
45
+        String actual = ArrayUtils.getMiddleElement(input);
43
 
46
 
44
         //then
47
         //then
45
         Assert.assertEquals(expected, actual);
48
         Assert.assertEquals(expected, actual);

+ 18
- 16
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/RemoveMiddleCharacterTest.java Bestand weergeven

8
     @Test
8
     @Test
9
     public void test1() {
9
     public void test1() {
10
         // given
10
         // given
11
-        String[] strings = {"The", "Quick", "Brown"};
12
         String[] expected = {"The", "Brown"};
11
         String[] expected = {"The", "Brown"};
12
+        String[] input = {"The", "Quick", "Brown"};
13
+        test(expected, input);
13
 
14
 
14
-        // when
15
-        String[] actual = ArrayUtils.removeMiddleElement(strings);
16
-
17
-        //then
18
-        Assert.assertArrayEquals(expected, actual);
19
     }
15
     }
20
 
16
 
21
     @Test
17
     @Test
22
     public void test2() {
18
     public void test2() {
23
         // given
19
         // given
24
         String[] expected = {"The", "Quick", "Fox", "Jumps"};
20
         String[] expected = {"The", "Quick", "Fox", "Jumps"};
25
-        String[] strings = {"The", "Quick", "Brown", "Fox", "Jumps"};
26
-
27
-        // when
28
-        String[] actual = ArrayUtils.removeMiddleElement(strings);
29
-
30
-        //then
31
-        Assert.assertArrayEquals(expected, actual);
21
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps"};
22
+        test(expected, input);
32
     }
23
     }
33
 
24
 
34
-
35
     @Test
25
     @Test
36
     public void test3() {
26
     public void test3() {
37
         // given
27
         // given
38
-        String[] strings = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The"};
39
         String[] expected = {"The", "Quick", "Brown", "Jumps", "Over", "The"};
28
         String[] expected = {"The", "Quick", "Brown", "Jumps", "Over", "The"};
29
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The"};
30
+        test(expected, input);
31
+    }
32
+
33
+
34
+    @Test
35
+    public void test4() {
36
+        // given
37
+        String[] expected = {"The", "Quick", "Brown", "Fox", "Over", "The", "Lazy", "Dog"};
38
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The", "Lazy", "Dog"};
39
+        test(expected, input);
40
+    }
40
 
41
 
42
+    private void test(String[] expected, String[] input) {
41
         // when
43
         // when
42
-        String[] actual = ArrayUtils.removeMiddleElement(strings);
44
+        String[] actual = ArrayUtils.removeMiddleElement(input);
43
 
45
 
44
         //then
46
         //then
45
         Assert.assertArrayEquals(expected, actual);
47
         Assert.assertArrayEquals(expected, actual);

+ 4
- 4
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java Bestand weergeven

11
     @Test
11
     @Test
12
     public void test1() {
12
     public void test1() {
13
         // given
13
         // given
14
-        test(81.74, 32.70, 49.04);
14
+        test(98.5, 10.5, 88.5);
15
     }
15
     }
16
 
16
 
17
     @Test
17
     @Test
18
     public void test2() {
18
     public void test2() {
19
         // given
19
         // given
20
-        test(1435.93, 689.93, 746.00);
20
+        test(40.12, 19.93, 20.19);
21
     }
21
     }
22
 
22
 
23
     @Test
23
     @Test
24
     public void test3() {
24
     public void test3() {
25
         // given
25
         // given
26
-        test(109896.0, 35354.0, 74542.0);
26
+        test(39.94, 19.94, 20.00);
27
     }
27
     }
28
 
28
 
29
     @Test
29
     @Test
30
     public void test4() {
30
     public void test4() {
31
         // given
31
         // given
32
-        test(12.0, 4.0, 8.0);
32
+        test(100.00, 50.0, 50.0);
33
     }
33
     }
34
 
34
 
35
     @Test
35
     @Test

+ 4
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/CapitalizeMiddleCharacterTest.java Bestand weergeven

10
         // given
10
         // given
11
         String input = "o";
11
         String input = "o";
12
         String expected = "O";
12
         String expected = "O";
13
-
14
-        // when
15
-        String actual = StringUtils.capitalizeMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19
     }
14
     }
20
 
15
 
21
     @Test
16
     @Test
23
         // given
18
         // given
24
         String input = "ooo";
19
         String input = "ooo";
25
         String expected = "oOo";
20
         String expected = "oOo";
21
+        test(expected, input);
22
+    }
26
 
23
 
24
+    private void test(String expected, String input) {
27
         // when
25
         // when
28
         String actual = StringUtils.capitalizeMiddleCharacter(input);
26
         String actual = StringUtils.capitalizeMiddleCharacter(input);
29
 
27
 

+ 22
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/GetMiddleCharacterTest.java Bestand weergeven

10
         // given
10
         // given
11
         String input = "joint";
11
         String input = "joint";
12
         Character expected = 'i';
12
         Character expected = 'i';
13
-
14
-        // when
15
-        Character actual = StringUtils.getMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19
     }
14
     }
20
 
15
 
21
 
16
 
24
         // given
19
         // given
25
         String input = "burnt";
20
         String input = "burnt";
26
         Character expected = 'r';
21
         Character expected = 'r';
22
+        test(expected, input);
23
+    }
27
 
24
 
25
+
26
+    @Test
27
+    public void test3() {
28
+        // given
29
+        String input = "bang!";
30
+        Character expected = 'n';
31
+        test(expected, input);
32
+    }
33
+
34
+    @Test
35
+    public void test4() {
36
+        // given
37
+        String input = "bang!";
38
+        Character expected = 'n';
39
+        test(expected, input);
40
+    }
41
+
42
+    private void test(Character expected, String input) {
28
         // when
43
         // when
29
         Character actual = StringUtils.getMiddleCharacter(input);
44
         Character actual = StringUtils.getMiddleCharacter(input);
30
 
45
 
31
         // then
46
         // then
32
         Assert.assertEquals(expected, actual);
47
         Assert.assertEquals(expected, actual);
33
     }
48
     }
49
+
34
 }
50
 }

src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateCharacterTest.java → src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateConsecutiveCharactersTest.java Bestand weergeven

4
 import org.junit.Test;
4
 import org.junit.Test;
5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
 
6
 
7
-public class HasDuplicateCharacterTest {
7
+public class HasDuplicateConsecutiveCharactersTest {
8
     @Test
8
     @Test
9
     public void test1() {
9
     public void test1() {
10
         String input = "Happy";
10
         String input = "Happy";
11
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
11
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
12
     }
12
     }
13
 
13
 
14
     @Test
14
     @Test
15
     public void test2() {
15
     public void test2() {
16
         String input = "Fool";
16
         String input = "Fool";
17
-        Assert.assertTrue(StringUtils.hasDuplicateCharacters(input));
17
+        Assert.assertTrue(StringUtils.hasDuplicateConsecutiveCharacters(input));
18
     }
18
     }
19
 
19
 
20
     @Test
20
     @Test
21
     public void test3() {
21
     public void test3() {
22
         String input = "George";
22
         String input = "George";
23
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
23
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
24
     }
24
     }
25
 
25
 
26
     @Test
26
     @Test
27
     public void test4() {
27
     public void test4() {
28
         String input = "False";
28
         String input = "False";
29
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
29
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
30
     }
30
     }
31
 }
31
 }

+ 53
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramNegativeTest.java Bestand weergeven

1
+package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
+
7
+/**
8
+ * @author leon on 02/01/2019.
9
+ */
10
+public class IsogramNegativeTest {
11
+    @Test
12
+    public void test1() {
13
+        String input = "XX";
14
+        Assert.assertFalse(StringUtils.isIsogram(input));
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        String input = "XXX";
20
+        Assert.assertFalse(StringUtils.isIsogram(input));
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        String input = "AA";
26
+        Assert.assertFalse(StringUtils.isIsogram(input));
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        String input = "AAA";
32
+        Assert.assertFalse(StringUtils.isIsogram(input));
33
+    }
34
+
35
+
36
+    @Test
37
+    public void test5() {
38
+        String input = "Here";
39
+        Assert.assertFalse(StringUtils.isIsogram(input));
40
+    }
41
+
42
+    @Test
43
+    public void test6() {
44
+        String input = "Teared";
45
+        Assert.assertFalse(StringUtils.isIsogram(input));
46
+    }
47
+
48
+    @Test
49
+    public void test7() {
50
+        String input = "Brown Fox";
51
+        Assert.assertFalse(StringUtils.isIsogram(input));
52
+    }
53
+}

src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsIsoGramTest.java → src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramPositiveTest.java Bestand weergeven

4
 import org.junit.Test;
4
 import org.junit.Test;
5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
 
6
 
7
-public class IsIsoGramTest {
7
+public class IsogramPositiveTest {
8
     @Test
8
     @Test
9
     public void test1() {
9
     public void test1() {
10
         String input = "Jump";
10
         String input = "Jump";
19
 
19
 
20
     @Test
20
     @Test
21
     public void test3() {
21
     public void test3() {
22
-        String input = "Here";
23
-        Assert.assertFalse(StringUtils.isIsogram(input));
22
+        String input = "Jj0Oo";
23
+        Assert.assertTrue(StringUtils.isIsogram(input));
24
     }
24
     }
25
 
25
 
26
+
26
     @Test
27
     @Test
27
     public void test4() {
28
     public void test4() {
28
-        String input = "Teared";
29
-        Assert.assertFalse(StringUtils.isIsogram(input));
29
+        String input = "The Quick";
30
+        Assert.assertTrue(StringUtils.isIsogram(input));
30
     }
31
     }
32
+
33
+    @Test
34
+    public void test5() {
35
+        String input = "Brown";
36
+        Assert.assertTrue(StringUtils.isIsogram(input));
37
+    }
38
+
39
+
40
+
41
+
31
 }
42
 }

+ 21
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/LowerCaseMiddleCharacterTest.java Bestand weergeven

10
         // given
10
         // given
11
         String input = "O";
11
         String input = "O";
12
         String expected = "o";
12
         String expected = "o";
13
-
14
-        // when
15
-        String actual = StringUtils.lowerCaseMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19
     }
14
     }
20
 
15
 
21
     @Test
16
     @Test
23
         // given
18
         // given
24
         String input = "OOO";
19
         String input = "OOO";
25
         String expected = "OoO";
20
         String expected = "OoO";
21
+        test(expected, input);
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        // given
27
+        String input = "APPLE";
28
+        String expected = "APpLE";
29
+        test(expected, input);
30
+    }
31
+
32
+    @Test
33
+    public void test4() {
34
+        // given
35
+        String input = "Waffle Sauces";
36
+        String expected = "Waffle Sauces";
37
+        test(expected, input);
38
+    }
26
 
39
 
40
+    public void test(String expected, String input) {
27
         // when
41
         // when
28
         String actual = StringUtils.lowerCaseMiddleCharacter(input);
42
         String actual = StringUtils.lowerCaseMiddleCharacter(input);
29
 
43
 
30
         // then
44
         // then
31
         Assert.assertEquals(expected, actual);
45
         Assert.assertEquals(expected, actual);
32
     }
46
     }
47
+
33
 }
48
 }

+ 0
- 33
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateCharactersTest.java Bestand weergeven

1
-package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
-
7
-public class RemoveDuplicateCharactersTest {
8
-    @Test
9
-    public void test1() {
10
-        // given
11
-        String input = "Fool";
12
-        String expected = "Fl";
13
-
14
-        // when
15
-        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
19
-    }
20
-
21
-    @Test
22
-    public void test2() {
23
-        // given
24
-        String input = "Mississippi";
25
-        String expected = "Miiii";
26
-
27
-        // when
28
-        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
29
-
30
-        // then
31
-        Assert.assertEquals(expected, actual);
32
-    }
33
-}

+ 54
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateConsecutiveCharactersTest.java Bestand weergeven

1
+package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
+
7
+public class RemoveDuplicateConsecutiveCharactersTest {
8
+    @Test
9
+    public void test1() {
10
+        // given
11
+        String input = "Fool";
12
+        String expected = "Fl";
13
+        test(expected, input);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        // given
19
+        String input = "Mississippi";
20
+        String expected = "Miiii";
21
+        test(expected, input);
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        // given
27
+        String input = "Fleet";
28
+        String expected = "Flt";
29
+        test(expected, input);
30
+    }
31
+
32
+    @Test
33
+    public void test4() {
34
+        // given
35
+        String input = "Independence";
36
+        String expected = input;
37
+        test(expected, input);
38
+    }
39
+    @Test
40
+    public void test5() {
41
+        // given
42
+        String input = "Integer";
43
+        String expected = input;
44
+        test(expected, input);
45
+    }
46
+
47
+    public void test(String expected, String input) {
48
+        // when
49
+        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
50
+
51
+        // then
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+}

+ 39
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositNegativeTest.java Bestand weergeven

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
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 02/01/2019.
10
+ */
11
+@SuppressWarnings("all")
12
+public class DepositNegativeTest {
13
+
14
+
15
+    @Test(expected = IllegalArgumentException.class)
16
+    public void test1() {
17
+        test(100.0, -1.0);
18
+    }
19
+
20
+    @Test(expected = IllegalArgumentException.class)
21
+    public void test2() {
22
+        test(10.0, 50.0);
23
+    }
24
+
25
+    public void test(Double initialBalance, Double witdrawalAmount) {
26
+        // given
27
+        Double expected = initialBalance + witdrawalAmount;
28
+        BankAccount bankAccount = new BankAccount();
29
+        Transactable transactable = (Transactable)bankAccount;
30
+        bankAccount.setBalance(initialBalance);
31
+
32
+        // when
33
+        transactable.deposit(witdrawalAmount);
34
+        Double actual = transactable.getBalance();
35
+
36
+        // then
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+}

+ 47
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositPositiveTest.java Bestand weergeven

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
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 02/01/2019.
10
+ */
11
+@SuppressWarnings("all")
12
+public class DepositPositiveTest {
13
+    @Test(expected = IllegalArgumentException.class)
14
+    public void test1() {
15
+        test(100.0, -1.0);
16
+    }
17
+
18
+    @Test(expected = IllegalArgumentException.class)
19
+    public void test2() {
20
+        test(10.0, 50.0);
21
+    }
22
+
23
+    @Test(expected = IllegalArgumentException.class)
24
+    public void test3() {
25
+        test(55.0, 500.0);
26
+    }
27
+
28
+    @Test(expected = IllegalArgumentException.class)
29
+    public void test4() {
30
+        test(78.0, 90.0);
31
+    }
32
+
33
+    public void test(Double initialBalance, Double witdrawalAmount) {
34
+        // given
35
+        Double expected = initialBalance + witdrawalAmount;
36
+        BankAccount bankAccount = new BankAccount();
37
+        Transactable transactable = (Transactable)bankAccount;
38
+        bankAccount.setBalance(initialBalance);
39
+
40
+        // when
41
+        transactable.deposit(witdrawalAmount);
42
+        Double actual = transactable.getBalance();
43
+
44
+        // then
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+}

+ 4
- 2
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java Bestand weergeven

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
6
 
7
 
7
 /**
8
 /**
8
  * @author leon on 30/12/2018.
9
  * @author leon on 30/12/2018.
32
         // given
33
         // given
33
         Double expected = initialBalance + witdrawalAmount;
34
         Double expected = initialBalance + witdrawalAmount;
34
         BankAccount bankAccount = new BankAccount();
35
         BankAccount bankAccount = new BankAccount();
36
+        Transactable transactable = (Transactable)bankAccount;
35
         bankAccount.setBalance(initialBalance);
37
         bankAccount.setBalance(initialBalance);
36
 
38
 
37
         // when
39
         // when
38
-        bankAccount.deposit(witdrawalAmount);
39
-        Double actual = bankAccount.getBalance();
40
+        transactable.deposit(witdrawalAmount);
41
+        Double actual = transactable.getBalance();
40
 
42
 
41
         // then
43
         // then
42
         Assert.assertEquals(expected, actual);
44
         Assert.assertEquals(expected, actual);

+ 53
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalNegativeTest.java Bestand weergeven

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
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 30/12/2018.
10
+ */
11
+@SuppressWarnings("all")
12
+public class WithdrawalNegativeTest {
13
+
14
+    @Test(expected = IllegalArgumentException.class)
15
+    public void test1() {
16
+        test(0.0, 1.0);
17
+    }
18
+
19
+    @Test(expected = IllegalArgumentException.class)
20
+    public void test2() {
21
+        test(10.0, 50.0);
22
+    }
23
+
24
+    @Test(expected = IllegalArgumentException.class)
25
+    public void test3() {
26
+        test(10.0, -50.0);
27
+    }
28
+
29
+    @Test(expected = IllegalArgumentException.class)
30
+    public void test4() {
31
+        test(00.0, -50.0);
32
+    }
33
+
34
+    @Test(expected = IllegalArgumentException.class)
35
+    public void test5() {
36
+        test(00.0, 0.01);
37
+    }
38
+
39
+    private void test(Double initialBalance, Double withdrawalAmount) {
40
+        // given
41
+        Double expected = initialBalance - withdrawalAmount;
42
+        BankAccount bankAccount = new BankAccount();
43
+        Transactable transactable = (Transactable)bankAccount;
44
+        bankAccount.setBalance(initialBalance);
45
+
46
+        // when
47
+        transactable.withdrawal(withdrawalAmount);
48
+        Double actual = transactable.getBalance();
49
+
50
+        // then
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+}

src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalTest.java → src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalPositiveTest.java Bestand weergeven

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
6
 
7
 
7
 /**
8
 /**
8
- * @author leon on 30/12/2018.
9
+ * @author leon on 02/01/2019.
9
  */
10
  */
10
-public class WithdrawalTest {
11
+@SuppressWarnings("all")
12
+public class WithdrawalPositiveTest {
11
     @Test
13
     @Test
12
     public void test1() {
14
     public void test1() {
13
         test(100.0, 80.0);
15
         test(100.0, 80.0);
18
         test(150.0, 70.0);
20
         test(150.0, 70.0);
19
     }
21
     }
20
 
22
 
21
-    @Test(expected = IllegalArgumentException.class)
23
+
24
+    @Test
22
     public void test3() {
25
     public void test3() {
23
-        test(100.0, 180.0);
26
+        test(150.0, 150.0);
24
     }
27
     }
25
 
28
 
26
-    @Test(expected = IllegalArgumentException.class)
29
+    @Test
27
     public void test4() {
30
     public void test4() {
28
-        test(10.0, 50.0);
31
+        test(150.0, 100.0);
32
+    }
33
+
34
+    @Test
35
+    public void test5() {
36
+        test(150.0, 50.0);
29
     }
37
     }
30
 
38
 
31
     public void test(Double initialBalance, Double withdrawalAmount) {
39
     public void test(Double initialBalance, Double withdrawalAmount) {
32
         // given
40
         // given
33
         Double expected = initialBalance - withdrawalAmount;
41
         Double expected = initialBalance - withdrawalAmount;
34
         BankAccount bankAccount = new BankAccount();
42
         BankAccount bankAccount = new BankAccount();
43
+        Transactable transactable = (Transactable)bankAccount;
35
         bankAccount.setBalance(initialBalance);
44
         bankAccount.setBalance(initialBalance);
36
 
45
 
37
         // when
46
         // when
38
-        bankAccount.withdrawal(withdrawalAmount);
39
-        Double actual = bankAccount.getBalance();
47
+        transactable.withdrawal(withdrawalAmount);
48
+        Double actual = transactable.getBalance();
40
 
49
 
41
         // then
50
         // then
42
         Assert.assertEquals(expected, actual);
51
         Assert.assertEquals(expected, actual);

+ 16
- 12
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java Bestand weergeven

15
     public void testNullaryConstructor() {
15
     public void testNullaryConstructor() {
16
         // given
16
         // given
17
         Employee employee = new Employee();
17
         Employee employee = new Employee();
18
-        Worker worker = (Worker) employee;
19
-        Transactable transactable = (Transactable) employee;
18
+        Worker workerEmployee = (Worker) employee;
19
+        Transactable transactableEmployee = (Transactable) employee;
20
+        Transactable bankAccount = (Transactable) employee.getBankAccount();
21
+
22
+
20
 
23
 
21
         Double expectedHourlyWage = 35.0;
24
         Double expectedHourlyWage = 35.0;
22
         Double expectedHoursWorked = 0.0;
25
         Double expectedHoursWorked = 0.0;
24
         Double expectedBankAccountBalance = 0.0;
27
         Double expectedBankAccountBalance = 0.0;
25
 
28
 
26
         Assert.assertNotNull(employee.getBankAccount());
29
         Assert.assertNotNull(employee.getBankAccount());
27
-        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
28
-        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
29
-        Assert.assertEquals(expectedBalance, transactable.getBalance());
30
-        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
30
+        Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage());
31
+        Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked());
32
+        Assert.assertEquals(expectedBalance, transactableEmployee.getBalance());
33
+        Assert.assertEquals(expectedBankAccountBalance, bankAccount.getBalance());
31
     }
34
     }
32
 
35
 
33
     @Test
36
     @Test
40
         Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
43
         Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
41
         BankAccount bankAccount = new BankAccount();
44
         BankAccount bankAccount = new BankAccount();
42
         bankAccount.setBalance(expectedBankAccountBalance);
45
         bankAccount.setBalance(expectedBankAccountBalance);
46
+        Transactable transactableBankAccount = (Transactable)bankAccount;
43
 
47
 
44
         // when
48
         // when
45
         Employee employee = new Employee(bankAccount);
49
         Employee employee = new Employee(bankAccount);
46
-        Worker worker = (Worker) employee;
47
-        Transactable transactable = (Transactable) employee;
50
+        Worker workerEmployee = (Worker) employee;
51
+        Transactable transactableEmployee = (Transactable) employee;
48
 
52
 
49
 
53
 
50
         Assert.assertNotNull(employee.getBankAccount());
54
         Assert.assertNotNull(employee.getBankAccount());
51
-        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
52
-        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
53
-        Assert.assertEquals(expectedBalance, transactable.getBalance());
55
+        Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage());
56
+        Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked());
57
+        Assert.assertEquals(expectedBalance, transactableEmployee.getBalance());
54
         Assert.assertEquals(expectedMoneyEarned, expectedMoneyEarned);
58
         Assert.assertEquals(expectedMoneyEarned, expectedMoneyEarned);
55
-        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
59
+        Assert.assertEquals(expectedBankAccountBalance, transactableBankAccount.getBalance());
56
     }
60
     }
57
 
61
 
58
 }
62
 }

+ 1
- 1
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java Bestand weergeven

49
         // when
49
         // when
50
         employeeAsTransactable.deposit(amountToDeposit);
50
         employeeAsTransactable.deposit(amountToDeposit);
51
         Double actualEmployeeBalance = employeeAsTransactable.getBalance();
51
         Double actualEmployeeBalance = employeeAsTransactable.getBalance();
52
-        Double actualBankAccountBalance = bankAccount.getBalance();
52
+        Double actualBankAccountBalance = ((Transactable)bankAccount).getBalance();
53
 
53
 
54
 
54
 
55
         // then
55
         // then

+ 48
- 3
src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetAllSpicesTest.java Bestand weergeven

10
 
10
 
11
 import java.util.Arrays;
11
 import java.util.Arrays;
12
 import java.util.List;
12
 import java.util.List;
13
+import java.util.function.Supplier;
13
 
14
 
14
 public class GetAllSpicesTest {
15
 public class GetAllSpicesTest {
15
     @Test
16
     @Test
16
     public void test1() {
17
     public void test1() {
17
         // given
18
         // given
18
-        Food food = new Food();
19
-        List<Spice> expected = Arrays.asList(
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(),
20
                 (Spice) new Pepper(),
41
                 (Spice) new Pepper(),
21
                 (Spice) new Ginger(),
42
                 (Spice) new Ginger(),
22
-                (Spice) new Curry());
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
+    }
23
 
65
 
66
+    private void test(Supplier<List<Spice>> listSupplier) {
67
+        List<Spice> expected = listSupplier.get();
68
+        Food food = new Food();
24
         for (Spice spice : expected) {
69
         for (Spice spice : expected) {
25
             food.applySpice(spice);
70
             food.applySpice(spice);
26
         }
71
         }

+ 6
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/spice/SpicePolymorphismTest.java Bestand weergeven

2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.Curry;
5
 import rocks.zipcode.quiz3a.objectorientation.Ginger;
6
 import rocks.zipcode.quiz3a.objectorientation.Ginger;
6
 import rocks.zipcode.quiz3a.objectorientation.Pepper;
7
 import rocks.zipcode.quiz3a.objectorientation.Pepper;
7
 import rocks.zipcode.quiz3a.objectorientation.Spice;
8
 import rocks.zipcode.quiz3a.objectorientation.Spice;
19
     public void testGingerIsSpice() {
20
     public void testGingerIsSpice() {
20
         Assert.assertTrue(new Ginger() instanceof Spice);
21
         Assert.assertTrue(new Ginger() instanceof Spice);
21
     }
22
     }
23
+
24
+    @Test
25
+    public void testCurryIsSpice() {
26
+        Assert.assertTrue(new Curry() instanceof Spice);
27
+    }
22
 }
28
 }