RequestDetailsMapper implements Function<RequestInfoInstance, RequestDetails> { @Override public RequestDetails apply(final RequestInfoInstance requestInfoInstance) { final Optional<RequestInfoInstance> request = ofNullable(requestInfoInstance); if (request.isPresent() == false) { return null; } final RequestSummary summary = request.map(new RequestSummaryMapper()).get(); final List<ErrorSummary> errors = request.map(r -> r.getErrors()).map(e -> e.getItems()).orElse(emptyList()).stream().map(new ErrorSummaryMapper()).collect(toList()); final List<RequestParameterSummary> params = request.map(r -> r.getData()).orElse(emptyMap()).entrySet().stream() .map(e -> new RequestParameterSummary(e.getKey(), String.valueOf(e.getValue()))) .collect(toList()); return new RequestDetails(summary, errors, params); }  @Override RequestDetails apply(final RequestInfoInstance requestInfoInstance);  }
@Test public void testRequestDetailsMapper() { final RequestInfoInstance ri = newRequestInfoInstance(); final RequestDetails rd = new RequestDetailsMapper().apply(ri); assertRequestDetails(ri, rd); }
@Test public void testRequestDetailsMapperNull() { assertNull(new RequestDetailsMapper().apply(null)); }