From 62fb3869e6b8527e10baa1e69e42e574b50dd2f5 Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Mon, 21 Nov 2022 10:27:31 +0100 Subject: [PATCH] fixed failing tests --- .../java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java | 8 +++++--- .../ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java index b5a0a49..493ebd4 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java @@ -87,10 +87,11 @@ public class JsonTaskList implements TaskList { loadTaskListFromFile(); } - for (Task task : - taskMap.values()) { + List temptasks = taskMap.values().stream(). + filter(task -> { return task.getCropId() == cropId;}).toList(); + for (Task task : temptasks ) { if (task.getCropId() == cropId) { - taskMap.remove(task); + taskMap.remove(task.getId()); } } writeTaskListToFile(); @@ -113,6 +114,7 @@ public class JsonTaskList implements TaskList { if(task.getId() == 0) { task.withId(idProvider.incrementAndGet()); } + taskMap.put(task.getId(),task); writeTaskListToFile(); } diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java index 37cd3a4..a41c973 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java @@ -50,13 +50,13 @@ public class JsonTaskListTest { @Test @DisplayName("Add task.") void addTask() { - Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("01.05.2022", formatter), 1); + Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("2022-05-01", formatter), 1); try { testDatabase.saveTask(task); List 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); }