TimestampParser { public Optional<Long> parse(String inputString) { Optional<Long> epochMilli = Optional.empty(); if (StringUtils.isNotBlank(inputString)) { epochMilli = Optional.of(new DateTimeFormatterBuilder() .append(DateTimeFormatter.ISO_INSTANT) .toFormatter() .parse(inputString, Instant::from) .toEpochMilli()); } return epochMilli; }  Optional<Long> parse(String inputString);  }
@Test public void testEmpty() { Optional<Long> millis = parser.parse(""); assertFalse(millis.isPresent()); }
@Test public void testBlank() { Optional<Long> millis = parser.parse(" "); assertFalse(millis.isPresent()); }
@Test public void testIsoInstantFormat() { Optional<Long> millis = parser.parse("2011-12-03T10:15:30Z"); assertTrue(millis.isPresent()); assertEquals(1322907330000L, millis.get().longValue()); }
@Test public void testInvalidFormat() { assertThrows(DateTimeParseException.class, () -> parser.parse("1537502400000")); }