From 98ff259d95910564117f6abdc9f36d5bafe00fe8 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 30 Oct 2022 10:38:46 +0100 Subject: [PATCH] fixed Method getFilteredPlantListByString for case if SearchString is empty. --- .../ch/zhaw/gartenverwaltung/plantList/PlantListModel.java | 4 +++- .../zhaw/gartenverwaltung/plantList/PlantListModelTest.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java index 7039476..8e8a1b8 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java @@ -110,7 +110,9 @@ public class PlantListModel { * @throws IOException If the database cannot be accessed */ public List getFilteredPlantListByString(HardinessZone zone, String searchString) throws HardinessZoneNotSetException, IOException { - if(searchString.charAt(0) == '#') { + if(searchString.length() == 0){ + return getPlantList(zone); + } else if(searchString.charAt(0) == '#') { try { return getFilteredPlantListById(zone, Long.parseLong(searchString.substring(1))); } catch (NumberFormatException e) { diff --git a/src/test/java/ch/zhaw/gartenverwaltung/plantList/PlantListModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/plantList/PlantListModelTest.java index f341ba9..607608c 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/plantList/PlantListModelTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/plantList/PlantListModelTest.java @@ -170,6 +170,8 @@ class PlantListModelTest { assertEquals(examplePlantList.get(1), plantListResult.get(0)); plantListResult = model.getFilteredPlantListByString(HardinessZone.ZONE_8A, "apple"); assertEquals(0, plantListResult.size()); + plantListResult = model.getFilteredPlantListByString(HardinessZone.ZONE_8A, ""); + assertEquals(3, plantListResult.size()); } @Test