Leon Hunter 5 lat temu
rodzic
commit
71d2b9c90d

+ 1
- 13
src/main/java/rocks/zipcode/quiz3a/collections/Food.java Wyświetl plik

@@ -1,6 +1,5 @@
1 1
 package rocks.zipcode.quiz3a.collections;
2 2
 
3
-import rocks.zipcode.quiz3a.objectorientation.Condiment;
4 3
 import rocks.zipcode.quiz3a.objectorientation.Spice;
5 4
 
6 5
 import java.util.List;
@@ -14,21 +13,10 @@ public class Food {
14 13
         return null;
15 14
     }
16 15
 
17
-    public List<Condiment> getAllCondiments() {
18
-        return null;
19
-    }
20
-
21
-    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount(SpiceType spiceType) {
22
-        return null;
23
-    }
24
-
25
-    public Map<Condiment, Integer> getCondimentCount() {
16
+    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
26 17
         return null;
27 18
     }
28 19
 
29 20
     public void applySpice(Spice spice) {
30 21
     }
31
-
32
-    public void applyCondiment(Condiment condiment) {
33
-    }
34 22
 }

+ 0
- 7
src/main/java/rocks/zipcode/quiz3a/objectorientation/Condiment.java Wyświetl plik

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

+ 4
- 0
src/main/java/rocks/zipcode/quiz3a/objectorientation/Curry.java Wyświetl plik

@@ -0,0 +1,4 @@
1
+package rocks.zipcode.quiz3a.objectorientation;
2
+
3
+public class Curry {
4
+}

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/objectorientation/Spice.java Wyświetl plik

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz3a.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Spice {
6
+public interface Spice {
7 7
 }

+ 0
- 6
src/main/java/rocks/zipcode/quiz3a/objectorientation/enums/Person.java Wyświetl plik

@@ -1,6 +0,0 @@
1
-package rocks.zipcode.quiz3a.objectorientation.enums;
2
-
3
-public enum Person {
4
-    private String firstName;
5
-    private String lastName;
6
-}

+ 34
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetAllSpicesTest.java Wyświetl plik

@@ -0,0 +1,34 @@
1
+package rocks.zipcode.quiz3a.objectorientation.food;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.collections.Food;
6
+import rocks.zipcode.quiz3a.objectorientation.Curry;
7
+import rocks.zipcode.quiz3a.objectorientation.Ginger;
8
+import rocks.zipcode.quiz3a.objectorientation.Pepper;
9
+import rocks.zipcode.quiz3a.objectorientation.Spice;
10
+
11
+import java.util.Arrays;
12
+import java.util.List;
13
+
14
+public class GetAllSpicesTest {
15
+    @Test
16
+    public void test1() {
17
+        // given
18
+        Food food = new Food();
19
+        List<Spice> expected = Arrays.asList(
20
+                (Spice) new Pepper(),
21
+                (Spice) new Ginger(),
22
+                (Spice) new Curry());
23
+
24
+        for (Spice spice : expected) {
25
+            food.applySpice(spice);
26
+        }
27
+
28
+        // when
29
+        List<Spice> actual = food.getAllSpices();
30
+
31
+        // then
32
+        Assert.assertEquals(expected, actual);
33
+    }
34
+}

+ 30
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetSpiceCountTest.java Wyświetl plik

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

+ 2
- 2
src/test/java/rocks/zipcode/quiz3a/objectorientation/spice/SpicePolymorphismTest.java Wyświetl plik

@@ -12,11 +12,11 @@ import rocks.zipcode.quiz3a.objectorientation.Spice;
12 12
 public class SpicePolymorphismTest {
13 13
     @Test
14 14
     public void testPepperIsSpice() {
15
-        Assert.assertTrue((Object) new Pepper() instanceof Spice);
15
+        Assert.assertTrue(new Pepper() instanceof Spice);
16 16
     }
17 17
 
18 18
     @Test
19 19
     public void testGingerIsSpice() {
20
-        Assert.assertTrue((Object) new Ginger() instanceof Spice);
20
+        Assert.assertTrue(new Ginger() instanceof Spice);
21 21
     }
22 22
 }