com.jayway.awaitility.reflect
Class WhiteboxImpl

java.lang.Object
  extended by com.jayway.awaitility.reflect.WhiteboxImpl

public class WhiteboxImpl
extends Object

Various utilities for accessing internals of a class. Basically a simplified reflection utility. Copied with permission from PowerMock project.


Constructor Summary
WhiteboxImpl()
           
 
Method Summary
static
<T> T
getByNameAndType(Object object, String fieldName, Class<T> expectedFieldType)
           
static Field getFieldAnnotatedWith(Object object, Class<? extends Annotation> annotationType)
          Get field annotated with a particular annotation.
static
<T> T
getInternalState(Object object, Class<T> fieldType)
          Get the value of a field using reflection.
static
<T> T
getInternalState(Object object, String fieldName)
          Get the value of a field using reflection.
static Class<?> getType(Object object)
          Gets the type.
static boolean isClass(Object argument)
          Checks if is class.
static void throwExceptionIfFieldWasNotFound(Class<?> type, String fieldName, Field field)
          Throw exception if field was not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WhiteboxImpl

public WhiteboxImpl()
Method Detail

getInternalState

public static <T> T getInternalState(Object object,
                                     String fieldName)
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 modify
fieldName - the name of the field
Returns:
the internal state #getInternalState(Object, String, Class).

getInternalState

public static <T> T getInternalState(Object object,
                                     Class<T> fieldType)
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 modify
fieldType - the type of the field
Returns:
the internal state

throwExceptionIfFieldWasNotFound

public static void throwExceptionIfFieldWasNotFound(Class<?> type,
                                                    String fieldName,
                                                    Field field)
Throw exception if field was not found.

Parameters:
type - the type
fieldName - the field name
field - the field

getType

public static Class<?> getType(Object object)
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.
annotationTypes - The annotation types to look for
Returns:
A set of all fields containing the particular annotation(s).
Since:
1.3

isClass

public static boolean isClass(Object argument)
Checks if is class.

Parameters:
argument - the argument
Returns:
true, if is class

getByNameAndType

public static <T> T getByNameAndType(Object object,
                                     String fieldName,
                                     Class<T> expectedFieldType)


Copyright © 2010-2012. All Rights Reserved.