#27 gardenplanmodelTest bugfixed

This commit is contained in:
Gian-Andrea Hutter
2022-11-04 15:35:45 +01:00
parent 2361afd537
commit e91773b360
6 changed files with 594 additions and 65 deletions
@@ -6,15 +6,15 @@ import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.internal.stubbing.answers.DoesNothing;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.time.LocalDate;
import java.time.MonthDay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -34,6 +34,8 @@ public class GardenPlanModelTest {
@BeforeEach
void setUp() throws IOException {
examplePlantOnion = new Plant(
0,
"summertime onion",
@@ -49,8 +51,8 @@ public class GardenPlanModelTest {
new GrowthPhase(MonthDay.of(2, 8), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>()),
new GrowthPhase(MonthDay.of(10, 2), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.now());
exampleCropOnion.withId(13);
exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.of(2023,3,1));
exampleCropOnion.withId(3);
examplePlantCarrot = new Plant(
1,
"Early Carrot",
@@ -70,9 +72,9 @@ public class GardenPlanModelTest {
exampleCrop2 = new Crop(1,LocalDate.of(2023,3,1));
exampleCrop2.withId(1);
exampleCrop2.withArea(0.5);
exampleCrop3 = new Crop(0,LocalDate.of(2023,3,25));
exampleCrop3 = new Crop(0,LocalDate.of(2023,3,01));
exampleCrop3.withId(2);
exampleCrop3.withArea(1.5);
exampleCrop3.withArea(1.0);
cropList = new ArrayList<>();
cropList.add(exampleCrop1);
@@ -82,13 +84,18 @@ public class GardenPlanModelTest {
TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase());
model = new Gardenplanmodel(taskListModel);
// final URL dataSource = getClass().getClassLoader().getResource("taskdb.json");
// File src = new File(String.valueOf(getClass().getResource("originalDB/taskdb.json")));
// File dest = new File(String.valueOf(getClass().getClassLoader().getResource("originalDB/taskdb.json")));
// Files.copy(src.toPath(), dest.getParentFile().toPath());
}
GardenPlan mockGardenPlan(List<Crop> cropList) throws IOException {
GardenPlan gardenPlan = mock(GardenPlan.class);
when(gardenPlan.getCrops()).thenReturn(cropList);
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
when(gardenPlan.getCropById(13)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
return gardenPlan;
}
@@ -96,7 +103,9 @@ public class GardenPlanModelTest {
void plantAsCrop() throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
model.plantAsCrop(examplePlantOnion, LocalDate.of(2023,3,1));
assertTrue(model.getCrops().contains(exampleCropOnion));
exampleCropOnion = model.getCrop(2L).get();
assertEquals(model.getCrops().get(2),exampleCropOnion);
}
@Test