InstantToLongConverter implements Converter<Instant, Long> { @Override public Long convert(Instant instant) { if (instant == null) { return null; } if (instant.equals(Instant.EPOCH) || instant.isBefore(Instant.EPOCH)) { return 0L; } if (instant.isAfter(LONG_MAX_INSTANT)) { return Long.MAX_VALUE; } return Math.addExact(Math.multiplyExact(instant.getEpochSecond(), NANOS_PER_SECOND), instant.getNano()); }  @Override Long convert(Instant instant); static final InstantToLongConverter INSTANCE; static final Instant LONG_MAX_INSTANT; }
@Test void convertNull() { Long result = converter.convert(null); assertNull(result); }
@Test void convertLongMin() { Long result = converter.convert(Instant.MIN); assertEquals(0, result); }
@Test void convertLongMax() { Long result = converter.convert(Instant.MAX); assertEquals(Long.MAX_VALUE, result); }