refactor: first attempt at dependency injection

also some more renaming and improving date-picker dialog
This commit is contained in:
David Guler
2022-11-14 20:00:01 +01:00
parent 4f80a0a3e0
commit 15279838b7
14 changed files with 378 additions and 333 deletions
@@ -1,9 +1,6 @@
package ch.zhaw.gartenverwaltung.models;
import ch.zhaw.gartenverwaltung.io.*;
import ch.zhaw.gartenverwaltung.models.Garden;
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
import ch.zhaw.gartenverwaltung.types.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -13,6 +10,7 @@ import java.time.LocalDate;
import java.time.MonthDay;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -70,7 +68,7 @@ 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,01));
exampleCrop3 = new Crop(0,LocalDate.of(2023,3,1));
exampleCrop3.withId(2);
exampleCrop3.withArea(1.0);
@@ -81,7 +79,7 @@ public class GardenPlanModelTest {
cropList = mockGardenPlan(exampleCrops);
GardenSchedule gardenSchedule = new GardenSchedule(new JsonTaskList(), new JsonPlantList());
model = new Garden(gardenSchedule);
model = new Garden(gardenSchedule, cropList);
}
CropList mockGardenPlan(List<Crop> cropList) throws IOException {
@@ -96,15 +94,16 @@ public class GardenPlanModelTest {
void plantAsCrop() throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
model.plantAsCrop(examplePlantOnion, LocalDate.of(2023,3,1));
exampleCropOnion = model.getCrop(2L).get();
assertEquals(model.getCrops().get(2),exampleCropOnion);
Optional<Crop> exampleCrop = model.getCrop(2L);
assertTrue(exampleCrop.isPresent());
assertEquals(model.getCrops().get(2), exampleCrop.get());
}
@Test
void removeCrop() throws IOException {
exampleCrop1.withId(2);
exampleCrop1.withArea(1.500000);
exampleCrop1.withArea(1.5);
model.removeCrop(exampleCrop1);
assertEquals(2,model.getCrops().size());
}