InjectorBuilderImpl implements InjectorBuilder { static void throwInjectorException(DependencyGraph graph, Execution<Object> exec, Exception ex) { INTERNAL_LOGGER.error("Exception thrown by method invoked by Injector:"); if (ex.getCause() != null) { INTERNAL_LOGGER.error("Exception: " + ex.getCause().getClass().getSimpleName()); } INTERNAL_LOGGER.error("Class: " + exec.getType().getName()); INTERNAL_LOGGER.error(" @ExecuteBefore(" + exec.getState().name() + ")"); if (exec instanceof ReflectionExecutionImpl) { final Method method = ((ReflectionExecutionImpl<?>) exec).getMethod(); INTERNAL_LOGGER.error(format(" %s %s %s%s", Modifier.toString(method.getModifiers()), method.getReturnType().getSimpleName(), method.getName(), method.getParameterCount() == 0 ? "()" : "(")); if (method.getParameterCount() > 0) { Stream.of(method.getParameters()) .map(param -> formatParameter(graph, param)) .forEachOrdered(INTERNAL_LOGGER::error); INTERNAL_LOGGER.error(" );"); } } throw new InjectorException(ex); } InjectorBuilderImpl();   InjectorBuilderImpl(ClassLoader classLoader);   InjectorBuilderImpl(Set<Class<?>> injectables); private  InjectorBuilderImpl(ClassLoader classLoader, Set<Class<?>> injectables);   InjectorBuilderImpl(final InjectorBuilder toCopy); @Override InjectorBuilder withComponent(Class<?> injectableType); @Override InjectorBuilder withComponent(Class<T> injectableType, Supplier<T> instanceSupplier); @Override InjectorBuilder withBundle(Class<? extends InjectBundle> bundleClass); @Override InjectorBuilder withInjectorProxy(InjectorProxy injectorProxy); @Override InjectorBuilder withConfigFileLocation(Path configFile); @Override InjectorBuilder withParam(String name, String value); @Override InjectorBuilder before(ExecutionBuilder<T> executionBuilder); @Override Injector build(); @Override InjectorProxy proxyFor(Class<?> clazz); static final Logger INTERNAL_LOGGER; }
@Test void throwInjectorException() { try { final RuntimeException runtimeException = new RuntimeException("AnyReason"); final InjectorProxy injectorProxy = new MyInjectorProxy(); final DependencyGraph dependencyGraph = DependencyGraph.create(Stream.of(Bar.class, BarConsumerThrows.class), c -> injectorProxy); dependencyGraph.getOrCreate(Bar.class); final DependencyNode n = dependencyGraph.getOrCreate(BarConsumerThrows.class); final Execution ex = n.getExecutions().iterator().next(); InjectorBuilderImpl.throwInjectorException(dependencyGraph, ex, runtimeException); } catch (InjectorException e) { final String msg = e.getMessage(); assertTrue(msg.contains("AnyReason")); } }