public final class ReflectionRecipes
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.Class<?>[] |
classesFromParameters(Parameter[] parameters)
Extracts class instances from parameters.
|
static boolean |
exactMatch(java.lang.Class<?>[] classes,
java.lang.Object[] args)
Matches an array of class instances to an array of instances.
|
static boolean |
exactMatch(Parameter[] parameters,
java.lang.Object[] args)
Matches an array of parameters to an array of instances.
|
static Parameter[] |
filter(Parameter[] parameters,
java.util.Set<InjectableParameter> filters)
Omits 1.
|
static Parameter[] |
getConstructorParameters(java.lang.reflect.Constructor constructor)
Extracts constructor parameters.
|
static Parameter[] |
getMethodParameters(java.lang.reflect.Method method)
Extracts method parameters.
|
static java.lang.Object[] |
inject(Parameter[] parameters,
java.util.Set<InjectableParameter> filters,
java.lang.Object[] args,
java.lang.reflect.Constructor constructor,
ITestContext context,
ITestResult testResult)
Injects appropriate arguments.
|
static java.lang.Object[] |
inject(Parameter[] parameters,
java.util.Set<InjectableParameter> filters,
java.lang.Object[] args,
java.lang.reflect.Method injectionMethod,
ITestContext context,
ITestResult testResult)
Injects appropriate arguments.
|
static boolean |
isInstanceOf(java.lang.Class reference,
java.lang.Object object)
Checks if an instance is an instance of the given class.
|
static boolean |
isOrExtends(java.lang.Class<?> reference,
java.lang.Class<?> clazz)
Checks a class instance for being a given class or its sub-class.
|
static boolean |
isOrImplementsInterface(java.lang.Class<?> reference,
java.lang.Class<?> clazz)
Checks a class instance for being a given interface or its implementation.
|
static boolean |
lenientMatch(java.lang.Class<?>[] classes,
java.lang.Object[] args)
Matches an array of class instances to an array of instances.
|
static boolean |
lenientMatch(Parameter[] parameters,
java.lang.Object[] args)
Matches an array of parameters to an array of instances.
|
static boolean |
matchArrayEnding(java.lang.Class<?>[] classes,
java.lang.Object[] args)
Matches an array of class instances to an array of instances having last class instance an
array.
|
static boolean |
matchArrayEnding(Parameter[] parameters,
java.lang.Object[] param) |
public static boolean isInstanceOf(java.lang.Class reference, java.lang.Object object)
reference
- reference class.object
- instance to be tested.public static boolean isOrImplementsInterface(java.lang.Class<?> reference, java.lang.Class<?> clazz)
reference
- reference interface instance.clazz
- class instance to be tested.public static boolean isOrExtends(java.lang.Class<?> reference, java.lang.Class<?> clazz)
reference
- reference class instance.clazz
- class instance to be tested.public static java.lang.Class<?>[] classesFromParameters(Parameter[] parameters)
parameters
- an array of parameters.public static Parameter[] getMethodParameters(java.lang.reflect.Method method)
method
- any valid method.public static Parameter[] getConstructorParameters(java.lang.reflect.Constructor constructor)
constructor
- any valid constructor.public static boolean matchArrayEnding(Parameter[] parameters, java.lang.Object[] param)
matchArrayEnding(Class[], Object[])
public static boolean matchArrayEnding(java.lang.Class<?>[] classes, java.lang.Object[] args)
Assuming upper case letters denote classes and corresponding lowercase its instances. Classes {A,B,C...}, instances {a,b,c1,c2} ==> check for {a,b,{c1,c2}} match or Classes {A,B,C[]}, instances {a,b,c1,c2} ==> check for {a,b,{c1,c2}} match both of the above cases are equivalent.
classes
- array of class instances to check against.args
- instances to be verified.public static boolean exactMatch(Parameter[] parameters, java.lang.Object[] args)
exactMatch(Class[], Object[])
public static boolean exactMatch(java.lang.Class<?>[] classes, java.lang.Object[] args)
classes
- array of class instances to check against.args
- instances to be verified.public static boolean lenientMatch(Parameter[] parameters, java.lang.Object[] args)
lenientMatch(Class[], Object[])
public static boolean lenientMatch(java.lang.Class<?>[] classes, java.lang.Object[] args)
classes
- array of class instances to check against.args
- instances to be verified.public static Parameter[] filter(Parameter[] parameters, java.util.Set<InjectableParameter> filters)
An example would be Input: {ITestContext.class, int.class, Boolean.class, TestContext.class} Output: {int.class, Boolean.class}
parameters
- array of parameter instances under question.filters
- filters to use.public static java.lang.Object[] inject(Parameter[] parameters, java.util.Set<InjectableParameter> filters, java.lang.Object[] args, java.lang.reflect.Method injectionMethod, ITestContext context, ITestResult testResult)
parameters
- array of parameter instances under question.filters
- filters to use.args
- user supplied arguments.injectionMethod
- current test method.context
- current test context.testResult
- on going test results.public static java.lang.Object[] inject(Parameter[] parameters, java.util.Set<InjectableParameter> filters, java.lang.Object[] args, java.lang.reflect.Constructor constructor, ITestContext context, ITestResult testResult)
parameters
- array of parameter instances under question.filters
- filters to use.args
- user supplied arguments.constructor
- current test method.context
- current test context.testResult
- on going test results.