@Test public void testGetProvider() { assertThat(SpiFactory.getProvider(MockSPI.class)).isInstanceOf(MockSpiImpl.class); }
@SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); }
SpiFactory { @SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); } }
SpiFactory { @SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); }  }
SpiFactory { @SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); }  @SuppressWarnings("unchecked") static T override(final Class<T> clazz, final T object); static void removeOverride(final Class<?> clazz); @SuppressWarnings("unchecked") static T getProvider(final Class<T> clazz); }
SpiFactory { @SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); }  @SuppressWarnings("unchecked") static T override(final Class<T> clazz, final T object); static void removeOverride(final Class<?> clazz); @SuppressWarnings("unchecked") static T getProvider(final Class<T> clazz);  }