refactor: Made Task::id nullable/Optional for semantic reasons
better use of builder semantics in task and crop creation
This commit is contained in:
@@ -72,7 +72,8 @@ public class JsonTaskListTest {
|
||||
@Test
|
||||
@DisplayName("Remove task.")
|
||||
void removeTask() {
|
||||
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1).withId(2);
|
||||
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1)
|
||||
.withId(2);
|
||||
try {
|
||||
testDatabase.removeTask(task);
|
||||
List<Task> taskList;
|
||||
|
||||
@@ -55,8 +55,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.of(2023,3,1));
|
||||
exampleCropOnion.withId(3);
|
||||
exampleCropOnion = new Crop(examplePlantOnion.id(), LocalDate.of(2023, 3, 1))
|
||||
.withId(3);
|
||||
examplePlantCarrot = new Plant(
|
||||
1,
|
||||
"Early Carrot",
|
||||
@@ -67,18 +67,18 @@ public class GardenPlanModelTest {
|
||||
"sandy to loamy, loose soil, free of stones",
|
||||
new ArrayList<>(),
|
||||
List.of(new GrowthPhase(MonthDay.of(4, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, new ArrayList<>())));
|
||||
exampleCropCarrot = new Crop(examplePlantCarrot.id(), LocalDate.now());
|
||||
exampleCropCarrot.withId(5);
|
||||
exampleCropCarrot = new Crop(examplePlantCarrot.id(), LocalDate.now())
|
||||
.withId(5);
|
||||
|
||||
exampleCrop1 = new Crop(1, LocalDate.of(2023,2,25));
|
||||
exampleCrop1.withId(0);
|
||||
exampleCrop1.withArea(0.5);
|
||||
exampleCrop2 = new Crop(1,LocalDate.of(2023,3,1));
|
||||
exampleCrop2.withId(1);
|
||||
exampleCrop2.withArea(0.5);
|
||||
exampleCrop3 = new Crop(0,LocalDate.of(2023,3,1));
|
||||
exampleCrop3.withId(2);
|
||||
exampleCrop3.withArea(1.0);
|
||||
exampleCrop1 = new Crop(1, LocalDate.of(2023, 2, 25))
|
||||
.withId(0)
|
||||
.withArea(0.5);
|
||||
exampleCrop2 = new Crop(1, LocalDate.of(2023, 3, 1))
|
||||
.withId(1)
|
||||
.withArea(0.5);
|
||||
exampleCrop3 = new Crop(0, LocalDate.of(2023, 3, 1))
|
||||
.withId(2)
|
||||
.withArea(1.0);
|
||||
|
||||
exampleCrops = new ArrayList<>();
|
||||
exampleCrops.add(exampleCrop1);
|
||||
@@ -107,7 +107,7 @@ public class GardenPlanModelTest {
|
||||
@Test
|
||||
void plantAsCrop() throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
||||
|
||||
model.plantAsCrop(examplePlantOnion, LocalDate.of(2023,3,1));
|
||||
model.plantAsCrop(examplePlantOnion, LocalDate.of(2023, 3, 1));
|
||||
Optional<Crop> exampleCrop = model.getCrop(2L);
|
||||
assertTrue(exampleCrop.isPresent());
|
||||
assertEquals(model.getCrops().get(2), exampleCrop.get());
|
||||
@@ -119,6 +119,6 @@ public class GardenPlanModelTest {
|
||||
exampleCrop1.withId(2);
|
||||
exampleCrop1.withArea(1.5);
|
||||
model.removeCrop(exampleCrop1);
|
||||
assertEquals(2,model.getCrops().size());
|
||||
assertEquals(2, model.getCrops().size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user