@Test void shouldForwardExceptionFromProviderHandler() throws Exception { Handler handler = mock(Handler.class); doThrow(IllegalStateException.class).when(handler).onProvider(any(Class.class), any(Provider.class)); config.getHandlers().add(handler); try { injector.registerProvider(Delta.class, new Delta1Provider()); fail("Expected exception"); } catch (InjectorException e) { assertThat(e.getMessage(), containsString("An error occurred")); assertThat(e.getCause(), instanceOf(IllegalStateException.class)); } }
@Override public <T> void registerProvider(Class<T> clazz, Provider<? extends T> provider) { checkNotNull(clazz, "Class may not be null"); checkNotNull(provider, "Provider may not be null"); try { for (Handler handler : config.getHandlers()) { handler.onProvider(clazz, provider); } } catch (Exception e) { rethrowException(e); } }
InjectorImpl implements Injector { @Override public <T> void registerProvider(Class<T> clazz, Provider<? extends T> provider) { checkNotNull(clazz, "Class may not be null"); checkNotNull(provider, "Provider may not be null"); try { for (Handler handler : config.getHandlers()) { handler.onProvider(clazz, provider); } } catch (Exception e) { rethrowException(e); } } }
InjectorImpl implements Injector { @Override public <T> void registerProvider(Class<T> clazz, Provider<? extends T> provider) { checkNotNull(clazz, "Class may not be null"); checkNotNull(provider, "Provider may not be null"); try { for (Handler handler : config.getHandlers()) { handler.onProvider(clazz, provider); } } catch (Exception e) { rethrowException(e); } } protected  InjectorImpl(InjectorConfig config); }
InjectorImpl implements Injector { @Override public <T> void registerProvider(Class<T> clazz, Provider<? extends T> provider) { checkNotNull(clazz, "Class may not be null"); checkNotNull(provider, "Provider may not be null"); try { for (Handler handler : config.getHandlers()) { handler.onProvider(clazz, provider); } } catch (Exception e) { rethrowException(e); } } protected  InjectorImpl(InjectorConfig config); @Override void register(Class<? super T> clazz, T object); @Override void provide(Class<? extends Annotation> clazz, Object object); @Override T getSingleton(Class<T> clazz); @Override T newInstance(Class<T> clazz); @Override T getIfAvailable(Class<T> clazz); @Override T createIfHasDependencies(Class<T> clazz); @Override Collection<T> retrieveAllOfType(Class<T> clazz); @Override void registerProvider(Class<T> clazz, Provider<? extends T> provider); @Override void registerProvider(Class<T> clazz, Class<P> providerClass); InjectorConfig getConfig(); }
InjectorImpl implements Injector { @Override public <T> void registerProvider(Class<T> clazz, Provider<? extends T> provider) { checkNotNull(clazz, "Class may not be null"); checkNotNull(provider, "Provider may not be null"); try { for (Handler handler : config.getHandlers()) { handler.onProvider(clazz, provider); } } catch (Exception e) { rethrowException(e); } } protected  InjectorImpl(InjectorConfig config); @Override void register(Class<? super T> clazz, T object); @Override void provide(Class<? extends Annotation> clazz, Object object); @Override T getSingleton(Class<T> clazz); @Override T newInstance(Class<T> clazz); @Override T getIfAvailable(Class<T> clazz); @Override T createIfHasDependencies(Class<T> clazz); @Override Collection<T> retrieveAllOfType(Class<T> clazz); @Override void registerProvider(Class<T> clazz, Provider<? extends T> provider); @Override void registerProvider(Class<T> clazz, Class<P> providerClass); InjectorConfig getConfig();  }