### Question:
Expiring { public T computeIfAbsent (Callable<T> callable, long durationInMillis) { return computeIfAbsent(callable, Duration.ofMillis(durationInMillis)); } Expiring(T object, Instant expiryTime);  Expiring(T object, long millis);  Expiring(T object, Duration objectDuration); T value(); @Override String toString(); void expire(); T computeIfAbsent(Callable<T> callable, long durationInMillis); T computeIfAbsent(Callable<T> callable, Duration objectDuration);  }### Answer:
@Test @SuppressWarnings("unchecked") public void computeIfAbsent () throws Exception { Object object2 = new Object(); Callable<Object> callable = Mockito.spy(Callable.class); doReturn(object2).when(callable).call(); expiringObject = new Expiring<>(object, Duration.ZERO); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> expiringObject.isExpired()); assertEquals(object2, expiringObject.computeIfAbsent(callable, Duration.ZERO)); verify(callable, atLeastOnce()).call(); }
@Test @SuppressWarnings("unchecked") public void computeIfAbsentNotAbsent () throws Exception { Callable<Object> callable = Mockito.spy(Callable.class); assertEquals(object, expiringObject.computeIfAbsent(callable, Duration.ZERO)); verify(callable, never()).call(); }
@Test public void testConstructor () { final Expiring<Object> t = new Expiring<>(object, Instant.now()); await().atLeast(100, TimeUnit.MILLISECONDS).until(t::isExpired); assertNull(t.computeIfAbsent(() -> { throw new Exception(); }, -1000L)); final Expiring<Object> t2 = new Expiring<>(object, -1000L); await().atLeast(100, TimeUnit.MILLISECONDS).until(t2::isExpired); assertNull(t2.computeIfAbsent(() -> { throw new Exception(); }, -1000L)); }