Java8RandomShortApi { public static Instant instant() { return new RandomDate().instant(); }  static Instant instant(); static List<Instant> instants(int n); static LocalDateTime localDateTime(); static List<LocalDateTime> localDateTimes(int nOfTimes); static ZonedDateTime zonedDateTime(); static List<ZonedDateTime> zonedDateTimes(int nOfTimes); static OffsetDateTime offsetDateTime(); static List<OffsetDateTime> offsetDateTimes(int nOfTimes); static LocalDate localDate(); static List<LocalDate> localDates(int nOfTimes);  }
@Test void defaultPeriodIsBetweenMinAndMaxLongs() { Instant min = Instant.ofEpochMilli(Long.MIN_VALUE + 808); Instant max = Instant.ofEpochMilli(Long.MAX_VALUE); assertThat(instant(), allOf(greaterThan(min), lessThan(max))); }
@Test void returnsSameValueIfFromAndToAreEqual() { ZonedDateTime dateTime = ZonedDateTime.now(); assertThat(between(dateTime, dateTime).instant(), equalTo(dateTime.toInstant())); }
@Test void returnsNanosUpToMaxIfMinBoundaryIsSmaller() { ZonedDateTime to = ZonedDateTime.now(); ZonedDateTime from = to.minusSeconds(1).plusNanos(upTo(999_999_999L).Long()); assertThat(between(from.plusNanos(1), to).instant(), greaterThanOrEqualTo(from.toInstant())); assertThat(between(from.plusNanos(1), to).instant(), lessThanOrEqualTo(to.toInstant())); }
@Test void plusMinus100YearsReturnsDateWithinThisPeriod() { ZoneOffset offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()); ZonedDateTime from = ZonedDateTime.now(offset).minusYears(100); assertThat(plusMinus100Years().instant(), greaterThan(from.toInstant())); assertThat(plusMinus100Years().instant(), lessThan(ZonedDateTime.now(offset).plusYears(100).toInstant())); }