From 560cea2ff9a715026c8d602cde5c807b45420d0b Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Sat, 26 Nov 2022 12:49:42 +0100 Subject: [PATCH] Extended coverage for tests --- .../io/JsonPlantListTest.java | 11 ++++++++ .../gartenverwaltung/io/JsonTaskListTest.java | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantListTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantListTest.java index b28c486..4ceeb25 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantListTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantListTest.java @@ -95,5 +95,16 @@ public class JsonPlantListTest { } + @Test + void testDefaultConstructor(){ + JsonPlantList db = new JsonPlantList(); + try { + assertNotNull(db.getPlantList(HardinessZone.ZONE_8A)); + } catch (IOException | HardinessZoneNotSetException e) { + throw new RuntimeException(e); + } + + } + } diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java index 359ea9a..00e21e3 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskListTest.java @@ -2,6 +2,8 @@ package ch.zhaw.gartenverwaltung.io; import ch.zhaw.gartenverwaltung.types.Task; import org.junit.jupiter.api.*; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; import java.io.IOException; import java.net.URISyntaxException; @@ -14,6 +16,8 @@ import java.time.format.DateTimeFormatter; import java.util.List; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class JsonTaskListTest { @@ -113,4 +117,27 @@ public class JsonTaskListTest { Assertions.assertEquals(0, taskList.size()); } + + @Test + void testDefaultConstructor(){ + JsonTaskList db = new JsonTaskList(); + try { + assertNotNull(db.getTaskForCrop(0)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + @Test + void testSubscription() { + TaskList.TaskListObserver mockObs = Mockito.mock(TaskList.TaskListObserver.class); + testDatabase.subscribe(mockObs); + try { + testDatabase.removeTasksForCrop(0); + } catch (IOException e) { + throw new RuntimeException(e); + } + verify(mockObs, times(1)).onChange(ArgumentMatchers.anyList()); + } } \ No newline at end of file