Class InstanceField
- java.lang.Object
-
- org.mockito.internal.util.reflection.InstanceField
-
public class InstanceField extends java.lang.ObjectRepresents an accessible instance field. Contains the instance reference on which the field can be read adn write.
-
-
Constructor Summary
Constructors Constructor Description InstanceField(java.lang.reflect.Field field, java.lang.Object instance)Create a new InstanceField.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends java.lang.annotation.Annotation>
Aannotation(java.lang.Class<A> annotationClass)Returns the annotation instance for the given annotation type.booleanequals(java.lang.Object o)inthashCode()booleanisAnnotatedBy(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Check if the field is annotated by the given annotation.booleanisNull()Check that the field is not null.java.lang.reflect.FieldjdkField()Returns the JDKFieldinstance.java.lang.Stringname()Returns the name of the field.java.lang.Objectread()Safely read the field.voidset(java.lang.Object value)Set the given value to the field of this instance.
-
-
-
Constructor Detail
-
InstanceField
public InstanceField(java.lang.reflect.Field field, java.lang.Object instance)Create a new InstanceField.- Parameters:
field- The field that should be accessed, note that no checks are performed to ensure the field belong to this instance class.instance- The instance from which the field shall be accessed.
-
-
Method Detail
-
read
public java.lang.Object read()
Safely read the field.- Returns:
- the field value.
- See Also:
FieldReader
-
set
public void set(java.lang.Object value)
Set the given value to the field of this instance.- Parameters:
value- The value that should be written to the field.- See Also:
FieldSetter
-
isNull
public boolean isNull()
Check that the field is not null.- Returns:
trueifnull, elsefalse.
-
isAnnotatedBy
public boolean isAnnotatedBy(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Check if the field is annotated by the given annotation.- Parameters:
annotationClass- The annotation type to check.- Returns:
trueif the field is annotated by this annotation, elsefalse.
-
annotation
public <A extends java.lang.annotation.Annotation> A annotation(java.lang.Class<A> annotationClass)
Returns the annotation instance for the given annotation type.- Type Parameters:
A- Type of the annotation.- Parameters:
annotationClass- Tha annotation type to retrieve.- Returns:
- The annotation instance.
-
jdkField
public java.lang.reflect.Field jdkField()
Returns the JDKFieldinstance.- Returns:
- The actual
Fieldinstance.
-
name
public java.lang.String name()
Returns the name of the field.- Returns:
- Name of the field.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-