From 77541c282c866ef5407bf752bc65f45c7b3bfcd1 Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Sat, 26 Nov 2022 11:22:27 +0100 Subject: [PATCH] fixed RemoveTasksForCrop --- .../ch/zhaw/gartenverwaltung/io/JsonTaskList.java | 3 ++- .../zhaw/gartenverwaltung/io/JsonTaskListTest.java | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java index 7f6d36b..caecb1a 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskList.java @@ -88,7 +88,8 @@ public class JsonTaskList implements TaskList { if(taskMap.isEmpty()) { loadTaskListFromFile(); } - taskMap.values().removeIf(task -> task.getCropId() == cropId); + taskMap.entrySet().removeIf(entry -> entry.getValue().getCropId() == cropId); + writeTaskListToFile(); notifySubscribers(); } diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java index bc11d99..359ea9a 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java @@ -47,17 +47,16 @@ public class JsonTaskListTest { } - @Disabled("disabled until adding works.") @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); } @@ -72,8 +71,7 @@ public class JsonTaskListTest { @Test @DisplayName("Remove task.") void removeTask() { - Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1) - .withId(2); + Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1).withId(2); try { testDatabase.removeTask(task); List taskList; @@ -102,7 +100,7 @@ public class JsonTaskListTest { } - @Disabled("Disabled until removing works") + @Test void removeTasksForCrop() { List taskList;