SingletonProvider implements Provider<T> { @Override public final T get() { if (obj == null) { synchronized (lock) { if (obj == null) { obj = create(); } } } return obj; }  @Override final T get();  }
@Test public void testSingletonBehavior() { StringProvider provider = new StringProvider(); Foo foo1 = provider.get(); Foo foo2 = provider.get(); Assert.assertSame(foo1, foo2); }