fixed Method getFilteredPlantListByString for case if SearchString is empty.

This commit is contained in:
schrom01 2022-10-30 10:38:46 +01:00
parent 4e794a8a93
commit 98ff259d95
2 changed files with 5 additions and 1 deletions

View File

@ -110,7 +110,9 @@ public class PlantListModel {
* @throws IOException If the database cannot be accessed
*/
public List<Plant> 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) {

View File

@ -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