Package org.awaitility.reflect
Class WhiteboxImpl
java.lang.Object
org.awaitility.reflect.WhiteboxImpl
Various utilities for accessing internals of a class. Basically a simplified
reflection utility. Copied with permission from PowerMock project.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidAssert object in get internal state is not null.private static FieldfindFieldInHierarchy(Object object, String fieldName) Find field in hierarchy.private static FieldfindFieldInHierarchy(Object object, FieldMatcherStrategy strategy) Find field in hierarchy.private static FieldfindSingleFieldUsingStrategy(FieldMatcherStrategy strategy, Object object, boolean checkHierarchy, Class<?> startClass) Find single field using strategy.static <T> TgetByNameAndType(Object object, String fieldName, Class<T> expectedFieldType) getByNameAndType.static FieldgetFieldAnnotatedWith(Object object, Class<? extends Annotation> annotationType) Get field annotated with a particular annotation.static <T> TgetInternalState(Object object, Class<T> fieldType) Get the value of a field using reflection.static <T> TgetInternalState(Object object, String fieldName) Get the value of a field using reflection.static Class<?>Gets the type.private static booleanhasFieldProperModifier(Object object, Field field) Checks for field proper modifier.static booleanChecks if is class.static voidthrowExceptionIfFieldWasNotFound(Class<?> type, String fieldName, Field field) Throw exception if field was not found.
-
Constructor Details
-
WhiteboxImpl
public WhiteboxImpl()
-
-
Method Details
-
getInternalState
Get the value of a field using reflection. This method will iterate through the entire class hierarchy and return the value of the first field named fieldName. If you want to get a specific field value at specific place in the class hierarchy please refer to- Type Parameters:
T- the generic type- Parameters:
object- the object to modifyfieldName- the name of the field- Returns:
- the internal state.
-
findFieldInHierarchy
Find field in hierarchy.- Parameters:
object- the objectfieldName- the field name- Returns:
- the field
-
findFieldInHierarchy
Find field in hierarchy.- Parameters:
object- the objectstrategy- the strategy- Returns:
- the field
-
assertObjectInGetInternalStateIsNotNull
Assert object in get internal state is not null.- Parameters:
object- the object
-
findSingleFieldUsingStrategy
private static Field findSingleFieldUsingStrategy(FieldMatcherStrategy strategy, Object object, boolean checkHierarchy, Class<?> startClass) Find single field using strategy.- Parameters:
strategy- the strategyobject- the objectcheckHierarchy- the check hierarchystartClass- the start class- Returns:
- the field
-
hasFieldProperModifier
Checks for field proper modifier.- Parameters:
object- the objectfield- the field- Returns:
- true, if successful
-
getInternalState
Get the value of a field using reflection. This method will traverse the super class hierarchy until the first field of type fieldType is found. The value of this field will be returned.- Type Parameters:
T- the generic type- Parameters:
object- the object to modifyfieldType- the type of the field- Returns:
- the internal state
-
throwExceptionIfFieldWasNotFound
Throw exception if field was not found.- Parameters:
type- the typefieldName- the field namefield- the field
-
getType
Gets the type.- Parameters:
object- the object- Returns:
- The type of the of an object.
-
getFieldAnnotatedWith
public static Field getFieldAnnotatedWith(Object object, Class<? extends Annotation> annotationType) Get field annotated with a particular annotation. This method traverses the class hierarchy when checking for the annotation.- Parameters:
object- The object to look for annotations. Note that if're you're passing an object only instance fields are checked, passing a class will only check static fields.annotationType- The annotation types to look for- Returns:
- A set of all fields containing the particular annotation(s).
- Since:
- 1.3
-
isClass
Checks if is class.- Parameters:
argument- the argument- Returns:
- a boolean.
-
getByNameAndType
getByNameAndType.
-