Merge branch 'dev' into feature_taskList_m2

This commit is contained in:
schrom01
2022-11-24 21:55:52 +01:00
45 changed files with 1029 additions and 547 deletions
@@ -28,8 +28,8 @@ public class JsonCropListTest {
/**
* Files to isolate the test-units
*/
private final URL dbDataSource = this.getClass().getResource("user-crops.json");
private final URL testFile = this.getClass().getResource("test-user-crops.json");
private final URL dbDataSource = this.getClass().getResource("test-user-crops.json");
private final URL testFile = this.getClass().getResource("template-user-crops.json");
@BeforeEach
void connectToDb() throws URISyntaxException, IOException {
@@ -8,17 +8,22 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class JsonPlantListTest {
private final URL testFile = this.getClass().getResource("test-plantdb.json");
PlantList testDatabase;
@BeforeEach
void connectToDb() {
testDatabase = new JsonPlantList();
assertNotNull(testFile);
testDatabase = new JsonPlantList(testFile);
}
@@ -18,27 +18,27 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class JsonTaskListTest {
TaskList testDatabase;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
private final URL testFile = this.getClass().getResource("test-taskdb.json");
private final URL dbDataSource = this.getClass().getResource("test-taskdb.json");
private final URL testFile = this.getClass().getResource("template-taskdb.json");
@BeforeEach
void connectToDb() throws URISyntaxException, IOException {
assertNotNull(testFile);
assertNotNull(dbDataSource);
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
testDatabase = new JsonTaskList();
testDatabase = new JsonTaskList(dbDataSource);
}
@Test
@DisplayName("Check if results are retrieved completely")
void getTasks() {
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
LocalDate.parse("2022-05-31", formatter));
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -54,7 +54,7 @@ public class JsonTaskListTest {
Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("01.05.2022", formatter), 1);
try {
testDatabase.saveTask(task);
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
@@ -72,13 +72,14 @@ public class JsonTaskListTest {
@Test
@DisplayName("Remove task.")
void removeTask() {
Task task = new Task("Dummy", "Dummy", LocalDate.parse("31.05.2022", 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 = null;
List<Task> taskList;
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
LocalDate.parse("2022-05-31", formatter));
Assertions.assertEquals(2, taskList.size());
} catch (IOException e) {
@@ -90,7 +91,7 @@ public class JsonTaskListTest {
@Test
void getTaskForCrop() {
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskForCrop(0);
} catch (IOException e) {
@@ -104,7 +105,7 @@ public class JsonTaskListTest {
@Disabled("Disabled until removing works")
@Test
void removeTasksForCrop() {
List<Task> taskList = null;
List<Task> taskList;
try {
testDatabase.removeTasksForCrop(0);
taskList = testDatabase.getTaskForCrop(0);
@@ -22,8 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;
public class GardenPlanModelTest {
private final URL dbDataSource = JsonCropList.class.getResource("user-crops.json");
private final URL testFile = JsonCropList.class.getResource("test-user-crops.json");
private final URL dbDataSource = JsonCropListTest.class.getResource("test-user-crops.json");
private final URL testFile = JsonCropListTest.class.getResource("template-user-crops.json");
CropList cropList;
List<Crop> exampleCrops;
@@ -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());
}
}