### Question:
PolicyQueryResultAssembler { static FindPolicyQueryResult constructResult(List<PolicyView> policies) { return new FindPolicyQueryResult( policies.stream() .map(PolicyListItemDtoAssembler::map) .sorted(Comparator.comparing(PolicyListItemDto::getDateFrom, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()) ); }    }### Answer:
@Test public void shouldSortResultsByDescendingStartDate() { PolicyQueryResultAssembler assembler = new PolicyQueryResultAssembler(); List<PolicyView> policies = new ArrayList<>(Arrays.asList( new PolicyView("1", LocalDate.of(2015,11,1), LocalDate.of(2016,10,30), "Tom Hanks"), new PolicyView("2", LocalDate.of(2015,11,3), LocalDate.of(2016,10,30), "Alanis Morissette"), new PolicyView("3", LocalDate.of(2015,11,2), LocalDate.of(2016,10,30), "Andy Warhol") )); FindPolicyQueryResult result = assembler.constructResult(policies); Assertions.assertTrue(result.getPolicies().get(0).getNumber().equalsIgnoreCase("2")); Assertions.assertTrue(result.getPolicies().get(1).getNumber().equalsIgnoreCase("3")); Assertions.assertTrue(result.getPolicies().get(2).getNumber().equalsIgnoreCase("1")); }
@Test public void shouldHandleNullStartDatesAndPlaceThemAtTheEnd() { PolicyQueryResultAssembler assembler = new PolicyQueryResultAssembler(); List<PolicyView> policies = new ArrayList<>(Arrays.asList( new PolicyView("1", LocalDate.of(2015,11,1), LocalDate.of(2016,10,30), "Tom Hanks"), new PolicyView("2", null, null, "Alanis Morissette"), new PolicyView("3", LocalDate.of(2015,11,2), LocalDate.of(2016,10,30), "Andy Warhol") )); FindPolicyQueryResult result = assembler.constructResult(policies); Assertions.assertTrue(result.getPolicies().get(2).getNumber().equalsIgnoreCase("2")); }