ScopedProvider implements Provider<T> { public static <T> Provider<T> create(Factory<T> factory) { if (factory == null) { throw new NullPointerException(); } return new ScopedProvider<T>(factory); } private  ScopedProvider(Factory<T> factory); @SuppressWarnings("unchecked") // cast only happens when result comes from the factory @Override T get(); static Provider<T> create(Factory<T> factory);  }
@Test public void create_nullPointerException() { try { ScopedProvider.create(null); fail(); } catch (NullPointerException expected) { } }