private FieldInitializer(Object fieldOwner, Field field, ConstructorInstantiator instantiator) { if(new FieldReader(fieldOwner, field).isNull()) { checkNotLocal(field); checkNotInner(field); checkNotInterface(field); checkNotEnum(field); checkNotAbstract(field); } this.fieldOwner = fieldOwner; this.field = field; this.instantiator = instantiator; }
public Object thenInject() { try { if (!new BeanPropertySetter(injectee, candidateFieldToBeInjected).set(matchingMock)) { setField(injectee, candidateFieldToBeInjected,matchingMock); } } catch (RuntimeException e) { throw cannotInjectDependency(candidateFieldToBeInjected, matchingMock, e); } return matchingMock; } };
private FieldInitializationReport acquireFieldInstance() throws IllegalAccessException { Object fieldInstance = field.get(fieldOwner); if(fieldInstance != null) { return new FieldInitializationReport(fieldInstance, false, false); } return instantiator.instantiate(); }
private FieldReader reader() { if (fieldReader == null) { fieldReader = new FieldReader(instance, field); } return fieldReader; }
public FieldReader(Object target, Field field) { this.target = target; this.field = field; changer.enableAccess(field); }
/** * Prepare initializer with the given field on the given instance. * * <p> * This constructor fail fast if the field type cannot be handled. * </p> * * @param fieldOwner Instance of the test. * @param field Field to be initialize. */ public FieldInitializer(Object fieldOwner, Field field) { this(fieldOwner, field, new NoArgConstructorInstantiator(fieldOwner, field)); }
/** * Set the given value to the field of this instance. * * @param value The value that should be written to the field. * @see FieldSetter */ public void set(Object value) { setField(instance, field,value); }
public ParameterizedReturnType(GenericMetadataSupport source, TypeVariable<?>[] typeParameters, ParameterizedType parameterizedType) { this.parameterizedType = parameterizedType; this.typeParameters = typeParameters; this.contextualActualTypeParameters = source.contextualActualTypeParameters; readTypeParameters(); readTypeVariables(); }
public TypeVariableReturnType(GenericMetadataSupport source, TypeVariable<?>[] typeParameters, TypeVariable<?> typeVariable) { this.typeParameters = typeParameters; this.typeVariable = typeVariable; this.contextualActualTypeParameters = source.contextualActualTypeParameters; readTypeParameters(); readTypeVariables(); }
public boolean isOut(InstanceField instanceField) { return instanceField.isNull(); } };
/** * @param typeParameter The TypeVariable parameter * @return A {@link BoundedType} for easy bound information, if first bound is a TypeVariable * then retrieve BoundedType of this TypeVariable */ private BoundedType boundsOf(TypeVariable<?> typeParameter) { if (typeParameter.getBounds()[0] instanceof TypeVariable) { return boundsOf((TypeVariable<?>) typeParameter.getBounds()[0]); } return new TypeVarBoundedType(typeParameter); }
/** * Gets the generic type of given matcher. For example, * for matcher class that extends BaseMatcher[Integer] this method returns Integer */ public static Class<?> genericTypeOfMatcher(Class<?> matcherClass) { //TODO SF check if we can reuse it for Mockito ArgumentMatcher return genericTypeOf(matcherClass, BaseMatcher.class, Matcher.class); } }
/** * @return Returns true if metadata knows about extra-interfaces {@link #extraInterfaces()} <strong>if relevant</strong>. */ public boolean hasRawExtraInterfaces() { return rawExtraInterfaces().length > 0; }
protected void registerTypeParametersOn(TypeVariable<?>[] typeParameters) { for (TypeVariable<?> type : typeParameters) { registerTypeVariableIfNotPresent(type); } }
@Override public Class<?> rawType() { if (rawType == null) { rawType = extractRawTypeOf(typeVariable); } return rawType; }
public NotGenericReturnTypeSupport(GenericMetadataSupport source, Type genericReturnType) { returnType = (Class<?>) genericReturnType; this.contextualActualTypeParameters = source.contextualActualTypeParameters; registerAllTypeVariables(returnType); }
public boolean isOut(InstanceField instanceField) { return instanceField.isSynthetic(); } };
@Override public String toString() { return "{firstBound=" + firstBound() + ", interfaceBounds=[]}"; }