From 251060811791e16f4230bc906111d0740631f71a Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Mon, 31 Oct 2022 11:55:20 +0100 Subject: [PATCH] Extended taskDb tests --- .../io/JsonTaskDatabaseTest.java | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java index e75ea40..a6c3689 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabaseTest.java @@ -6,32 +6,80 @@ import org.junit.jupiter.api.*; import java.io.IOException; 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; + public class JsonTaskDatabaseTest { TaskDatabase testDatabase; - SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); @BeforeEach void connectToDb() { - // testDatabase = new JsonTaskDatabase(); + testDatabase = new JsonTaskDatabase(); } @Test @DisplayName("Check if results are retrieved completely") void getTasks(){ - /* + List taskList=null; try { - taskList = testDatabase.getTaskList(formatter.parse("01.05.2022"), formatter.parse("01.08.2022")); + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); } catch (IOException e) { throw new RuntimeException(e); - } catch (ParseException e) { - throw new RuntimeException(e); } - Assertions.assertTrue(taskList.size()>0); - */ + Assertions.assertEquals(3,taskList.size()); + } + + @Disabled("disabled until idProvider works") + @Test + @DisplayName("Add task.") + void addTask(){ + Task task = new Task("Testtask","This is a test Task.",LocalDate.parse("01.05.2022",formatter)); + try { + testDatabase.saveTask(task); + List taskList=null; + try { + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Assertions.assertEquals(4,taskList.size()); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + @DisplayName("Remove task.") + void removeTask(){ + Task task = new Task("Dummy","Dummy",LocalDate.parse("31.05.2022",formatter)).withId(2); + try { + testDatabase.removeTask(task); + List taskList=null; + try { + taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022",formatter), + LocalDate.parse("31.05.2022",formatter)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Assertions.assertEquals(2,taskList.size()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + }