void instantiateWithInjectableValues(@Nonnull Object testClassInstance) { if (isAvailableDuringSetup() && getFieldValue(testedField, testClassInstance) != null) { return; } injectionState.setTestedField(testedField); Object testedObject = getTestedObjectFromFieldInTestClassIfApplicable(testClassInstance); Class<?> testedClass = testedField.getType(); if (testedObject == null && createAutomatically) { if (reusePreviouslyCreatedInstance(testClassInstance, testedClass)) { return; } if (testedObjectCreation != null) { testedObject = testedObjectCreation.create(); setFieldValue(testedField, testClassInstance, testedObject); injectionState.saveTestedObject(testedClass, testedObject); } } else if (testedObject != null) { String dependencyKey = InjectionPoint.dependencyKey(testedClass, testedField.getName()); injectionState.saveTestedObject(dependencyKey, testedObject); testedClass = testedObject.getClass(); } if (testedObject != null) { performFieldInjection(testedClass, testedObject); executeInitializationMethodsIfAny(testedClass, testedObject); } }
TestedField( @Nonnull InjectionState injectionState, @Nonnull Field field, @Nonnull Tested metadata) { this.injectionState = injectionState; testedField = field; this.metadata = metadata; fullInjection = metadata.fullyInitialized() ? new FullInjection(injectionState) : null; Class<?> fieldType = field.getType(); if (fieldType.isInterface()) { testedObjectCreation = null; } else { testedObjectCreation = new TestedObjectCreation(injectionState, fullInjection, field); injectionState.lifecycleMethods.findLifecycleMethods(fieldType); } }