WeakValue extends WeakReference<T> implements Weak<T> { @Override public T orThrow() { T value = get(); if (value != null) { return value; } else { throw new NoSuchElementException("Value was reclaimed"); } } WeakValue(T referent); @Override Weak<T> filter(Predicate<? super T> predicate); @Override Weak<U> flatMap(Function<? super T, ? extends Weak<? extends U>> mapper); @Override Weak<U> map(Function<? super T, ? extends U> mapper); @Override Weak<T> orElse(Supplier<? extends Weak<? extends T>> other); @Override T or(T other); @Override T or(Supplier<T> other); @Override T orThrow(); @Override T orThrow(Supplier<? extends E> exception); @Override void ifPresent(Consumer<? super T> action); @Override void ifPresent(Consumer<? super T> action, Runnable otherwise); @Override boolean isPresent(); @Override Stream<T> stream(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }
@Test void orThrow() { assertEquals(VALUE, WEAK.orThrow()); }
@Test void orThrow_exception() { assertEquals("Value was reclaimed", assertThrows(NoSuchElementException.class, () -> Weak.empty().orThrow()).getMessage()); }
@Test void orThrow_supplier() { assertEquals(VALUE, WEAK.orThrow(RuntimeException::new)); }
@Test void orThrow_supplier_exception() { assertThrows(RuntimeException.class , () -> Weak.empty().orThrow(RuntimeException::new)); }