LazyInit implements Supplier<T> { public static <T> LazyInit<T> of(Callable<? extends T> initializer) { return new LazyInit<>(initializer); } LazyInit(Callable<? extends T> initializer); static LazyInit<T> of(Callable<? extends T> initializer); @Override T get(); boolean hasValue(); void clear();  }
@Test public void testNullInitializer() { assertThrows(NullPointerException.class, () -> LazyInit.of(null), "Null initializer should throw"); }
@Test public void testInitializerThrows() { String message = "Exception message"; LazyInit<Object> throwing = LazyInit.of(() -> { throw new UnsupportedOperationException(message); }); RuntimeException thrown = assertThrows(RuntimeException.class, throwing::get); Throwable cause = thrown.getCause(); assertNotNull(cause); assertAll( () -> assertEquals(UnsupportedOperationException.class, cause.getClass()), () -> assertEquals(message, cause.getMessage()) ); }