Class InstanceField
java.lang.Object
org.mockito.internal.util.reflection.InstanceField
Represents an accessible instance field.
Contains the instance reference on which the field can be read adn write.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
Aannotation
(Class<A> annotationClass) Returns the annotation instance for the given annotation type.boolean
int
hashCode()
boolean
isAnnotatedBy
(Class<? extends Annotation> annotationClass) Check if the field is annotated by the given annotation.boolean
isNull()
Check that the field is not null.jdkField()
Returns the JDKField
instance.name()
Returns the name of the field.read()
Safely read the field.void
Set the given value to the field of this instance.
-
Constructor Details
-
InstanceField
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 Details
-
read
Safely read the field.- Returns:
- the field value.
- See Also:
-
set
Set the given value to the field of this instance.- Parameters:
value
- The value that should be written to the field.- See Also:
-
isNull
public boolean isNull()Check that the field is not null.- Returns:
true
ifnull
, elsefalse
.
-
isAnnotatedBy
Check if the field is annotated by the given annotation.- Parameters:
annotationClass
- The annotation type to check.- Returns:
true
if the field is annotated by this annotation, elsefalse
.
-
annotation
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
Returns the JDKField
instance.- Returns:
- The actual
Field
instance.
-
name
Returns the name of the field.- Returns:
- Name of the field.
-
equals
-
hashCode
public int hashCode()
-