From 384dc2d85313df09d4c470b2a272d8ab2d91a891 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 18 Nov 2022 11:34:53 +0100 Subject: [PATCH 1/6] completed Tests for GardenScheduleTest --- .../GardenScheduleTest.java | 86 +++++++++++++------ 1 file changed, 62 insertions(+), 24 deletions(-) rename src/test/java/ch/zhaw/gartenverwaltung/{taskList => models}/GardenScheduleTest.java (57%) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/taskList/GardenScheduleTest.java b/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java similarity index 57% rename from src/test/java/ch/zhaw/gartenverwaltung/taskList/GardenScheduleTest.java rename to src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java index cf354de..0cadffb 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/taskList/GardenScheduleTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java @@ -1,35 +1,45 @@ -package ch.zhaw.gartenverwaltung.taskList; +package ch.zhaw.gartenverwaltung.models; import ch.zhaw.gartenverwaltung.io.*; import ch.zhaw.gartenverwaltung.models.GardenSchedule; -import ch.zhaw.gartenverwaltung.types.HardinessZone; -import ch.zhaw.gartenverwaltung.types.Plant; -import ch.zhaw.gartenverwaltung.types.Task; +import ch.zhaw.gartenverwaltung.types.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import java.time.LocalDate; +import java.time.MonthDay; import java.util.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; class GardenScheduleTest { + LocalDate exampleStartDate = LocalDate.of(2020, 02, 02); TaskList taskList; PlantList plantList; + List examplePlantList; List exampleTaskList; - Map examplePlantMap; + List exampleTaskTemplateList; GardenSchedule model; @BeforeEach - void setUp() throws IOException { + void setUp() throws IOException, HardinessZoneNotSetException { createExampleTaskList(); + createExampleTaskTemplateList(); + createExamplePlantList(); taskList = mockTaskDatabase(exampleTaskList); - plantList = mockPlantDatabase(examplePlantMap); + plantList = mockPlantDatabase(examplePlantList); model = new GardenSchedule(taskList, plantList); } + PlantList mockPlantDatabase(List plantList) throws HardinessZoneNotSetException, IOException { + PlantList plantDatabase = mock(JsonPlantList.class); + when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList); + when(plantDatabase.getPlantById(HardinessZone.ZONE_8A,20)).thenReturn(Optional.of(examplePlantList.get(0))); + return plantDatabase; + } + private TaskList mockTaskDatabase(List exampleTaskList) throws IOException { TaskList taskList = mock(JsonTaskList.class); when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList); @@ -54,18 +64,39 @@ class GardenScheduleTest { return taskList; } - private PlantList mockPlantDatabase(Map examplePlantMap) { - return new PlantList() { - @Override - public List getPlantList(HardinessZone zone) { - return null; - } + void createExampleTaskTemplateList(){ + exampleTaskTemplateList = new ArrayList<>(); + exampleTaskTemplateList.add(mock(TaskTemplate.class)); + exampleTaskTemplateList.add(mock(TaskTemplate.class)); + exampleTaskTemplateList.add(mock(TaskTemplate.class)); + exampleTaskTemplateList.add(mock(TaskTemplate.class)); + when(exampleTaskTemplateList.get(0).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(0)); + when(exampleTaskTemplateList.get(1).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(1)); + when(exampleTaskTemplateList.get(2).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(2)); + when(exampleTaskTemplateList.get(3).generateTask(exampleStartDate, 30)).thenReturn(exampleTaskList.get(3)); + } - @Override - public Optional getPlantById(HardinessZone zone, long id) { - return Optional.ofNullable(examplePlantMap.get(id)); - } - }; + void createExamplePlantList(){ + examplePlantList = new ArrayList<>(); + examplePlantList.add(new Plant( + 20, + "summertime onion", + "Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.", + null, + "15,30,2", + 0, + "sandy to loamy, loose soil, free of stones", + new ArrayList<>(), + List.of( + new GrowthPhase(MonthDay.of(6, 4), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.HARVEST, HardinessZone.ZONE_8A, List.of( + exampleTaskTemplateList.get(0), + exampleTaskTemplateList.get(1) + )), + new GrowthPhase(MonthDay.of(4, 3), MonthDay.of(12, 4), 0, new WateringCycle(0, 0, null), GrowthPhaseType.PLANT, HardinessZone.ZONE_8A, List.of( + exampleTaskTemplateList.get(2), + exampleTaskTemplateList.get(3) + )) + ))); } void createExampleTaskList() { @@ -77,12 +108,6 @@ class GardenScheduleTest { exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L)); } - void createExamplePlantMap() { - examplePlantMap = new HashMap<>(); - } - - - @Test void addTask() throws IOException { Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L); @@ -156,4 +181,17 @@ class GardenScheduleTest { model.removeTasksForCrop(1L); verify(taskList, times(1)).removeTasksForCrop(1L); } + + @Test + void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException { + model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30)); + verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30); + verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30); + verify(exampleTaskTemplateList.get(2), times(1)).generateTask(exampleStartDate, 30); + verify(exampleTaskTemplateList.get(3), times(1)).generateTask(exampleStartDate, 30); + verify(taskList, times(1)).saveTask(exampleTaskList.get(0)); + verify(taskList, times(1)).saveTask(exampleTaskList.get(1)); + verify(taskList, times(1)).saveTask(exampleTaskList.get(2)); + verify(taskList, times(1)).saveTask(exampleTaskList.get(3)); + } } \ No newline at end of file From 165dc6d9015147e38949c0e94af2090849120247 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 18 Nov 2022 12:21:21 +0100 Subject: [PATCH 2/6] implemented Method getGrowphaseGroupForDate --- .../zhaw/gartenverwaltung/models/GardenSchedule.java | 3 ++- .../java/ch/zhaw/gartenverwaltung/types/Plant.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index 9195d51..a362f00 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -46,7 +46,8 @@ public class GardenSchedule { */ public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException { Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new); - for (GrowthPhase growthPhase : plant.lifecycle()) { + int growPhaseGroup = plant.getGrowphaseGroupForDate(crop.getStartDate()); + for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) { for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) { addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L))); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java index 9cb3d08..5fb6dff 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java @@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.types; import javafx.scene.image.Image; import java.time.LocalDate; +import java.time.MonthDay; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -39,6 +40,16 @@ public record Plant( .collect(Collectors.toList()); } + public int getGrowphaseGroupForDate(LocalDate date) { + for(GrowthPhase growthPhase : lifecycle){ + MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth()); + if(plantingDate.isAfter(growthPhase.startDate()) && plantingDate.isBefore(growthPhase.endDate())){ + return growthPhase.group(); + } + } + return 0; // TODO implement + } + /** * get sow date from given harvest day from lifecycle group * @param harvestDate date of the harvest From 775e35a70b0ea5719b4ba1d1ea916dcfde584a9b Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 24 Nov 2022 22:18:08 +0100 Subject: [PATCH 3/6] new Structure of Task --- .../ch/zhaw/gartenverwaltung/types/Task.java | 27 +++++++++++++++++++ .../gartenverwaltung/types/TaskTemplate.java | 4 --- .../ch/zhaw/gartenverwaltung/io/plantdb.json | 27 +++++++------------ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index df15fc4..dab4d39 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -15,6 +15,8 @@ public class Task { private final LocalDate startDate; private Integer interval; private LocalDate endDate; + private LocalDate nextExecution; + private LocalDate nextNotification; private long cropId; /** @@ -25,12 +27,14 @@ public class Task { name= ""; description= ""; startDate = LocalDate.now(); + nextExecution = startDate; } public Task(String name, String description, LocalDate startDate, long cropId) { this.name = name; this.description = description; this.startDate = startDate; + nextExecution = startDate; this.cropId = cropId; } @@ -38,6 +42,7 @@ public class Task { this.name = name; this.description = description; this.startDate = startDate; + nextExecution = startDate; this.endDate = endDate; this.interval = interval; this.cropId = cropId; @@ -61,7 +66,29 @@ public class Task { return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); } + public void done(){ + if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){ + nextExecution = nextExecution.plusDays(interval); + } else { + nextExecution = null; + } + } + + public boolean isDone(){ + return nextExecution == null; + } + + public void setNextExecution(LocalDate nextExecution) { + this.nextExecution = nextExecution; + } + + public void setNextNotification(LocalDate nextNotification) { + this.nextNotification = nextNotification; + } + // Getters + public LocalDate getNextNotification() { return nextNotification; } + public LocalDate getNextExecution() { return nextExecution; } public Optional getId() { return Optional.ofNullable(id); } public String getName() { return name; } public String getDescription() { return description; } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java index 2e471cb..d094665 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java @@ -16,10 +16,6 @@ public class TaskTemplate { @JsonProperty private Integer interval; - // TODO: reconsider if we need this - @JsonProperty - private boolean isOptional = false; - /** * Default constructor * (Used by deserializer) diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json index 8cacaeb..fac9a5b 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json @@ -32,8 +32,7 @@ "relativeStartDate": -14, "relativeEndDate": null, "description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -54,8 +53,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.", - "interval": 21, - "isOptional": false + "interval": 21 } ] }, @@ -76,8 +74,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -106,8 +103,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -130,8 +126,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -152,8 +147,7 @@ "relativeStartDate": 0, "relativeEndDate": 14, "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -192,8 +186,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Plant the sets about 5cm deep into the soil.", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -216,8 +209,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -239,8 +231,7 @@ "relativeStartDate": 0, "relativeEndDate": 14, "description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter", - "interval": null, - "isOptional": false + "interval": null } ] } From b2c0886e4647bd445bd02ae04816e7a187035e57 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 24 Nov 2022 22:27:16 +0100 Subject: [PATCH 4/6] new Structure of taskdb.json --- .../ch/zhaw/gartenverwaltung/io/taskdb.json | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json index 6d40011..7b86231 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/taskdb.json @@ -4,8 +4,10 @@ "name": "sow plant", "description": "Plant the seeds, crops in de bed.", "startDate": "2022-05-01", + "nextExecution": "2022-05-01", + "nextNotification": "2022-05-01", "endDate": "2022-05-01", - "interval": 0, + "interval": null, "cropId": 0 }, { @@ -13,6 +15,8 @@ "name": "water plant", "description": "water the plant, so that the soil is wet around the plant.", "startDate": "2022-05-01", + "nextExecution": "2022-05-01", + "nextNotification": "2022-05-01", "endDate": "2022-09-01", "interval": 2, "cropId": 0 @@ -22,6 +26,8 @@ "name": "fertilize plant", "description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture", "startDate": "2022-06-01", + "nextExecution": "2022-06-01", + "nextNotification": "2022-06-01", "endDate": "2022-08-01", "interval": 28, "cropId": 0 @@ -31,8 +37,10 @@ "name": "covering plant", "description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage", "startDate": "2022-07-01", + "nextExecution": "2022-07-01", + "nextNotification": "2022-07-01", "endDate": "2022-07-01", - "interval": 0, + "interval": null, "cropId": 0 }, { @@ -40,6 +48,8 @@ "name": "look after plant", "description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil", "startDate": "2022-05-01", + "nextExecution": "2022-05-01", + "nextNotification": "2022-05-01", "endDate": "2022-09-01", "interval": 5, "cropId": 0 @@ -49,8 +59,10 @@ "name": "harvest plant", "description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ", "startDate": "2022-09-01", + "nextExecution": "2022-09-01", + "nextNotification": "2022-09-01", "endDate": "2022-09-01", - "interval": 0, + "interval": null, "cropId": 0 } ] \ No newline at end of file From f389cfcdfd96a091f8606fcf11f3a5e9d44e613a Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 25 Nov 2022 11:13:45 +0100 Subject: [PATCH 5/6] adapted GardenSchedule and GardenScheduleTest to new Structure of Task --- .../models/GardenSchedule.java | 24 ++++++++++++----- .../ch/zhaw/gartenverwaltung/types/Task.java | 4 ++- .../models/GardenScheduleTest.java | 18 ++++++++----- .../gartenverwaltung/io/test-plantdb.json | 27 +++++++------------ 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index a362f00..f4b2bb3 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -9,6 +9,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.function.Consumer; import java.util.stream.Collectors; public class GardenSchedule { @@ -136,10 +137,22 @@ public class GardenSchedule { * @throws IOException If the database cannot be accessed */ public List> getTasksUpcomingWeek() throws IOException { + final int listLength = 7; + List weekTasks = taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(listLength - 1)); List> dayTaskList = new ArrayList<>(); - for(int i = 0; i < 7; i++) { + for(int i = 0; i < listLength; i++) { LocalDate date = LocalDate.now().plusDays(i); - dayTaskList.add(taskList.getTaskList(date, date)); + dayTaskList.add(new ArrayList<>()); + final int finalI = i; + weekTasks.forEach(task -> { + LocalDate checkDate = task.getNextExecution(); + do { + if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) { + dayTaskList.get(finalI).add(task); + } + checkDate = checkDate.plusDays(task.getInterval().orElse(0)); + } while (task.getInterval().isPresent() && checkDate.isBefore(LocalDate.now().plusDays(listLength))); + }); } return dayTaskList; } @@ -150,11 +163,8 @@ public class GardenSchedule { * @throws IOException If the database cannot be accessed */ public List> getTasksUpcomingWeekForCrop(Long cropId) throws IOException { - List> dayTaskList = new ArrayList<>(); - for(int i = 0; i < 7; i++) { - LocalDate date = LocalDate.now().plusDays(i); - dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId)); - } + List> dayTaskList = getTasksUpcomingWeek(); + dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId)); return dayTaskList; } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index dab4d39..9501861 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -27,6 +27,7 @@ public class Task { name= ""; description= ""; startDate = LocalDate.now(); + endDate = startDate; nextExecution = startDate; } @@ -34,6 +35,7 @@ public class Task { this.name = name; this.description = description; this.startDate = startDate; + this.endDate = startDate; nextExecution = startDate; this.cropId = cropId; } @@ -63,7 +65,7 @@ public class Task { } public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){ - return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); + return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); } public void done(){ diff --git a/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java b/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java index 0cadffb..5e32687 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/models/GardenScheduleTest.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; class GardenScheduleTest { - LocalDate exampleStartDate = LocalDate.of(2020, 02, 02); + LocalDate exampleStartDate = LocalDate.of(2020, 2, 2); TaskList taskList; PlantList plantList; List examplePlantList; @@ -43,6 +43,7 @@ class GardenScheduleTest { private TaskList mockTaskDatabase(List exampleTaskList) throws IOException { TaskList taskList = mock(JsonTaskList.class); when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList); + when(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7 - 1))).thenReturn(exampleTaskList); when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4))); @@ -105,7 +106,7 @@ class GardenScheduleTest { exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 2L)); exampleTaskList.add(new Task("name", "description", LocalDate.now(), 1L)); exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L)); - exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L)); + exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(10), LocalDate.now().plusDays(4),2, 2L)); } @Test @@ -157,19 +158,22 @@ class GardenScheduleTest { assertEquals(7, dayList.size()); //Check day 0 - assertEquals(1, dayList.get(0).size()); - assertEquals(exampleTaskList.get(2), dayList.get(0).get(0)); + assertEquals(2, dayList.get(0).size()); + assertTrue(dayList.get(0).contains(exampleTaskList.get(2))); + assertTrue(dayList.get(0).contains(exampleTaskList.get(4))); //Check day 1 assertEquals(1, dayList.get(1).size()); - assertEquals(exampleTaskList.get(1), dayList.get(1).get(0)); + assertTrue(dayList.get(1).contains(exampleTaskList.get(1))); //Check day 2 - assertEquals(0, dayList.get(2).size()); + assertEquals(1, dayList.get(2).size()); + assertTrue(dayList.get(2).contains(exampleTaskList.get(4))); //Check day 3 assertEquals(0, dayList.get(3).size()); //Check day 4 - assertEquals(0, dayList.get(4).size()); + assertEquals(1, dayList.get(4).size()); + assertTrue(dayList.get(4).contains(exampleTaskList.get(4))); //Check day 5 assertEquals(0, dayList.get(5).size()); //Check day 6 diff --git a/src/test/resources/ch/zhaw/gartenverwaltung/io/test-plantdb.json b/src/test/resources/ch/zhaw/gartenverwaltung/io/test-plantdb.json index 5440e42..4268df1 100644 --- a/src/test/resources/ch/zhaw/gartenverwaltung/io/test-plantdb.json +++ b/src/test/resources/ch/zhaw/gartenverwaltung/io/test-plantdb.json @@ -32,8 +32,7 @@ "relativeStartDate": -14, "relativeEndDate": null, "description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -54,8 +53,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.", - "interval": 21, - "isOptional": false + "interval": 21 } ] }, @@ -76,8 +74,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -106,8 +103,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -130,8 +126,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -152,8 +147,7 @@ "relativeStartDate": 0, "relativeEndDate": 14, "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -193,8 +187,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -217,8 +210,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -241,8 +233,7 @@ "relativeStartDate": 0, "relativeEndDate": 14, "description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter", - "interval": null, - "isOptional": false + "interval": null } ] } From c9ba9c12347424f8fe2f130e16e840c7f0069685 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 25 Nov 2022 13:01:38 +0100 Subject: [PATCH 6/6] created sortByNextExecution Comparator --- .../java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index f4b2bb3..c3292f6 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -20,6 +20,7 @@ public class GardenSchedule { * Comparators to create sorted Task List */ static final Comparator sortByStartDate = Comparator.comparing(Task::getStartDate); + static final Comparator sortByNextExecution = Comparator.comparing(Task::getNextExecution); /** * Constructor to create Database Objects. @@ -176,7 +177,7 @@ public class GardenSchedule { * @throws IOException If the database cannot be accessed */ public List getFilteredTaskList(LocalDate start, LocalDate end) throws IOException { - return getSortedTaskList(taskList.getTaskList(start, end), sortByStartDate); + return getSortedTaskList(taskList.getTaskList(start, end), sortByNextExecution); } /**