Leon hace 5 años
padre
commit
df58c61da5
Se han modificado 21 ficheros con 432 adiciones y 41 borrados
  1. 12
    0
      pom.xml
  2. 7
    0
      src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java
  3. 1
    1
      src/main/java/rocks/zipcode/quiz3a/collections/Bank.java
  4. 1
    1
      src/main/java/rocks/zipcode/quiz3a/collections/Food.java
  5. 4
    3
      src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java
  6. 0
    35
      src/main/java/rocks/zipcode/quiz3a/objectorientation/BankAccount.java
  7. 13
    0
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Account.java
  8. 18
    0
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java
  9. 24
    0
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java
  10. 10
    0
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Transactable.java
  11. 11
    0
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Worker.java
  12. 14
    1
      src/test/java/rocks/zipcode/quiz3a/collections/food/GetSpiceCountTest.java
  13. 20
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/account/AccountPolymorphismTest.java
  14. 23
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/BankAccountPolymorphismTest.java
  15. 7
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DecreaseBalanceTest.java
  16. 7
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/IncreaseBalanceTest.java
  17. 59
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java
  18. 59
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java
  19. 31
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeePolymorphismTest.java
  20. 57
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/IncreaseHoursWorkedTest.java
  21. 54
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/SetBankAccountTest.java

+ 12
- 0
pom.xml Ver fichero

@@ -7,6 +7,18 @@
7 7
     <groupId>rocks.zipcode</groupId>
8 8
     <artifactId>quiz3a</artifactId>
9 9
     <version>1.0</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
     <dependencies>
11 23
         <dependency>
12 24
             <groupId>junit</groupId>

+ 7
- 0
src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java Ver fichero

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

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/collections/Bank.java Ver fichero

@@ -1,6 +1,6 @@
1 1
 package rocks.zipcode.quiz3a.collections;
2 2
 
3
-import rocks.zipcode.quiz3a.objectorientation.BankAccount;
3
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
4 4
 
5 5
 import java.util.List;
6 6
 

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/collections/Food.java Ver fichero

@@ -18,7 +18,7 @@ public class Food {
18 18
         return null;
19 19
     }
20 20
 
21
-    public Map<Spice, Integer> getSpiceCount() {
21
+    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount(SpiceType spiceType) {
22 22
         return null;
23 23
     }
24 24
 

+ 4
- 3
src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java Ver fichero

@@ -5,9 +5,6 @@ package rocks.zipcode.quiz3a.fundamentals;
5 5
  */
6 6
 public class StringUtils {
7 7
     public static Character getMiddleCharacter(String string) {
8
-        // 0. figure out how long
9
-        // 1. divide length by 2
10
-        // 2.
11 8
         return null;
12 9
     }
13 10
 
@@ -18,4 +15,8 @@ public class StringUtils {
18 15
     public static String lowerCaseMiddleCharacter(String str) {
19 16
         return null;
20 17
     }
18
+
19
+    public static Boolean isIsogram(String str) {
20
+        return null;
21
+    }
21 22
 }

+ 0
- 35
src/main/java/rocks/zipcode/quiz3a/objectorientation/BankAccount.java Ver fichero

@@ -1,35 +0,0 @@
1
-package rocks.zipcode.quiz3a.objectorientation;
2
-
3
-/**
4
- * @author leon on 27/12/2018.
5
- */
6
-public class BankAccount {
7
-    public void increaseBalance(Double amountToIncreaseBy) {
8
-
9
-    }
10
-
11
-    public void decreaseBalance(Double amountToIncreaseBy) {
12
-
13
-    }
14
-
15
-    public Long getId() {
16
-        return null;
17
-    }
18
-
19
-    public void setId(Long id) {
20
-    }
21
-
22
-    public Double getBalance() {
23
-        return null;
24
-    }
25
-
26
-    public void setBalance(Double balance) {
27
-    }
28
-
29
-    public String getAccountHolderName() {
30
-        return null;
31
-    }
32
-
33
-    public void setAccountHolderName(String accountHolderName) {
34
-    }
35
-}

+ 13
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Account.java Ver fichero

@@ -0,0 +1,13 @@
1
+package rocks.zipcode.quiz3a.objectorientation.account;
2
+
3
+/**
4
+ * @author leon on 30/12/2018.
5
+ */
6
+public class Account extends BankAccount {
7
+    public Long getId() {
8
+        return null;
9
+    }
10
+
11
+    public void setId(Long id) {
12
+    }
13
+}

+ 18
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java Ver fichero

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

+ 24
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java Ver fichero

@@ -0,0 +1,24 @@
1
+package rocks.zipcode.quiz3a.objectorientation.account;
2
+
3
+/**
4
+ * @author leon on 30/12/2018.
5
+ */
6
+public class Employee {
7
+    public Employee() {
8
+    }
9
+
10
+    public Employee(BankAccount bankAccount) {
11
+    }
12
+
13
+    public BankAccount getBankAccount() {
14
+        return null;
15
+    }
16
+
17
+    public void setBankAccount(BankAccount bankAccount) {
18
+
19
+    }
20
+
21
+    public String getName() {
22
+        return null;
23
+    }
24
+}

+ 10
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Transactable.java Ver fichero

@@ -0,0 +1,10 @@
1
+package rocks.zipcode.quiz3a.objectorientation.account;
2
+
3
+/**
4
+ * @author leon on 30/12/2018.
5
+ */
6
+public interface Transactable {
7
+    void deposit(Double amountToIncreaseBy);
8
+    void withdrawal(Double amountToDecreaseBy);
9
+    Double getBalance();
10
+}

+ 11
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Worker.java Ver fichero

@@ -0,0 +1,11 @@
1
+package rocks.zipcode.quiz3a.objectorientation.account;
2
+
3
+/**
4
+ * @author leon on 30/12/2018.
5
+ */
6
+public interface Worker {
7
+    void increaseHoursWorked(Double numberOfHours);
8
+    Double getHoursWorked();
9
+    Double getHourlyWage();
10
+    Double getMoneyEarned();
11
+}

+ 14
- 1
src/test/java/rocks/zipcode/quiz3a/collections/food/GetSpiceCountTest.java Ver fichero

@@ -1,9 +1,14 @@
1 1
 package rocks.zipcode.quiz3a.collections.food;
2 2
 
3
+import org.junit.Assert;
3 4
 import org.junit.Test;
4 5
 import rocks.zipcode.quiz3a.collections.Food;
6
+import rocks.zipcode.quiz3a.objectorientation.Ginger;
7
+import rocks.zipcode.quiz3a.objectorientation.Pepper;
5 8
 import rocks.zipcode.quiz3a.objectorientation.Spice;
6 9
 
10
+import java.util.Map;
11
+
7 12
 /**
8 13
  * @author leon on 27/12/2018.
9 14
  */
@@ -12,8 +17,16 @@ public class GetSpiceCountTest {
12 17
     public void test1() {
13 18
         // given
14 19
         Food food = new Food();
15
-        food.applySpice(new Spice());
20
+        food.applySpice((Spice)(Object)new Pepper());
21
+        food.applySpice((Spice)(Object)new Pepper());
22
+        food.applySpice((Spice)(Object)new Ginger());
23
+        food.applySpice((Spice)(Object)new Ginger());
24
+
16 25
         // when
26
+        Map<? extends Class<? extends Spice>, Integer> spiceCount = food.getSpiceCount((Class<? extends Spice>)(Object)Pepper.class);
27
+        spiceCount.get(null);
28
+
17 29
         // then
30
+//        Assert.assertEquals();
18 31
     }
19 32
 }

+ 20
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/account/AccountPolymorphismTest.java Ver fichero

@@ -0,0 +1,20 @@
1
+package rocks.zipcode.quiz3a.objectorientation.account;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * @author leon on 30/12/2018.
8
+ */
9
+public class AccountPolymorphismTest {
10
+    private Account account = new Account();
11
+    @Test
12
+    public void test1() {
13
+        Assert.assertFalse(account instanceof Transactable);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        Assert.assertFalse(account instanceof BankAccount);
19
+    }
20
+}

+ 23
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/BankAccountPolymorphismTest.java Ver fichero

@@ -0,0 +1,23 @@
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.Account;
6
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
7
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
8
+
9
+/**
10
+ * @author leon on 30/12/2018.
11
+ */
12
+public class BankAccountPolymorphismTest {
13
+    BankAccount bankAccount = new BankAccount();
14
+    @Test
15
+    public void test1() {
16
+        Assert.assertTrue(bankAccount instanceof Transactable);
17
+    }
18
+
19
+    @Test
20
+    public void test2() {
21
+        Assert.assertTrue(bankAccount instanceof Account);
22
+    }
23
+}

+ 7
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DecreaseBalanceTest.java Ver fichero

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

+ 7
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/IncreaseBalanceTest.java Ver fichero

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

+ 59
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java Ver fichero

@@ -0,0 +1,59 @@
1
+package rocks.zipcode.quiz3a.objectorientation.employee;
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.Employee;
7
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
8
+import rocks.zipcode.quiz3a.objectorientation.account.Worker;
9
+
10
+/**
11
+ * @author leon on 30/12/2018.
12
+ */
13
+public class EmployeeConstructorTest {
14
+    @Test
15
+    public void testNullaryConstructor() {
16
+        // given
17
+        Employee employee = new Employee();
18
+        Worker worker = (Worker) employee;
19
+        Transactable transactable = (Transactable) employee;
20
+
21
+        Double expectedHourlyWage = 35.0;
22
+        Double expectedHoursWorked = 0.0;
23
+        Double expectedBalance = 0.0;
24
+        Double expectedBankAccountBalance = 0.0;
25
+        Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
26
+
27
+        Assert.assertNotNull(employee.getBankAccount());
28
+        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
29
+        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
30
+        Assert.assertEquals(expectedBalance, transactable.getBalance());
31
+        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
32
+    }
33
+
34
+    @Test
35
+    public void testNonNullaryConstructor() {
36
+        // given
37
+        Double expectedHourlyWage = 35.0;
38
+        Double expectedHoursWorked = 0.0;
39
+        Double expectedBalance = 15.0;
40
+        Double expectedBankAccountBalance = expectedBalance;
41
+        Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
42
+        BankAccount bankAccount = new BankAccount();
43
+        bankAccount.increaseBalance(expectedBankAccountBalance);
44
+
45
+        // when
46
+        Employee employee = new Employee(bankAccount);
47
+        Worker worker = (Worker) employee;
48
+        Transactable transactable = (Transactable) employee;
49
+
50
+
51
+        Assert.assertNotNull(employee.getBankAccount());
52
+        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
53
+        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
54
+        Assert.assertEquals(expectedBalance, transactable.getBalance());
55
+        Assert.assertEquals(expectedMoneyEarned, expectedMoneyEarned);
56
+        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
57
+    }
58
+
59
+}

+ 59
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java Ver fichero

@@ -0,0 +1,59 @@
1
+package rocks.zipcode.quiz3a.objectorientation.employee;
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.Employee;
7
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
8
+
9
+/**
10
+ * @author leon on 30/12/2018.
11
+ */
12
+public class EmployeeDepositTest {
13
+    @Test
14
+    public void test1() {
15
+        test(0.0, 10.0);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        test(0.0, 20.0);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        test(10.0, 100.0);
26
+    }
27
+
28
+    @Test
29
+    public void test4() {
30
+        test(20.0, 300.0);
31
+    }
32
+
33
+    @Test
34
+    public void test5() {
35
+        test(0.0, 400.0);
36
+    }
37
+
38
+
39
+    private void test(Double preDepositBalance, Double amountToDeposit) {
40
+        // given
41
+        Employee employee = new Employee();
42
+        BankAccount bankAccount = employee.getBankAccount();
43
+        Transactable employeeAsTransactable = (Transactable) employee;
44
+
45
+        employeeAsTransactable.deposit(preDepositBalance);
46
+        Double expectedEmployeeBalance = preDepositBalance + amountToDeposit;
47
+
48
+
49
+        // when
50
+        employeeAsTransactable.deposit(amountToDeposit);
51
+        Double actualEmployeeBalance = employeeAsTransactable.getBalance();
52
+        Double actualBankAccountBalance = bankAccount.getBalance();
53
+
54
+
55
+        // then
56
+        Assert.assertEquals(expectedEmployeeBalance, actualEmployeeBalance);
57
+        Assert.assertEquals(expectedEmployeeBalance, actualBankAccountBalance);
58
+    }
59
+}

+ 31
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeePolymorphismTest.java Ver fichero

@@ -0,0 +1,31 @@
1
+package rocks.zipcode.quiz3a.objectorientation.employee;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.Account;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Employee;
7
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
8
+import rocks.zipcode.quiz3a.objectorientation.account.Worker;
9
+
10
+/**
11
+ * @author leon on 30/12/2018.
12
+ */
13
+public class EmployeePolymorphismTest {
14
+    private Employee employee = new Employee();
15
+
16
+    @Test
17
+    public void test1() {
18
+        Assert.assertTrue(employee instanceof Transactable);
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        Assert.assertTrue(employee instanceof Worker);
24
+    }
25
+
26
+
27
+    @Test
28
+    public void test3() {
29
+        Assert.assertFalse((Account) (Object) employee instanceof Account);
30
+    }
31
+}

+ 57
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/IncreaseHoursWorkedTest.java Ver fichero

@@ -0,0 +1,57 @@
1
+package rocks.zipcode.quiz3a.objectorientation.employee;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.Employee;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Worker;
7
+
8
+/**
9
+ * @author leon on 30/12/2018.
10
+ */
11
+public class IncreaseHoursWorkedTest {
12
+
13
+    @Test
14
+    public void test1() {
15
+        // given
16
+        test(0.0, 1.0);
17
+    }
18
+
19
+    @Test
20
+    public void test2() {
21
+        // given
22
+        test(0.0, 5.0);
23
+    }
24
+
25
+
26
+    @Test
27
+    public void test4() {
28
+        // given
29
+        test(1.0, 10.0);
30
+    }
31
+
32
+
33
+    @Test
34
+    public void test5() {
35
+        // given
36
+        test(2.0, 2.0);
37
+    }
38
+
39
+
40
+    private void test(Double numberOfHoursWorkedSoFar, Double numberOfHoursToWork) {
41
+        // given
42
+        Employee employee = new Employee();
43
+        Worker employeeAsWorker = (Worker) employee;
44
+
45
+        employeeAsWorker.increaseHoursWorked(numberOfHoursWorkedSoFar);
46
+        Double expected = numberOfHoursWorkedSoFar + numberOfHoursToWork;
47
+
48
+
49
+        // when
50
+        employeeAsWorker.increaseHoursWorked(numberOfHoursToWork);
51
+        Double actual = employeeAsWorker.getHoursWorked();
52
+
53
+
54
+        // then
55
+        Assert.assertEquals(expected, actual);
56
+    }
57
+}

+ 54
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/SetBankAccountTest.java Ver fichero

@@ -0,0 +1,54 @@
1
+package rocks.zipcode.quiz3a.objectorientation.employee;
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.Employee;
7
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
8
+
9
+/**
10
+ * @author leon on 30/12/2018.
11
+ */
12
+public class SetBankAccountTest {
13
+    @Test
14
+    public void test1() {
15
+        // given
16
+        Employee employee = new Employee();
17
+        BankAccount expected = new BankAccount();
18
+
19
+        // when
20
+        employee.setBankAccount(expected);
21
+        BankAccount actual = employee.getBankAccount();
22
+
23
+        // then
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void test2() {
29
+        test(10.0);
30
+    }
31
+
32
+
33
+    @Test
34
+    public void test3() {
35
+        test(15.0);
36
+    }
37
+
38
+
39
+    public void test(Double expectedBalance) {
40
+        // given
41
+        Employee employee = new Employee();
42
+        BankAccount expected = new BankAccount();
43
+        ((Transactable)expected).setBalance(expectedBalance);
44
+
45
+        // when
46
+        employee.setBankAccount(expected);
47
+        BankAccount actual = employee.getBankAccount();
48
+        Double actualBalance = ((Transactable)employee).getBalance();
49
+
50
+        // then
51
+        Assert.assertEquals(expected, actual);
52
+        Assert.assertEquals(expectedBalance, actualBalance);
53
+    }
54
+}