@Test public void create_throwsErrorOnMisconfiguration() throws Exception { class PrivateClass {} try { ServiceProvidersTestAbstractProvider ignored = ServiceProviders.create( ServiceProvidersTestAbstractProvider.class, PrivateClass.class); fail("Expected exception"); } catch (ServiceConfigurationError expected) { assertTrue("Expected ClassCastException cause: " + expected.getCause(), expected.getCause() instanceof ClassCastException); } }
@VisibleForTesting static <T> T create(Class<T> klass, Class<?> rawClass) { try { return rawClass.asSubclass(klass).getConstructor().newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError( String.format("Provider %s could not be instantiated %s", rawClass.getName(), t), t); } }
ServiceProviders { @VisibleForTesting static <T> T create(Class<T> klass, Class<?> rawClass) { try { return rawClass.asSubclass(klass).getConstructor().newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError( String.format("Provider %s could not be instantiated %s", rawClass.getName(), t), t); } } }
ServiceProviders { @VisibleForTesting static <T> T create(Class<T> klass, Class<?> rawClass) { try { return rawClass.asSubclass(klass).getConstructor().newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError( String.format("Provider %s could not be instantiated %s", rawClass.getName(), t), t); } } private  ServiceProviders(); }
ServiceProviders { @VisibleForTesting static <T> T create(Class<T> klass, Class<?> rawClass) { try { return rawClass.asSubclass(klass).getConstructor().newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError( String.format("Provider %s could not be instantiated %s", rawClass.getName(), t), t); } } private  ServiceProviders(); static T load(
      Class<T> klass,
      Iterable<Class<?>> hardcoded,
      ClassLoader cl,
      PriorityAccessor<T> priorityAccessor); static List<T> loadAll(
      Class<T> klass,
      Iterable<Class<?>> hardcoded,
      ClassLoader cl,
      final PriorityAccessor<T> priorityAccessor); @VisibleForTesting static Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl); }
ServiceProviders { @VisibleForTesting static <T> T create(Class<T> klass, Class<?> rawClass) { try { return rawClass.asSubclass(klass).getConstructor().newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError( String.format("Provider %s could not be instantiated %s", rawClass.getName(), t), t); } } private  ServiceProviders(); static T load(
      Class<T> klass,
      Iterable<Class<?>> hardcoded,
      ClassLoader cl,
      PriorityAccessor<T> priorityAccessor); static List<T> loadAll(
      Class<T> klass,
      Iterable<Class<?>> hardcoded,
      ClassLoader cl,
      final PriorityAccessor<T> priorityAccessor); @VisibleForTesting static Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl);  }