Made tests pass for plants not in zone
This commit is contained in:
@@ -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) -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user