### Question:
Instants { static Instant fromMillisOrIso8601(String time, String fieldName) { try { return Instant.ofEpochMilli(Long.parseLong(time)); } catch (NumberFormatException nfe) { try { DateTimeFormatter formatter = new DateTimeFormatterBuilder() .append(DateTimeFormatter.ISO_DATE_TIME) .optionalStart() .appendOffset("+HHmm", "+0000") .optionalEnd() .toFormatter(); return formatter.parse(time, Instant::from); } catch (DateTimeParseException dtpe) { throw new IllegalArgumentException( fieldName + " must be a number of milliseconds since epoch or an ISO 8601 formatted date"); } } }    }### Answer:
@Test public void testFromMillisOrIso8601_millis() { Instant parsed = Instants.fromMillisOrIso8601("100", "ignored"); Assert.assertEquals(Instant.ofEpochMilli(100), parsed); }
@Test public void testFromMillisOrIso8601_iso8601() { Instant parsed = Instants.fromMillisOrIso8601("2020-06-08T14:54:36+00:00", "ignored"); Assert.assertEquals(Instant.parse("2020-06-08T14:54:36Z"), parsed); }
@Test public void testFromMillisOrIso8601_failed() { try { Instants.fromMillisOrIso8601("bad-time", "testFieldName"); Assert.fail(); } catch (IllegalArgumentException iae) { Assert.assertEquals( "testFieldName must be a number of milliseconds since epoch or an ISO 8601 formatted date", iae.getMessage()); } }