@Test void shouldThrowUponInstantiationError() { AlphaService alphaService = AlphaService.newInstance(new ProvidedClass("")); Resolution<InvalidClass> injection = provider.safeGet(InvalidClass.class); assertThrows(InjectorException.class, () -> injection.instantiateWith(alphaService, 5)); }
@Override public T instantiateWith(Object... values) { InjectorUtils.checkArgument(values.length == constructor.getParameterTypes().length + fields.size(), "Number of values does not correspond to the expected number"); final int constructorParams = constructor.getParameterTypes().length; final List<Object> constructorValues = Arrays.asList(values).subList(0, constructorParams); T instance = ReflectionUtils.newInstance(constructor, constructorValues.toArray()); for (int i = 0; i < fields.size(); ++i) { ReflectionUtils.setField(fields.get(i), instance, values[i + constructorParams]); } return instance; }
StandardInjection implements Resolution<T> { @Override public T instantiateWith(Object... values) { InjectorUtils.checkArgument(values.length == constructor.getParameterTypes().length + fields.size(), "Number of values does not correspond to the expected number"); final int constructorParams = constructor.getParameterTypes().length; final List<Object> constructorValues = Arrays.asList(values).subList(0, constructorParams); T instance = ReflectionUtils.newInstance(constructor, constructorValues.toArray()); for (int i = 0; i < fields.size(); ++i) { ReflectionUtils.setField(fields.get(i), instance, values[i + constructorParams]); } return instance; } }
StandardInjection implements Resolution<T> { @Override public T instantiateWith(Object... values) { InjectorUtils.checkArgument(values.length == constructor.getParameterTypes().length + fields.size(), "Number of values does not correspond to the expected number"); final int constructorParams = constructor.getParameterTypes().length; final List<Object> constructorValues = Arrays.asList(values).subList(0, constructorParams); T instance = ReflectionUtils.newInstance(constructor, constructorValues.toArray()); for (int i = 0; i < fields.size(); ++i) { ReflectionUtils.setField(fields.get(i), instance, values[i + constructorParams]); } return instance; } StandardInjection(Constructor<T> constructor, List<Field> fields); }
StandardInjection implements Resolution<T> { @Override public T instantiateWith(Object... values) { InjectorUtils.checkArgument(values.length == constructor.getParameterTypes().length + fields.size(), "Number of values does not correspond to the expected number"); final int constructorParams = constructor.getParameterTypes().length; final List<Object> constructorValues = Arrays.asList(values).subList(0, constructorParams); T instance = ReflectionUtils.newInstance(constructor, constructorValues.toArray()); for (int i = 0; i < fields.size(); ++i) { ReflectionUtils.setField(fields.get(i), instance, values[i + constructorParams]); } return instance; } StandardInjection(Constructor<T> constructor, List<Field> fields); @Override List<ObjectIdentifier> getDependencies(); @Override T instantiateWith(Object... values); @Override boolean isInstantiation(); }
StandardInjection implements Resolution<T> { @Override public T instantiateWith(Object... values) { InjectorUtils.checkArgument(values.length == constructor.getParameterTypes().length + fields.size(), "Number of values does not correspond to the expected number"); final int constructorParams = constructor.getParameterTypes().length; final List<Object> constructorValues = Arrays.asList(values).subList(0, constructorParams); T instance = ReflectionUtils.newInstance(constructor, constructorValues.toArray()); for (int i = 0; i < fields.size(); ++i) { ReflectionUtils.setField(fields.get(i), instance, values[i + constructorParams]); } return instance; } StandardInjection(Constructor<T> constructor, List<Field> fields); @Override List<ObjectIdentifier> getDependencies(); @Override T instantiateWith(Object... values); @Override boolean isInstantiation();  }