### Question:
PostmanService { Optional<Instant> getStartDateTime(Response response) { if (response == null) { return Optional.empty(); } return Arrays.stream(response.getHeader()) .filter(header -> "Date".equalsIgnoreCase(header.getKey())) .findFirst() .map(KeyValue::getValue) .map(value -> { try { return ZonedDateTime.parse(value, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant(); } catch (DateTimeParseException e) { log.error("Cannot parse date from response header in Newman report: {}", value, e); return null; } }); }  void parse(JsonParser parser, NewmanParsingResult result); List<ExecutedScenario> postProcess(Run run, NewmanParsingResult result, String newmanReportPath, AtomicInteger requestPosition); void deleteTempFiles(NewmanParsingResult newmanParsingResult); static final String FOLDER_DELIMITER; }### Answer:
@Test public void testGetStartDateTime_should_return_the_parsed_date_for_utc() { final KeyValue[] headers = { new KeyValue("Some", "value"), new KeyValue("Date", "Wed, 21 Oct 2015 07:28:01 GMT"), new KeyValue("Other", "value") }; Calendar expected = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expected.set(2015, Calendar.OCTOBER, 21, 7, 28, 1); expected.set(Calendar.MILLISECOND, 0); final Optional<Instant> startDateTime = cut.getStartDateTime(new Response().withHeader(headers)); assertThat(startDateTime.orElse(null)).isEqualTo(expected.toInstant()); }
@Test public void testGetStartDateTime_should_return_the_parsed_date_for_other_time_zone() { final KeyValue[] headers = { new KeyValue("Some", "value"), new KeyValue("Date", "Wed, 21 Oct 2015 07:28:01 -0500"), new KeyValue("Other", "value") }; Calendar expected = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expected.set(2015, Calendar.OCTOBER, 21, 7 + 5, 28, 1); expected.set(Calendar.MILLISECOND, 0); final Optional<Instant> startDateTime = cut.getStartDateTime(new Response().withHeader(headers)); assertThat(startDateTime.orElse(null)).isEqualTo(expected.toInstant()); }
@Test public void testGetStartDateTime_should_return_empty_if_null_response() { final Response response = null; final Optional<Instant> startDateTime = cut.getStartDateTime(response); assertThat(startDateTime).isEmpty(); }
@Test public void testGetStartDateTime_should_return_empty_if_none() { final KeyValue[] headers = { new KeyValue("No", "date") }; final Optional<Instant> startDateTime = cut.getStartDateTime(new Response().withHeader(headers)); assertThat(startDateTime).isEmpty(); }
@Test public void testGetStartDateTime_should_return_empty_if_not_able_to_parse() { final KeyValue[] headers = { new KeyValue("Date", "not able to parse") }; final Optional<Instant> startDateTime = cut.getStartDateTime(new Response().withHeader(headers)); assertThat(startDateTime).isEmpty(); }