Compare commits
No commits in common. "4f80a0a3e08f09f4f73bd541d43eb9b162e84958" and "a7fa58344c754b9004d417a92ce6ef95a789fb0e" have entirely different histories.
4f80a0a3e0
...
a7fa58344c
|
@ -1,27 +0,0 @@
|
||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to document bugs.
|
|
||||||
title: "[BUG]"
|
|
||||||
labels: bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Class / Methods**
|
|
||||||
List of classes or methods which contains the bug. (If known)
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
|
@ -1,20 +0,0 @@
|
||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Features to implement
|
|
||||||
title: "[FEATURE]"
|
|
||||||
labels: feature
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Description of Usecase**
|
|
||||||
A clear and concise description of what the feature allows to do.
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**List of Classes and Methods to implement**
|
|
||||||
List all Classes and Methods which have to be implemented.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
|
@ -1,20 +0,0 @@
|
||||||
---
|
|
||||||
name: Tests
|
|
||||||
about: Tests to implement
|
|
||||||
title: "[TEST]"
|
|
||||||
labels: Tests
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Feature description**
|
|
||||||
A clear and concise description of the functionality which have to be tested.
|
|
||||||
|
|
||||||
**Test cases**
|
|
||||||
A list of cases which have to be tested.
|
|
||||||
|
|
||||||
**List of affected Classes and Methods**
|
|
||||||
A clear and concise list of the classes and methods which have to be tested.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
private static HardinessZone currentHardinessZone;
|
||||||
|
|
||||||
|
static {
|
||||||
|
currentHardinessZone = HardinessZone.ZONE_8A;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HardinessZone getCurrentHardinessZone() {
|
||||||
|
return currentHardinessZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
||||||
|
Config.currentHardinessZone = currentHardinessZone;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Pest;
|
import ch.zhaw.gartenverwaltung.types.Pest;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
|
@ -24,8 +24,8 @@ import java.util.List;
|
||||||
public class CropDetailController {
|
public class CropDetailController {
|
||||||
private Crop crop = null;
|
private Crop crop = null;
|
||||||
private final PlantListModel plantListModel = new PlantListModel();
|
private final PlantListModel plantListModel = new PlantListModel();
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
private final TaskListModel taskListModel = new TaskListModel();
|
||||||
private final Garden garden = new Garden(gardenSchedule);
|
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ImageView imageView;
|
private ImageView imageView;
|
||||||
|
@ -89,7 +89,7 @@ public class CropDetailController {
|
||||||
|
|
||||||
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
|
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||||
this.crop = crop;
|
this.crop = crop;
|
||||||
Plant plant = plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||||
cropName_label.setText(plant.name());
|
cropName_label.setText(plant.name());
|
||||||
description_label.setText(plant.description());
|
description_label.setText(plant.description());
|
||||||
light_label.setText(String.valueOf(plant.light()));
|
light_label.setText(String.valueOf(plant.light()));
|
||||||
|
@ -105,7 +105,7 @@ public class CropDetailController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTaskLists(Crop crop) throws IOException {
|
private void createTaskLists(Crop crop) throws IOException {
|
||||||
List<Task> taskList = gardenSchedule.getTaskListForCrop(crop.getCropId().get());
|
List<Task> taskList = taskListModel.getTaskListForCrop(crop.getCropId().get());
|
||||||
for (Task task : taskList) {
|
for (Task task : taskList) {
|
||||||
Label label = new Label(task.getDescription());
|
Label label = new Label(task.getDescription());
|
||||||
growthPhases_vbox.getChildren().add(label);
|
growthPhases_vbox.getChildren().add(label);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
@ -30,8 +30,8 @@ import java.util.*;
|
||||||
|
|
||||||
public class MyPlantsController implements Initializable {
|
public class MyPlantsController implements Initializable {
|
||||||
MainFXMLController mainController;
|
MainFXMLController mainController;
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
private final TaskListModel taskListModel = new TaskListModel();
|
||||||
private final Garden garden = new Garden(gardenSchedule);
|
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||||
private final PlantListModel plantListModel = new PlantListModel();
|
private final PlantListModel plantListModel = new PlantListModel();
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -79,13 +79,13 @@ public class MyPlantsController implements Initializable {
|
||||||
|
|
||||||
private List<Crop> getCropList() throws IOException {
|
private List<Crop> getCropList() throws IOException {
|
||||||
List<Crop> cropList;
|
List<Crop> cropList;
|
||||||
cropList = garden.getCrops();
|
cropList = gardenplanmodel.getCrops();
|
||||||
return cropList;
|
return cropList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HBox createPlantView(Crop crop) throws HardinessZoneNotSetException, IOException {
|
private HBox createPlantView(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||||
//ToDo add better design
|
//ToDo add better design
|
||||||
Plant plant = plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||||
HBox hBox = new HBox(10);
|
HBox hBox = new HBox(10);
|
||||||
ImageView imageView = new ImageView();
|
ImageView imageView = new ImageView();
|
||||||
imageView.setPreserveRatio(false);
|
imageView.setPreserveRatio(false);
|
||||||
|
@ -153,7 +153,7 @@ public class MyPlantsController implements Initializable {
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
Optional<ButtonType> option = alert.showAndWait();
|
||||||
|
|
||||||
if (option.get() == ButtonType.OK) {
|
if (option.get() == ButtonType.OK) {
|
||||||
garden.removeCrop(crop);
|
gardenplanmodel.removeCrop(crop);
|
||||||
loadCropList();
|
loadCropList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import javafx.beans.property.ListProperty;
|
import javafx.beans.property.ListProperty;
|
||||||
|
@ -28,8 +28,8 @@ import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class MyScheduleController implements Initializable {
|
public class MyScheduleController implements Initializable {
|
||||||
private Crop selectedCrop = null;
|
private Crop selectedCrop = null;
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
private final TaskListModel taskListModel = new TaskListModel();
|
||||||
private final Garden garden = new Garden(gardenSchedule);
|
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||||
private final PlantListModel plantListModel = new PlantListModel();
|
private final PlantListModel plantListModel = new PlantListModel();
|
||||||
|
|
||||||
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||||
|
@ -89,7 +89,7 @@ public class MyScheduleController implements Initializable {
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
List<Crop> cropList;
|
List<Crop> cropList;
|
||||||
try {
|
try {
|
||||||
cropList = garden.getCrops();
|
cropList = gardenplanmodel.getCrops();
|
||||||
cropListProperty.addAll(cropList);
|
cropListProperty.addAll(cropList);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -141,7 +141,7 @@ public class MyScheduleController implements Initializable {
|
||||||
setText(null);
|
setText(null);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
setText(plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0).name());
|
setText(plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0).name());
|
||||||
} catch (HardinessZoneNotSetException | IOException e) {
|
} catch (HardinessZoneNotSetException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -153,9 +153,9 @@ public class MyScheduleController implements Initializable {
|
||||||
private void loadTaskList() throws IOException {
|
private void loadTaskList() throws IOException {
|
||||||
List<List<Task>> taskLists = new LinkedList<>();
|
List<List<Task>> taskLists = new LinkedList<>();
|
||||||
if (selectedCrop != null) {
|
if (selectedCrop != null) {
|
||||||
taskLists = gardenSchedule.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
taskLists = taskListModel.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
||||||
} else {
|
} else {
|
||||||
taskLists = gardenSchedule.getTasksUpcomingWeek();
|
taskLists = taskListModel.getTasksUpcomingWeek();
|
||||||
}
|
}
|
||||||
if (!taskLists.isEmpty()) {
|
if (!taskLists.isEmpty()) {
|
||||||
viewTaskListOfDay(day1_pane, taskLists.get(0));
|
viewTaskListOfDay(day1_pane, taskLists.get(0));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Seasons;
|
import ch.zhaw.gartenverwaltung.types.Seasons;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
@ -21,8 +23,8 @@ import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class SelectSowDayController implements Initializable {
|
public class SelectSowDayController implements Initializable {
|
||||||
private Plant selectedPlant = null;
|
private Plant selectedPlant = null;
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
private final TaskListModel taskListModel = new TaskListModel();
|
||||||
private final Garden garden = new Garden(gardenSchedule);
|
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private DatePicker datepicker;
|
private DatePicker datepicker;
|
||||||
|
@ -61,7 +63,7 @@ public class SelectSowDayController implements Initializable {
|
||||||
//ToDo method to get current lifecycle group in plant
|
//ToDo method to get current lifecycle group in plant
|
||||||
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
||||||
}
|
}
|
||||||
garden.plantAsCrop(selectedPlant, sowDate);
|
gardenplanmodel.plantAsCrop(selectedPlant, sowDate);
|
||||||
closeWindow();
|
closeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +97,12 @@ public class SelectSowDayController implements Initializable {
|
||||||
* clear date picker editor when radio button is changed
|
* clear date picker editor when radio button is changed
|
||||||
*/
|
*/
|
||||||
private void clearDatePickerEntries() {
|
private void clearDatePickerEntries() {
|
||||||
sow_radio.selectedProperty().addListener((observable, oldValue, isNowSelected) -> datepicker.getEditor().clear());
|
sow_radio.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean isNowSelected) {
|
||||||
|
datepicker.getEditor().clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,12 +160,15 @@ public class SelectSowDayController implements Initializable {
|
||||||
*/
|
*/
|
||||||
private void enableDisableSaveButton() {
|
private void enableDisableSaveButton() {
|
||||||
save_button.setDisable(true);
|
save_button.setDisable(true);
|
||||||
datepicker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
|
datepicker.getEditor().textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
if (newValue == null || newValue.equals("")) {
|
if (newValue == null || newValue.equals("")) {
|
||||||
save_button.setDisable(true);
|
save_button.setDisable(true);
|
||||||
} else {
|
} else {
|
||||||
save_button.setDisable(false);
|
save_button.setDisable(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung;
|
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
|
||||||
|
|
||||||
public class Settings {
|
|
||||||
private HardinessZone currentHardinessZone = HardinessZone.ZONE_8A;
|
|
||||||
private static Settings instance;
|
|
||||||
|
|
||||||
static {
|
|
||||||
instance = new Settings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Settings getInstance() {
|
|
||||||
return Settings.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Settings() {}
|
|
||||||
|
|
||||||
public HardinessZone getCurrentHardinessZone() {
|
|
||||||
return currentHardinessZone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
|
||||||
this.currentHardinessZone = currentHardinessZone;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +1,41 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.CropList;
|
import ch.zhaw.gartenverwaltung.io.GardenPlan;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonCropList;
|
import ch.zhaw.gartenverwaltung.io.JsonGardenPlan;
|
||||||
|
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||||
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Gardenplan model manages the crops in the gardenplan.
|
* The Gardenplan model manages the crops in the gardenplan.
|
||||||
*/
|
*/
|
||||||
public class Garden {
|
public class Gardenplanmodel {
|
||||||
private CropList cropList;
|
private GardenPlan gardenPlan;
|
||||||
private final ObservableList<Crop> plantedCrops = FXCollections.observableArrayList();
|
private List<Crop> cropList;
|
||||||
private GardenSchedule gardenSchedule;
|
private TaskListModel taskListModel;
|
||||||
|
private Object IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of Gardenplan model
|
* Constructor of Gardenplan model
|
||||||
*
|
*
|
||||||
* @param gardenSchedule holds a reference to the task list object.
|
* @param taskListModel holds a reference to the task list object.
|
||||||
*/
|
*/
|
||||||
public Garden(GardenSchedule gardenSchedule) throws IOException {
|
public Gardenplanmodel(TaskListModel taskListModel) throws IOException {
|
||||||
this.gardenSchedule = gardenSchedule;
|
this.taskListModel = taskListModel;
|
||||||
cropList = new JsonCropList();
|
gardenPlan = new JsonGardenPlan();
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
cropList = new ArrayList<>();
|
||||||
|
cropList = gardenPlan.getCrops();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,10 +52,9 @@ public class Garden {
|
||||||
Crop crop = new Crop(plant.id(), plantingDate);
|
Crop crop = new Crop(plant.id(), plantingDate);
|
||||||
//TODO Add Area to Plant
|
//TODO Add Area to Plant
|
||||||
//crop.withArea(0);
|
//crop.withArea(0);
|
||||||
cropList.saveCrop(crop);
|
gardenPlan.saveCrop(crop);
|
||||||
gardenSchedule.planTasksForCrop(crop);
|
taskListModel.planTasksForCrop(crop);
|
||||||
plantedCrops.clear();
|
cropList = gardenPlan.getCrops();
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,10 +64,9 @@ public class Garden {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void removeCrop(Crop crop) throws IOException {
|
public void removeCrop(Crop crop) throws IOException {
|
||||||
cropList.removeCrop(crop);
|
gardenPlan.removeCrop(crop);
|
||||||
gardenSchedule.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
|
taskListModel.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
|
||||||
plantedCrops.clear();
|
cropList = gardenPlan.getCrops();
|
||||||
plantedCrops.addAll(cropList.getCrops());
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
||||||
|
@ -72,7 +74,10 @@ public class Garden {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<Crop> getCrops() throws IOException {
|
public List<Crop> getCrops() throws IOException {
|
||||||
return cropList.getCrops();
|
if(!cropList.isEmpty()){
|
||||||
|
cropList = gardenPlan.getCrops();
|
||||||
|
}
|
||||||
|
return cropList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,6 +87,6 @@ public class Garden {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public Optional<Crop> getCrop(Long cropId) throws IOException {
|
public Optional<Crop> getCrop(Long cropId) throws IOException {
|
||||||
return cropList.getCropById(cropId);
|
return gardenPlan.getCropById(cropId);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface CropList {
|
public interface GardenPlan {
|
||||||
/**
|
/**
|
||||||
* Yields a list of all {@link Crop}s in the database.
|
* Yields a list of all {@link Crop}s in the database.
|
||||||
*
|
*
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class JsonCropList implements CropList {
|
public class JsonGardenPlan implements GardenPlan {
|
||||||
private final URL dataSource;
|
private final URL dataSource;
|
||||||
|
|
||||||
private IdProvider idProvider;
|
private IdProvider idProvider;
|
||||||
|
@ -42,7 +42,7 @@ public class JsonCropList implements CropList {
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
public JsonCropList() {
|
public JsonGardenPlan() {
|
||||||
this.dataSource = getClass().getResource("user-crops.json");
|
this.dataSource = getClass().getResource("user-crops.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class JsonCropList implements CropList {
|
||||||
* Constructor to use a specified {@link URL} as a {@link #dataSource}
|
* Constructor to use a specified {@link URL} as a {@link #dataSource}
|
||||||
* @param dataSource A {@link URL} to the file to be used as a data source
|
* @param dataSource A {@link URL} to the file to be used as a data source
|
||||||
*/
|
*/
|
||||||
public JsonCropList(URL dataSource) {
|
public JsonGardenPlan(URL dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
|
@ -20,11 +20,11 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link PlantList} interface for loading {@link Plant} objects
|
* Implements the {@link PlantDatabase} interface for loading {@link Plant} objects
|
||||||
* from a JSON file.
|
* from a JSON file.
|
||||||
* The reads are cached to minimize file-io operations.
|
* The reads are cached to minimize file-io operations.
|
||||||
*/
|
*/
|
||||||
public class JsonPlantList implements PlantList {
|
public class JsonPlantDatabase implements PlantDatabase {
|
||||||
private final URL dataSource = getClass().getResource("plantdb.json");
|
private final URL dataSource = getClass().getResource("plantdb.json");
|
||||||
|
|
||||||
private HardinessZone currentZone;
|
private HardinessZone currentZone;
|
||||||
|
@ -49,7 +49,7 @@ public class JsonPlantList implements PlantList {
|
||||||
* from the {@link #currentZone}, data is loaded from {@link #dataSource}.
|
* from the {@link #currentZone}, data is loaded from {@link #dataSource}.
|
||||||
* In any case, the values of {@link #plantMap} are returned.
|
* In any case, the values of {@link #plantMap} are returned.
|
||||||
*
|
*
|
||||||
* @see PlantList#getPlantList(HardinessZone)
|
* @see PlantDatabase#getPlantList(HardinessZone)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Plant> getPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
|
public List<Plant> getPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
|
||||||
|
@ -60,7 +60,7 @@ public class JsonPlantList implements PlantList {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see PlantList#getPlantById(long)
|
* @see PlantDatabase#getPlantById(long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {
|
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {
|
|
@ -1,5 +1,6 @@
|
||||||
package ch.zhaw.gartenverwaltung.io;
|
package ch.zhaw.gartenverwaltung.io;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||||
|
@ -19,11 +20,11 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link TaskList} interface for loading and writing {@link Task} objects
|
* Implements the {@link TaskDatabase} interface for loading and writing {@link Task} objects
|
||||||
* from and to a JSON file.
|
* from and to a JSON file.
|
||||||
* The reads are cached to minimize file-io operations.
|
* The reads are cached to minimize file-io operations.
|
||||||
*/
|
*/
|
||||||
public class JsonTaskList implements TaskList {
|
public class JsonTaskDatabase implements TaskDatabase{
|
||||||
IdProvider idProvider;
|
IdProvider idProvider;
|
||||||
private final URL dataSource = getClass().getResource("taskdb.json");
|
private final URL dataSource = getClass().getResource("taskdb.json");
|
||||||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||||
|
@ -47,7 +48,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
||||||
* In any case, the values of {@link #taskMap} are returned.
|
* In any case, the values of {@link #taskMap} are returned.
|
||||||
*
|
*
|
||||||
* @see TaskList#getTaskList(LocalDate, LocalDate)
|
* @see TaskDatabase#getTaskList(LocalDate, LocalDate)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException{
|
public List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException{
|
||||||
|
@ -89,7 +90,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* it to the {@link #taskMap}. In any case, the {@link #taskMap} is written
|
* it to the {@link #taskMap}. In any case, the {@link #taskMap} is written
|
||||||
* to the {@link #dataSource}.
|
* to the {@link #dataSource}.
|
||||||
*
|
*
|
||||||
* @see TaskList#saveTask(Task)
|
* @see TaskDatabase#saveTask(Task)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveTask(Task task) throws IOException {
|
public void saveTask(Task task) throws IOException {
|
||||||
|
@ -107,7 +108,7 @@ public class JsonTaskList implements TaskList {
|
||||||
* If the {@link Task}s id is found in the {@link #taskMap}, the Task is removed
|
* If the {@link Task}s id is found in the {@link #taskMap}, the Task is removed
|
||||||
* from the {@link #taskMap}. Then the Task are written to the {@link #dataSource}.
|
* from the {@link #taskMap}. Then the Task are written to the {@link #dataSource}.
|
||||||
*
|
*
|
||||||
* @see TaskList#removeTask(Task)
|
* @see TaskDatabase#removeTask(Task)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void removeTask(Task task) throws IOException {
|
public void removeTask(Task task) throws IOException {
|
|
@ -11,7 +11,7 @@ import java.util.Optional;
|
||||||
* A database of {@link Plant}s.
|
* A database of {@link Plant}s.
|
||||||
* The interface specifies the minimal required operations.
|
* The interface specifies the minimal required operations.
|
||||||
*/
|
*/
|
||||||
public interface PlantList {
|
public interface PlantDatabase {
|
||||||
/**
|
/**
|
||||||
* Yields a list of all {@link Plant}s in the database with only data relevant to the specfied {@link HardinessZone}
|
* Yields a list of all {@link Plant}s in the database with only data relevant to the specfied {@link HardinessZone}
|
||||||
*
|
*
|
|
@ -1,16 +1,20 @@
|
||||||
package ch.zhaw.gartenverwaltung.io;
|
package ch.zhaw.gartenverwaltung.io;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A database of {@link Task}s.
|
* A database of {@link Task}s.
|
||||||
* The interface specifies the minimal required operations.
|
* The interface specifies the minimal required operations.
|
||||||
*/
|
*/
|
||||||
public interface TaskList {
|
public interface TaskDatabase {
|
||||||
/**
|
/**
|
||||||
* Yields a list of all {@link Task}s in the database with the start and end date of a period of time.
|
* Yields a list of all {@link Task}s in the database with the start and end date of a period of time.
|
||||||
*
|
*
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.zhaw.gartenverwaltung.json;
|
package ch.zhaw.gartenverwaltung.json;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
@ -18,7 +18,7 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
||||||
@Override
|
@Override
|
||||||
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||||
Image result = null;
|
Image result = null;
|
||||||
URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
|
URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText()));
|
||||||
if (imageUrl != null) {
|
if (imageUrl != null) {
|
||||||
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
|
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
|
||||||
result = new Image(is);
|
result = new Image(is);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.plantList;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
|
@ -16,7 +16,7 @@ import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlantListModel {
|
public class PlantListModel {
|
||||||
private PlantList plantList;
|
private PlantDatabase plantDatabase;
|
||||||
private HardinessZone currentZone;
|
private HardinessZone currentZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,17 +29,17 @@ public class PlantListModel {
|
||||||
* Constructor to create Database Object.
|
* Constructor to create Database Object.
|
||||||
*/
|
*/
|
||||||
public PlantListModel() {
|
public PlantListModel() {
|
||||||
plantList = new JsonPlantList();
|
plantDatabase = new JsonPlantDatabase();
|
||||||
setDefaultZone();
|
setDefaultZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlantListModel(PlantList plantList) {
|
public PlantListModel(PlantDatabase plantDatabase) {
|
||||||
this.plantList = plantList;
|
this.plantDatabase = plantDatabase;
|
||||||
setDefaultZone();
|
setDefaultZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultZone() {
|
private void setDefaultZone() {
|
||||||
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings
|
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Config
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentZone(HardinessZone currentZone) {
|
public void setCurrentZone(HardinessZone currentZone) {
|
||||||
|
@ -72,7 +72,7 @@ public class PlantListModel {
|
||||||
*/
|
*/
|
||||||
public List<Plant> getSortedPlantList(HardinessZone zone, Comparator<Plant> comparator) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getSortedPlantList(HardinessZone zone, Comparator<Plant> comparator) throws HardinessZoneNotSetException, IOException {
|
||||||
setCurrentZone(zone);
|
setCurrentZone(zone);
|
||||||
return plantList.getPlantList(zone).stream().sorted(comparator).collect(Collectors.toList());
|
return plantDatabase.getPlantList(zone).stream().sorted(comparator).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,7 +101,7 @@ public class PlantListModel {
|
||||||
public List<Plant> getFilteredPlantListById(HardinessZone zone, Long id) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getFilteredPlantListById(HardinessZone zone, Long id) throws HardinessZoneNotSetException, IOException {
|
||||||
setCurrentZone(zone);
|
setCurrentZone(zone);
|
||||||
List<Plant> plantList = new ArrayList<>();
|
List<Plant> plantList = new ArrayList<>();
|
||||||
this.plantList.getPlantById(zone, id).ifPresent(plantList::add);
|
plantDatabase.getPlantById(zone, id).ifPresent(plantList::add);
|
||||||
return plantList;
|
return plantList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.taskList;
|
||||||
|
|
||||||
public class PlantNotFoundException extends Exception {
|
public class PlantNotFoundException extends Exception {
|
||||||
public PlantNotFoundException() {
|
public PlantNotFoundException() {
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.taskList;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.Settings;
|
import ch.zhaw.gartenverwaltung.Config;
|
||||||
import ch.zhaw.gartenverwaltung.io.*;
|
import ch.zhaw.gartenverwaltung.io.*;
|
||||||
import ch.zhaw.gartenverwaltung.types.*;
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
|
|
||||||
|
@ -9,28 +9,29 @@ import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class GardenSchedule {
|
public class TaskListModel {
|
||||||
private TaskList taskList;
|
private TaskDatabase taskDatabase;
|
||||||
private PlantList plantList;
|
private PlantDatabase plantDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparators to create sorted Task List
|
* Comparators to create sorted Task List
|
||||||
*/
|
*/
|
||||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||||
|
|
||||||
public GardenSchedule(){
|
public TaskListModel(){
|
||||||
taskList = new JsonTaskList();
|
taskDatabase = new JsonTaskDatabase();
|
||||||
plantList = new JsonPlantList();
|
plantDatabase = new JsonPlantDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to create Database Objects.
|
* Constructor to create Database Objects.
|
||||||
*/
|
*/
|
||||||
public GardenSchedule(TaskList taskList, PlantList plantList) {
|
public TaskListModel(TaskDatabase taskDatabase, PlantDatabase plantDatabase) {
|
||||||
this.taskList = taskList;
|
this.taskDatabase = taskDatabase;
|
||||||
this.plantList = plantList;
|
this.plantDatabase = plantDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +40,7 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void addTask(Task task) throws IOException {
|
public void addTask(Task task) throws IOException {
|
||||||
taskList.saveTask(task);
|
taskDatabase.saveTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +51,7 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
||||||
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
Plant plant = plantDatabase.getPlantById(Config.getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||||
for (GrowthPhase growthPhase : plant.lifecycle()) {
|
for (GrowthPhase growthPhase : plant.lifecycle()) {
|
||||||
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
||||||
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||||
|
@ -64,7 +65,7 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void removeTasksForCrop(long cropId) throws IOException {
|
public void removeTasksForCrop(long cropId) throws IOException {
|
||||||
taskList.removeTasksForCrop(cropId);
|
taskDatabase.removeTasksForCrop(cropId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +74,7 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void removeTask(Task task) throws IOException {
|
public void removeTask(Task task) throws IOException {
|
||||||
taskList.removeTask(task);
|
taskDatabase.removeTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Task> filterListByCrop(List<Task> taskList, Long cropId) {
|
private List<Task> filterListByCrop(List<Task> taskList, Long cropId) {
|
||||||
|
@ -143,7 +144,7 @@ public class GardenSchedule {
|
||||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++) {
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
LocalDate date = LocalDate.now().plusDays(i);
|
||||||
dayTaskList.add(taskList.getTaskList(date, date));
|
dayTaskList.add(taskDatabase.getTaskList(date, date));
|
||||||
}
|
}
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +158,7 @@ public class GardenSchedule {
|
||||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++) {
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
LocalDate date = LocalDate.now().plusDays(i);
|
||||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
dayTaskList.add(filterListByCrop(taskDatabase.getTaskList(date, date), cropId));
|
||||||
}
|
}
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,7 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
||||||
return getSortedTaskList(taskList.getTaskList(start, end), sortByStartDate);
|
return getSortedTaskList(taskDatabase.getTaskList(start, end), sortByStartDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,14 +1,16 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.*;
|
import ch.zhaw.gartenverwaltung.io.*;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.*;
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.MonthDay;
|
import java.time.MonthDay;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -19,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class GardenPlanModelTest {
|
public class GardenPlanModelTest {
|
||||||
CropList cropList;
|
GardenPlan gardenPlan;
|
||||||
List<Crop> exampleCrops;
|
List<Crop> cropList;
|
||||||
Crop exampleCropOnion;
|
Crop exampleCropOnion;
|
||||||
Crop exampleCropCarrot;
|
Crop exampleCropCarrot;
|
||||||
Crop exampleCrop1;
|
Crop exampleCrop1;
|
||||||
|
@ -28,7 +30,7 @@ public class GardenPlanModelTest {
|
||||||
Crop exampleCrop3;
|
Crop exampleCrop3;
|
||||||
Plant examplePlantOnion;
|
Plant examplePlantOnion;
|
||||||
Plant examplePlantCarrot;
|
Plant examplePlantCarrot;
|
||||||
Garden model;
|
Gardenplanmodel model;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws IOException {
|
void setUp() throws IOException {
|
||||||
|
@ -74,18 +76,18 @@ public class GardenPlanModelTest {
|
||||||
exampleCrop3.withId(2);
|
exampleCrop3.withId(2);
|
||||||
exampleCrop3.withArea(1.0);
|
exampleCrop3.withArea(1.0);
|
||||||
|
|
||||||
exampleCrops = new ArrayList<>();
|
cropList = new ArrayList<>();
|
||||||
exampleCrops.add(exampleCrop1);
|
cropList.add(exampleCrop1);
|
||||||
exampleCrops.add(exampleCrop2);
|
cropList.add(exampleCrop2);
|
||||||
exampleCrops.add(exampleCrop3);
|
cropList.add(exampleCrop3);
|
||||||
cropList = mockGardenPlan(exampleCrops);
|
gardenPlan = mockGardenPlan(cropList);
|
||||||
|
|
||||||
GardenSchedule gardenSchedule = new GardenSchedule(new JsonTaskList(), new JsonPlantList());
|
TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase());
|
||||||
model = new Garden(gardenSchedule);
|
model = new Gardenplanmodel(taskListModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
CropList mockGardenPlan(List<Crop> cropList) throws IOException {
|
GardenPlan mockGardenPlan(List<Crop> cropList) throws IOException {
|
||||||
CropList gardenPlan = mock(CropList.class);
|
GardenPlan gardenPlan = mock(GardenPlan.class);
|
||||||
when(gardenPlan.getCrops()).thenReturn(cropList);
|
when(gardenPlan.getCrops()).thenReturn(cropList);
|
||||||
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
||||||
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
|
@ -22,8 +22,8 @@ import java.util.stream.Collectors;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class JsonCropListTest {
|
public class JsonGardenPlanTest {
|
||||||
private CropList testDatabase;
|
private GardenPlan testDatabase;
|
||||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
/**
|
/**
|
||||||
* Files to isolate the test-units
|
* Files to isolate the test-units
|
||||||
|
@ -36,7 +36,7 @@ public class JsonCropListTest {
|
||||||
assertNotNull(testFile);
|
assertNotNull(testFile);
|
||||||
assertNotNull(dbDataSource);
|
assertNotNull(dbDataSource);
|
||||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
testDatabase = new JsonCropList(dbDataSource);
|
testDatabase = new JsonGardenPlan(dbDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,12 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class JsonPlantListTest {
|
public class JsonPlantDatabaseTest {
|
||||||
PlantList testDatabase;
|
PlantDatabase testDatabase;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void connectToDb() {
|
void connectToDb() {
|
||||||
testDatabase = new JsonPlantList();
|
testDatabase = new JsonPlantDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,19 @@ import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
public class JsonTaskListTest {
|
public class JsonTaskDatabaseTest {
|
||||||
|
|
||||||
TaskList testDatabase;
|
TaskDatabase testDatabase;
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||||
|
|
||||||
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
|
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
|
||||||
|
@ -28,7 +32,7 @@ public class JsonTaskListTest {
|
||||||
assertNotNull(testFile);
|
assertNotNull(testFile);
|
||||||
assertNotNull(dbDataSource);
|
assertNotNull(dbDataSource);
|
||||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
testDatabase = new JsonTaskList();
|
testDatabase = new JsonTaskDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -47,7 +51,7 @@ public class JsonTaskListTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("disabled until adding works.")
|
//@Disabled("disabled until idProvider works")
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Add task.")
|
@DisplayName("Add task.")
|
||||||
void addTask() {
|
void addTask() {
|
||||||
|
@ -101,7 +105,6 @@ public class JsonTaskListTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Disabled until removing works")
|
|
||||||
@Test
|
@Test
|
||||||
void removeTasksForCrop() {
|
void removeTasksForCrop() {
|
||||||
List<Task> taskList = null;
|
List<Task> taskList = null;
|
|
@ -1,9 +1,8 @@
|
||||||
package ch.zhaw.gartenverwaltung.models;
|
package ch.zhaw.gartenverwaltung.plantList;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.*;
|
import ch.zhaw.gartenverwaltung.types.*;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -23,15 +22,15 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
class PlantListModelTest {
|
class PlantListModelTest {
|
||||||
PlantList plantList;
|
PlantDatabase plantDatabase;
|
||||||
List<Plant> examplePlantList;
|
List<Plant> examplePlantList;
|
||||||
PlantListModel model;
|
PlantListModel model;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws HardinessZoneNotSetException, IOException {
|
void setUp() throws HardinessZoneNotSetException, IOException {
|
||||||
createExamplePlantList();
|
createExamplePlantList();
|
||||||
plantList = mockPlantDatabase(examplePlantList);
|
plantDatabase = mockPlantDatabase(examplePlantList);
|
||||||
model = new PlantListModel(plantList);
|
model = new PlantListModel(plantDatabase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
@ -80,8 +79,8 @@ class PlantListModelTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlantList mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
PlantDatabase mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||||
PlantList plantDatabase = mock(JsonPlantList.class);
|
PlantDatabase plantDatabase = mock(JsonPlantDatabase.class);
|
||||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
||||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_1A)).thenReturn(new ArrayList<>());
|
when(plantDatabase.getPlantList(HardinessZone.ZONE_1A)).thenReturn(new ArrayList<>());
|
||||||
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A, 0)).thenReturn(Optional.of(plantList.get(1)));
|
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A, 0)).thenReturn(Optional.of(plantList.get(1)));
|
|
@ -1,7 +1,6 @@
|
||||||
package ch.zhaw.gartenverwaltung.taskList;
|
package ch.zhaw.gartenverwaltung.taskList;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.io.*;
|
import ch.zhaw.gartenverwaltung.io.*;
|
||||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
|
@ -15,47 +14,47 @@ import java.util.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
class GardenScheduleTest {
|
class TaskListModelTest {
|
||||||
TaskList taskList;
|
TaskDatabase taskDatabase;
|
||||||
PlantList plantList;
|
PlantDatabase plantDatabase;
|
||||||
List<Task> exampleTaskList;
|
List<Task> exampleTaskList;
|
||||||
Map<Long, Plant> examplePlantMap;
|
Map<Long, Plant> examplePlantMap;
|
||||||
GardenSchedule model;
|
TaskListModel model;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws IOException {
|
void setUp() throws IOException {
|
||||||
createExampleTaskList();
|
createExampleTaskList();
|
||||||
taskList = mockTaskDatabase(exampleTaskList);
|
taskDatabase = mockTaskDatabase(exampleTaskList);
|
||||||
plantList = mockPlantDatabase(examplePlantMap);
|
plantDatabase = mockPlantDatabase(examplePlantMap);
|
||||||
model = new GardenSchedule(taskList, plantList);
|
model = new TaskListModel(taskDatabase, plantDatabase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
private TaskDatabase mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||||
TaskList taskList = mock(JsonTaskList.class);
|
TaskDatabase taskDatabase = mock(JsonTaskDatabase.class);
|
||||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||||
|
|
||||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||||
|
|
||||||
List<Task> pastTasks = new ArrayList<>();
|
List<Task> pastTasks = new ArrayList<>();
|
||||||
pastTasks.add(exampleTaskList.get(0));
|
pastTasks.add(exampleTaskList.get(0));
|
||||||
pastTasks.add(exampleTaskList.get(2));
|
pastTasks.add(exampleTaskList.get(2));
|
||||||
pastTasks.add(exampleTaskList.get(4));
|
pastTasks.add(exampleTaskList.get(4));
|
||||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
||||||
|
|
||||||
|
|
||||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.now())).thenReturn(List.of(exampleTaskList.get(2)));
|
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.now())).thenReturn(List.of(exampleTaskList.get(2)));
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(1L), LocalDate.now().plusDays(1L))).thenReturn(List.of(exampleTaskList.get(1)));
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(1L), LocalDate.now().plusDays(1L))).thenReturn(List.of(exampleTaskList.get(1)));
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(2L), LocalDate.now().plusDays(2L))).thenReturn(List.of());
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(2L), LocalDate.now().plusDays(2L))).thenReturn(List.of());
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(3L), LocalDate.now().plusDays(3L))).thenReturn(List.of());
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(3L), LocalDate.now().plusDays(3L))).thenReturn(List.of());
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(4L), LocalDate.now().plusDays(4L))).thenReturn(List.of());
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(4L), LocalDate.now().plusDays(4L))).thenReturn(List.of());
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(5L), LocalDate.now().plusDays(5L))).thenReturn(List.of());
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(5L), LocalDate.now().plusDays(5L))).thenReturn(List.of());
|
||||||
when(taskList.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
when(taskDatabase.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
||||||
|
|
||||||
return taskList;
|
return taskDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlantList mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
private PlantDatabase mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||||
return new PlantList() {
|
return new PlantDatabase() {
|
||||||
@Override
|
@Override
|
||||||
public List<Plant> getPlantList(HardinessZone zone) {
|
public List<Plant> getPlantList(HardinessZone zone) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -87,14 +86,14 @@ class GardenScheduleTest {
|
||||||
void addTask() throws IOException {
|
void addTask() throws IOException {
|
||||||
Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L);
|
Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L);
|
||||||
model.addTask(taskToAdd);
|
model.addTask(taskToAdd);
|
||||||
verify(taskList, times(1)).saveTask(taskToAdd);
|
verify(taskDatabase, times(1)).saveTask(taskToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void removeTask() throws IOException {
|
void removeTask() throws IOException {
|
||||||
Task taskToRemove = new Task("name", "description", LocalDate.now(), 1L);
|
Task taskToRemove = new Task("name", "description", LocalDate.now(), 1L);
|
||||||
model.removeTask(taskToRemove);
|
model.removeTask(taskToRemove);
|
||||||
verify(taskList, times(1)).removeTask(taskToRemove);
|
verify(taskDatabase, times(1)).removeTask(taskToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -154,6 +153,6 @@ class GardenScheduleTest {
|
||||||
@Test
|
@Test
|
||||||
void removeTasksForCrop() throws IOException {
|
void removeTasksForCrop() throws IOException {
|
||||||
model.removeTasksForCrop(1L);
|
model.removeTasksForCrop(1L);
|
||||||
verify(taskList, times(1)).removeTasksForCrop(1L);
|
verify(taskDatabase, times(1)).removeTasksForCrop(1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue