@Test void shouldThrowForInvalidFieldValue() { ProvidedClass providedClass = new ProvidedClass(""); AlphaService alphaService = AlphaService.newInstance(providedClass); GammaService gammaService = new GammaService(alphaService); Resolution<BetaManager> injection = provider.safeGet(BetaManager.class); assertThrows(InjectorReflectionException.class, () -> injection.instantiateWith(providedClass, alphaService, gammaService)); }
@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();  }