From ee96ffbc523a357802db9145173ecdd5a5b8315c Mon Sep 17 00:00:00 2001 From: Elias Csomor Date: Mon, 31 Oct 2022 10:43:13 +0100 Subject: [PATCH] Extended test for zones --- .../io/JsonPlantDatabaseTest.java | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabaseTest.java b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabaseTest.java index a21b440..73ed8cb 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabaseTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabaseTest.java @@ -26,11 +26,13 @@ public class JsonPlantDatabaseTest { @Test @DisplayName("Check if results are retrieved completely") - void getPlantList() { + void getPlantListNotEmpty() { List testList; try { testList = testDatabase.getPlantList(HardinessZone.ZONE_8A); - } catch (IOException | HardinessZoneNotSetException e) { + } catch (IOException e) { + throw new RuntimeException(e); + } catch (HardinessZoneNotSetException e) { throw new RuntimeException(e); } Assertions.assertEquals(3, testList.size()); @@ -40,13 +42,50 @@ public class JsonPlantDatabaseTest { Assertions.assertEquals(expected,names); } + @Test + @DisplayName("Check if results are retrieved correctly when empty") + void getPlantListEmpty() { + List testList; + try { + testList = testDatabase.getPlantList(HardinessZone.ZONE_1A); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (HardinessZoneNotSetException e) { + throw new RuntimeException(e); + } + Assertions.assertEquals(0, testList.size()); + + + } + @Test @DisplayName("Check whether single access works.") - void getPlantById() { + void getPlantByIdAndZone() { Optional testPlant; try { - testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A,1); - } catch (IOException | HardinessZoneNotSetException e) { + testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (HardinessZoneNotSetException e) { + throw new RuntimeException(e); + } + Assertions.assertTrue(testPlant.isPresent()); + Assertions.assertEquals("Early Carrot", testPlant.get().name()); + } + + @Test + @DisplayName("Check whether single access respects zone correctly.") + void getPlantByIdAndWrongZone() { + Optional testPlant; + try { + testPlant = testDatabase.getPlantById(HardinessZone.ZONE_1A, 1); + Assertions.assertFalse(testPlant.isPresent()); + testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1); + Assertions.assertTrue(testPlant.isPresent()); + + } catch (IOException e) { + throw new RuntimeException(e); + } catch (HardinessZoneNotSetException e) { throw new RuntimeException(e); } Assertions.assertTrue(testPlant.isPresent()); @@ -58,8 +97,10 @@ public class JsonPlantDatabaseTest { void getPlantByIdMustFail() { Optional testPlant; try { - testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A,99); - } catch (IOException | HardinessZoneNotSetException e) { + testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 99); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (HardinessZoneNotSetException e) { throw new RuntimeException(e); } Assertions.assertFalse(testPlant.isPresent()); @@ -68,4 +109,3 @@ public class JsonPlantDatabaseTest { } } -