### Question:
Suppliers { public static <T> Lazy<T> lazySingleton( final Supplier<T> supplier ) { return new Lazy<T>() { volatile T instance; @Override public T get() { if ( isInitialised() ) { return instance; } synchronized ( this ) { if ( instance == null ) { instance = supplier.get(); } } return instance; } @Override public boolean isInitialised() { return instance != null; } }; } private  Suppliers(); static Supplier<T> singleton( final T instance ); static Lazy<T> lazySingleton( final Supplier<T> supplier ); static Supplier<T> adapted( final Supplier<V> supplier, final Function<V,T> adaptor ); static ThrowingCapturingSupplier<T,E> compose(
            final ThrowingSupplier<T,? extends E> input,
            final ThrowingPredicate<T,? extends E> predicate ); static BooleanSupplier untilTimeExpired( long duration, TimeUnit unit );  }### Answer:
@Test void lazySingletonSupplierShouldOnlyRequestInstanceWhenRequired() { Object o = new Object(); Supplier<Object> mockSupplier = mock( Supplier.class ); when( mockSupplier.get() ).thenReturn( o ); Supplier<Object> supplier = Suppliers.lazySingleton( mockSupplier ); verifyZeroInteractions( mockSupplier ); assertThat( supplier.get(), sameInstance( o ) ); assertThat( supplier.get(), sameInstance( o ) ); assertThat( supplier.get(), sameInstance( o ) ); verify( mockSupplier ).get(); verifyNoMoreInteractions( mockSupplier ); }
@Test void correctlyReportNotInitialisedSuppliers() { Suppliers.Lazy<Object> lazySingleton = Suppliers.lazySingleton( Object::new ); assertFalse( lazySingleton.isInitialised() ); }
@Test void correctlyReportInitialisedSuppliers() { Suppliers.Lazy<Object> lazySingleton = Suppliers.lazySingleton( Object::new ); lazySingleton.get(); assertTrue( lazySingleton.isInitialised() ); }