Selaa lähdekoodia

tests up to friday completed

mpierse 6 vuotta sitten
vanhempi
commit
21b31b15c6

+ 7
- 3
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Freelan.java Näytä tiedosto

@@ -7,11 +7,15 @@ import com.zipcodewilmington.froilansfarm.PlantsAndCrops.Botanist;
7 7
 import com.zipcodewilmington.froilansfarm.PlantsAndCrops.CornStalk;
8 8
 import com.zipcodewilmington.froilansfarm.PlantsAndCrops.Crop;
9 9
 import com.zipcodewilmington.froilansfarm.PlantsAndCrops.TomatoPlant;
10
+import com.zipcodewilmington.froilansfarm.Vehicle.Flyer;
10 11
 
11
-public class Freelan extends Person implements Botanist {
12
+public class Freelan extends Person implements Botanist, Flyer {
12 13
 
13
-    public void plantNewRow(Crop type, int numToPlant){
14
-        Field field = new Field();
14
+
15
+    private Field field;
16
+
17
+    public void plantNewRow(Crop type, int numToPlant, Field field){
18
+        field = field;
15 19
         CropRow row = new CropRow(type, numToPlant);
16 20
         field.addToField(row);
17 21
     }

+ 4
- 2
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Froilan.java Näytä tiedosto

@@ -8,8 +8,10 @@ import com.zipcodewilmington.froilansfarm.PlantsAndCrops.Crop;
8 8
 
9 9
 public class Froilan extends Person implements Botanist {
10 10
 
11
-    public void plantNewRow(Crop type, int numToPlant){
12
-        Field field = new Field();
11
+    protected Field field;
12
+
13
+    public void plantNewRow(Crop type, int numToPlant, Field field){
14
+        field = field;
13 15
         CropRow row = new CropRow(type, numToPlant);
14 16
         field.addToField(row);
15 17
     }

+ 3
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Holders/Farm.java Näytä tiedosto

@@ -102,6 +102,9 @@ public class Farm  {
102 102
     public Tractor getTractor2() {
103 103
         return tractor2;
104 104
     }
105
+    public CornStalk getCornStalk(){
106
+        return cornStalk;
107
+    }
105 108
 
106 109
     public void populateFarm(){
107 110
         house.addToFarmHpuse(froilan);

+ 8
- 4
src/main/java/com/zipcodewilmington/froilansfarm/Holders/Field.java Näytä tiedosto

@@ -6,8 +6,8 @@ import java.util.Map;
6 6
 
7 7
 public class Field {
8 8
 
9
-    static private Map<Integer, CropRow> fieldMap;
10
-    private int rowNumber=1;
9
+    private Map<Integer, CropRow> fieldMap;
10
+    private int rowNumber=0;
11 11
     private static boolean isFertilized = false;
12 12
 
13 13
     public void setFertilized(boolean fertilized) {
@@ -25,10 +25,14 @@ public class Field {
25 25
     }
26 26
 
27 27
     public void addToField(CropRow cropRow){
28
-        fieldMap.put(getRowNumber(), cropRow);
28
+        fieldMap.put(setRowNumber(), cropRow);
29
+    }
30
+
31
+    public int setRowNumber() {
32
+        return ++rowNumber;
29 33
     }
30 34
 
31 35
     public int getRowNumber() {
32
-        return rowNumber++;
36
+        return rowNumber;
33 37
     }
34 38
 }

+ 2
- 1
src/main/java/com/zipcodewilmington/froilansfarm/PlantsAndCrops/Botanist.java Näytä tiedosto

@@ -1,10 +1,11 @@
1 1
 package com.zipcodewilmington.froilansfarm.PlantsAndCrops;
2 2
 
3 3
 import com.zipcodewilmington.froilansfarm.Holders.CropRow;
4
+import com.zipcodewilmington.froilansfarm.Holders.Field;
4 5
 
5 6
 public interface Botanist {
6 7
 
7
-    void plantNewRow(Crop type, int numToPlant);
8
+    void plantNewRow(Crop type, int numToPlant, Field field);
8 9
 
9 10
     void plant(CropRow row, int numberPlanted);
10 11
 

+ 39
- 0
src/test/java/com/zipcodewilmington/froilansfarm/FridayTest.java Näytä tiedosto

@@ -0,0 +1,39 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import com.zipcodewilmington.froilansfarm.Holders.Farm;
7
+
8
+public class FridayTest {
9
+
10
+    Farm farm;
11
+
12
+
13
+    @Before
14
+    public void setup() {
15
+        farm = new Farm();
16
+        farm.populateFarm();
17
+        farm.morningRoutine();
18
+        farm.getFroilanda().setIsMounted();
19
+        farm.getCropDuster().fertilize(farm.getFroilanda());
20
+        farm.getFreelan().plantNewRow(farm.getCornStalk(), 40, farm.getField());
21
+    }
22
+
23
+    //Freelan plants the 5th row of plants(corn) and fertilizes it
24
+
25
+    @Test
26
+    public void plantTest(){
27
+        farm.getFreelan().plantNewRow(farm.getCornStalk(), 40, farm.getField());
28
+        int actual = farm.getField().getRowNumber();
29
+        int expected = 5;
30
+        Assert.assertEquals(expected, actual);
31
+    }
32
+
33
+    @Test
34
+    public void fertilizeFieldTest() {
35
+        farm.getFreelan().setIsMounted();
36
+        farm.getCropDuster().fertilize(farm.getFreelan());
37
+        Assert.assertTrue(farm.getField().getIsFertilized());
38
+    }
39
+}

+ 34
- 0
src/test/java/com/zipcodewilmington/froilansfarm/ThursdayTest.java Näytä tiedosto

@@ -0,0 +1,34 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import com.zipcodewilmington.froilansfarm.Holders.Farm;
7
+
8
+public class ThursdayTest {
9
+
10
+    Farm farm;
11
+
12
+    @Before
13
+    public void setup(){
14
+        farm = new Farm();
15
+        farm.populateFarm();
16
+        farm.morningRoutine();
17
+    }
18
+
19
+    //On thursdays Freelan and Froilanda go for joy rides in the crop duster
20
+    @Test
21
+    public void freelanJoyRideTest() {
22
+        farm.getFreelan().setIsMounted();
23
+        String actual = farm.getCropDuster().ride(farm.getFreelan());
24
+        String expected = "We're flying!";
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+    @Test
28
+    public void froilandaJoyRideTest() {
29
+        farm.getFroilanda().setIsMounted();
30
+        String actual = farm.getCropDuster().ride(farm.getFroilanda());
31
+        String expected = "We're flying!";
32
+        Assert.assertEquals(expected, actual);
33
+    }
34
+}

+ 9
- 2
src/test/java/com/zipcodewilmington/froilansfarm/TuesdayTest.java Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 package com.zipcodewilmington.froilansfarm;
2 2
 
3
+
3 4
 import org.junit.Assert;
4 5
 import org.junit.Before;
5 6
 import org.junit.Test;
@@ -30,8 +31,6 @@ public class TuesdayTest {
30 31
         String actual = farm.getTractor1().ride(farm.getFroilan());
31 32
         String expected = "Driving in the field today";
32 33
         Assert.assertEquals(expected, actual);
33
-        farm.getFroilanda().setIsMounted();
34
-        farm.getCropDuster().fertilize(farm.getFroilanda());
35 34
     }
36 35
 
37 36
     @Test
@@ -68,4 +67,12 @@ public class TuesdayTest {
68 67
         int expected =40;
69 68
         Assert.assertEquals(expected, actual);
70 69
     }
70
+
71
+    @Test
72
+    public void plantTest(){
73
+        farm.getFreelan().plantNewRow(farm.getCornStalk(), 40, farm.getField());
74
+        int actual = farm.getField().getRowNumber();
75
+        int expected = 4;
76
+        Assert.assertEquals(expected, actual);
77
+    }
71 78
 }