finished Tests for TaskListModel

This commit is contained in:
schrom01 2022-11-04 14:20:58 +01:00
parent eea530931e
commit 38288f8561
2 changed files with 45 additions and 20 deletions

View File

@ -9,6 +9,7 @@ import ch.zhaw.gartenverwaltung.types.*;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@ -105,17 +106,17 @@ public class TaskListModel {
}
/**
* Method to get an Array of 7 Tasklists for the next 7 days. Index 0 is Tasklist for Today.
* @return Array with length 7 (List<Task>[])
* Method to get an List of 7 Tasklists for the next 7 days. Index 0 is Tasklist for Today.
* @return List with length 7 (List<List<Task>>)
* @throws IOException If the database cannot be accessed
*/
public List<Task>[] getTasksUpcomingWeek() throws IOException {
List<Task>[] listArray = new List[7];
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
List<List<Task>> dayTaskList = new ArrayList<>();
for(int i = 0; i < 7; i++) {
LocalDate date = LocalDate.now().plusDays(i);
listArray[i] = taskDatabase.getTaskList(date, date);
dayTaskList.add(taskDatabase.getTaskList(date, date));
}
return listArray;
return dayTaskList;
}
/**

View File

@ -41,18 +41,27 @@ class TaskListModelTest {
pastTasks.add(exampleTaskList.get(4));
when(taskDatabase.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());
return taskDatabase;
}
private PlantDatabase mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
return new PlantDatabase() {
@Override
public List<Plant> getPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
public List<Plant> getPlantList(HardinessZone zone) {
return null;
}
@Override
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws IOException, HardinessZoneNotSetException {
public Optional<Plant> getPlantById(HardinessZone zone, long id) {
return Optional.ofNullable(examplePlantMap.get(id));
}
};
@ -61,10 +70,10 @@ class TaskListModelTest {
void createExampleTaskList() {
exampleTaskList = new ArrayList<>();
exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(1), 1L));
exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 1L));
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), 1L));
exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L));
}
void createExamplePlantMap() {
@ -117,18 +126,33 @@ class TaskListModelTest {
}
@Test
void getTasksUpcomingWeek() {
void getTasksUpcomingWeek() throws IOException {
List<List<Task>> dayList = model.getTasksUpcomingWeek();
assertEquals(7, dayList.size());
//Check day 0
assertEquals(1, dayList.get(0).size());
assertEquals(exampleTaskList.get(2), dayList.get(0).get(0));
//Check day 1
assertEquals(1, dayList.get(1).size());
assertEquals(exampleTaskList.get(1), dayList.get(1).get(0));
//Check day 2
assertEquals(0, dayList.get(2).size());
//Check day 3
assertEquals(0, dayList.get(3).size());
//Check day 4
assertEquals(0, dayList.get(4).size());
//Check day 5
assertEquals(0, dayList.get(5).size());
//Check day 6
assertEquals(0, dayList.get(6).size());
}
@Test
void getFilteredTaskList() {
}
@Test
void planTasksForCrop() {
}
@Test
void removeTasksForCrop() {
void removeTasksForCrop() throws IOException {
model.removeTasksForCrop(1L);
verify(taskDatabase, times(1)).removeTasksForCrop(1L);
}
}