DataSetMarshaller { static RoutingProblem toDomain(DataSet dataSet) { return new RoutingProblem( Optional.ofNullable(dataSet.getName()).orElse(""), Optional.ofNullable(dataSet.getVehicles()).orElse(Collections.emptyList()) .stream() .map(DataSetMarshaller::toDomain) .collect(toList()), Optional.ofNullable(dataSet.getDepot()).map(DataSetMarshaller::toDomain).orElse(null), Optional.ofNullable(dataSet.getVisits()).orElse(Collections.emptyList()) .stream() .map(DataSetMarshaller::toDomain) .collect(toList())); } DataSetMarshaller();   DataSetMarshaller(ObjectMapper mapper); RoutingProblem unmarshal(Reader reader); String marshal(RoutingProblem routingProblem);  }
@Test void should_convert_empty_data_set_correctly() { DataSet emptyDataSet = new DataSet(); RoutingProblem routingProblem = toDomain(emptyDataSet); assertThat(routingProblem.name()).isEmpty(); assertThat(routingProblem.depot()).isEmpty(); assertThat(routingProblem.vehicles()).isEmpty(); assertThat(routingProblem.visits()).isEmpty(); }