Made tests pass for plants not in zone

This commit is contained in:
David Guler
2022-11-03 14:25:25 +01:00
parent 82eab6d5cd
commit ce93531ab8
2 changed files with 37 additions and 46 deletions
@@ -1,6 +1,5 @@
package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.GrowthPhase;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -32,6 +31,7 @@ public class JsonPlantDatabase implements PlantDatabase {
* Creating constant objects required to deserialize the {@link MonthDay} classes
*/
private final static JavaTimeModule timeModule = new JavaTimeModule();
static {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM-dd");
MonthDayDeserializer dateDeserializer = new MonthDayDeserializer(dateFormat);
@@ -82,21 +82,16 @@ public class JsonPlantDatabase implements PlantDatabase {
List<Plant> result;
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
for (Plant plant : result) {
// for discussion because of failing tests:
// for(GrowthPhase growthPhase: plant.lifecycle()) {
// if(growthPhase.zone()==zone) {
// keep in result, remove if no match
// }
// }
plant.inZone(currentZone);
}
// Turn list into a HashMap with structure id => Plant
plantMap = result.stream()
// Remove plants not in the current zone
.filter(plant -> {
plant.inZone(currentZone);
return !plant.lifecycle().isEmpty();
})
// Create Hashmap from results
.collect(HashMap::new,
(res, plant) -> res.put(plant.id(), plant),
(existing, replacement) -> { });
(existing, replacement) -> {});
}
}
}