@Test void shouldInstantiate() { GammaService gammaService = new GammaService( AlphaService.newInstance(new ProvidedClass(""))); Resolution<ClassWithAnnotations> injection = provider.safeGet(ClassWithAnnotations.class); ClassWithAnnotations instance = injection.instantiateWith(-112, gammaService, 19L); assertThat(instance, not(nullValue())); assertThat(instance.getSize(), equalTo(-112)); assertThat(instance.getGammaService(), equalTo(gammaService)); assertThat(instance.getDuration(), equalTo(19L)); }
@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();  }