refactor: renamed everything
This commit is contained in:
+3
-3
@@ -22,8 +22,8 @@ import java.util.stream.Collectors;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JsonGardenPlanTest {
|
||||
private GardenPlan testDatabase;
|
||||
public class JsonCropListTest {
|
||||
private CropList testDatabase;
|
||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
/**
|
||||
* Files to isolate the test-units
|
||||
@@ -36,7 +36,7 @@ public class JsonGardenPlanTest {
|
||||
assertNotNull(testFile);
|
||||
assertNotNull(dbDataSource);
|
||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||
testDatabase = new JsonGardenPlan(dbDataSource);
|
||||
testDatabase = new JsonCropList(dbDataSource);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -13,12 +13,12 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonPlantDatabaseTest {
|
||||
PlantDatabase testDatabase;
|
||||
public class JsonPlantListTest {
|
||||
PlantList testDatabase;
|
||||
|
||||
@BeforeEach
|
||||
void connectToDb() {
|
||||
testDatabase = new JsonPlantDatabase();
|
||||
testDatabase = new JsonPlantList();
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -9,19 +9,15 @@ import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class JsonTaskDatabaseTest {
|
||||
public class JsonTaskListTest {
|
||||
|
||||
TaskDatabase testDatabase;
|
||||
TaskList testDatabase;
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
|
||||
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
|
||||
@@ -32,7 +28,7 @@ public class JsonTaskDatabaseTest {
|
||||
assertNotNull(testFile);
|
||||
assertNotNull(dbDataSource);
|
||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||
testDatabase = new JsonTaskDatabase();
|
||||
testDatabase = new JsonTaskList();
|
||||
}
|
||||
|
||||
@Test
|
||||
+16
-18
@@ -1,16 +1,14 @@
|
||||
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDate;
|
||||
import java.time.MonthDay;
|
||||
import java.util.ArrayList;
|
||||
@@ -21,8 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class GardenPlanModelTest {
|
||||
GardenPlan gardenPlan;
|
||||
List<Crop> cropList;
|
||||
CropList cropList;
|
||||
List<Crop> exampleCrops;
|
||||
Crop exampleCropOnion;
|
||||
Crop exampleCropCarrot;
|
||||
Crop exampleCrop1;
|
||||
@@ -30,7 +28,7 @@ public class GardenPlanModelTest {
|
||||
Crop exampleCrop3;
|
||||
Plant examplePlantOnion;
|
||||
Plant examplePlantCarrot;
|
||||
Gardenplanmodel model;
|
||||
Garden model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
@@ -76,18 +74,18 @@ public class GardenPlanModelTest {
|
||||
exampleCrop3.withId(2);
|
||||
exampleCrop3.withArea(1.0);
|
||||
|
||||
cropList = new ArrayList<>();
|
||||
cropList.add(exampleCrop1);
|
||||
cropList.add(exampleCrop2);
|
||||
cropList.add(exampleCrop3);
|
||||
gardenPlan = mockGardenPlan(cropList);
|
||||
exampleCrops = new ArrayList<>();
|
||||
exampleCrops.add(exampleCrop1);
|
||||
exampleCrops.add(exampleCrop2);
|
||||
exampleCrops.add(exampleCrop3);
|
||||
cropList = mockGardenPlan(exampleCrops);
|
||||
|
||||
TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase());
|
||||
model = new Gardenplanmodel(taskListModel);
|
||||
GardenSchedule gardenSchedule = new GardenSchedule(new JsonTaskList(), new JsonPlantList());
|
||||
model = new Garden(gardenSchedule);
|
||||
}
|
||||
|
||||
GardenPlan mockGardenPlan(List<Crop> cropList) throws IOException {
|
||||
GardenPlan gardenPlan = mock(GardenPlan.class);
|
||||
CropList mockGardenPlan(List<Crop> cropList) throws IOException {
|
||||
CropList gardenPlan = mock(CropList.class);
|
||||
when(gardenPlan.getCrops()).thenReturn(cropList);
|
||||
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
||||
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
||||
+9
-8
@@ -1,8 +1,9 @@
|
||||
package ch.zhaw.gartenverwaltung.plantList;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -22,15 +23,15 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PlantListModelTest {
|
||||
PlantDatabase plantDatabase;
|
||||
PlantList plantList;
|
||||
List<Plant> examplePlantList;
|
||||
PlantListModel model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws HardinessZoneNotSetException, IOException {
|
||||
createExamplePlantList();
|
||||
plantDatabase = mockPlantDatabase(examplePlantList);
|
||||
model = new PlantListModel(plantDatabase);
|
||||
plantList = mockPlantDatabase(examplePlantList);
|
||||
model = new PlantListModel(plantList);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -79,8 +80,8 @@ class PlantListModelTest {
|
||||
);
|
||||
}
|
||||
|
||||
PlantDatabase mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||
PlantDatabase plantDatabase = mock(JsonPlantDatabase.class);
|
||||
PlantList mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||
PlantList plantDatabase = mock(JsonPlantList.class);
|
||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_1A)).thenReturn(new ArrayList<>());
|
||||
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A, 0)).thenReturn(Optional.of(plantList.get(1)));
|
||||
+26
-25
@@ -1,6 +1,7 @@
|
||||
package ch.zhaw.gartenverwaltung.taskList;
|
||||
|
||||
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;
|
||||
@@ -14,47 +15,47 @@ import java.util.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class TaskListModelTest {
|
||||
TaskDatabase taskDatabase;
|
||||
PlantDatabase plantDatabase;
|
||||
class GardenScheduleTest {
|
||||
TaskList taskList;
|
||||
PlantList plantList;
|
||||
List<Task> exampleTaskList;
|
||||
Map<Long, Plant> examplePlantMap;
|
||||
TaskListModel model;
|
||||
GardenSchedule model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
createExampleTaskList();
|
||||
taskDatabase = mockTaskDatabase(exampleTaskList);
|
||||
plantDatabase = mockPlantDatabase(examplePlantMap);
|
||||
model = new TaskListModel(taskDatabase, plantDatabase);
|
||||
taskList = mockTaskDatabase(exampleTaskList);
|
||||
plantList = mockPlantDatabase(examplePlantMap);
|
||||
model = new GardenSchedule(taskList, plantList);
|
||||
}
|
||||
|
||||
private TaskDatabase mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskDatabase taskDatabase = mock(JsonTaskDatabase.class);
|
||||
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskList taskList = mock(JsonTaskList.class);
|
||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||
|
||||
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||
|
||||
List<Task> pastTasks = new ArrayList<>();
|
||||
pastTasks.add(exampleTaskList.get(0));
|
||||
pastTasks.add(exampleTaskList.get(2));
|
||||
pastTasks.add(exampleTaskList.get(4));
|
||||
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
||||
|
||||
|
||||
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.now())).thenReturn(List.of(exampleTaskList.get(2)));
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(1L), LocalDate.now().plusDays(1L))).thenReturn(List.of(exampleTaskList.get(1)));
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(2L), LocalDate.now().plusDays(2L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(3L), LocalDate.now().plusDays(3L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(4L), LocalDate.now().plusDays(4L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(5L), LocalDate.now().plusDays(5L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
||||
when(taskList.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(taskList.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(taskList.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(taskList.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
||||
|
||||
return taskDatabase;
|
||||
return taskList;
|
||||
}
|
||||
|
||||
private PlantDatabase mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||
return new PlantDatabase() {
|
||||
private PlantList mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||
return new PlantList() {
|
||||
@Override
|
||||
public List<Plant> getPlantList(HardinessZone zone) {
|
||||
return null;
|
||||
@@ -86,14 +87,14 @@ class TaskListModelTest {
|
||||
void addTask() throws IOException {
|
||||
Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L);
|
||||
model.addTask(taskToAdd);
|
||||
verify(taskDatabase, times(1)).saveTask(taskToAdd);
|
||||
verify(taskList, times(1)).saveTask(taskToAdd);
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeTask() throws IOException {
|
||||
Task taskToRemove = new Task("name", "description", LocalDate.now(), 1L);
|
||||
model.removeTask(taskToRemove);
|
||||
verify(taskDatabase, times(1)).removeTask(taskToRemove);
|
||||
verify(taskList, times(1)).removeTask(taskToRemove);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,6 +154,6 @@ class TaskListModelTest {
|
||||
@Test
|
||||
void removeTasksForCrop() throws IOException {
|
||||
model.removeTasksForCrop(1L);
|
||||
verify(taskDatabase, times(1)).removeTasksForCrop(1L);
|
||||
verify(taskList, times(1)).removeTasksForCrop(1L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user