Class ReflectionRecipes
java.lang.Object
org.testng.internal.reflect.ReflectionRecipes
Utility class to handle reflection.
- Author:
- Nitin Verma
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>[]classesFromParameters(Parameter[] parameters) Extracts class instances from parameters.static booleanexactMatch(Class<?>[] classes, Object[] args) Matches an array of class instances to an array of instances.static booleanexactMatch(Parameter[] parameters, Object[] args) Matches an array of parameters to an array of instances.static Parameter[]filter(Parameter[] parameters, Set<InjectableParameter> filters) Omits 1.static Parameter[]getConstructorParameters(Constructor<?> constructor) Extracts constructor parameters.static Parameter[]getMethodParameters(Method method) Extracts method parameters.static Object[]inject(Parameter[] parameters, Set<InjectableParameter> filters, Object[] args, Constructor<?> constructor, ITestContext context, ITestResult testResult) Injects appropriate arguments.static Object[]inject(Parameter[] parameters, Set<InjectableParameter> filters, Object[] args, Method injectionMethod, ITestContext context, ITestResult testResult) Injects appropriate arguments.static booleanisInstanceOf(Class<?> reference, Object object) Checks if an instance is an instance of the given class.static booleanisOrExtends(Class<?> reference, Class<?> clazz) Checks a class instance for being a given class or its sub-class.static booleanisOrImplementsInterface(Class<?> reference, Class<?> clazz) Checks a class instance for being a given interface or its implementation.static booleanlenientMatch(Class<?>[] classes, Object[] args) Matches an array of class instances to an array of instances.static booleanlenientMatch(Parameter[] parameters, Object[] args) Matches an array of parameters to an array of instances.static booleanmatchArrayEnding(Class<?>[] classes, Object[] args) Matches an array of class instances to an array of instances having last class instance an array.static booleanmatchArrayEnding(Parameter[] parameters, Object[] param)
-
Method Details
-
isInstanceOf
-
isOrImplementsInterface
Checks a class instance for being a given interface or its implementation.- Parameters:
reference- reference interface instance.clazz- class instance to be tested.- Returns:
- would an instance of 'clazz' be an instance of reference interface.
-
isOrExtends
-
classesFromParameters
-
getMethodParameters
-
getConstructorParameters
Extracts constructor parameters.- Parameters:
constructor- any valid constructor.- Returns:
- extracted constructor parameters.
-
matchArrayEnding
-
matchArrayEnding
Matches an array of class instances to an array of instances having last class instance an array.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.
- Parameters:
classes- array of class instances to check against.args- instances to be verified.- Returns:
- matches or not
-
exactMatch
-
exactMatch
-
lenientMatch
-
lenientMatch
Matches an array of class instances to an array of instances. Such that {int, boolean, float} matches {int, boolean}- Parameters:
classes- array of class instances to check against.args- instances to be verified.- Returns:
- matches or not
-
filter
Omits 1. org.testng.ITestContext or its implementations from input array 2. org.testng.ITestResult or its implementations from input array 3. org.testng.xml.XmlTest or its implementations from input array 4. First method depending on filters.An example would be Input: {ITestContext.class, int.class, Boolean.class, TestContext.class} Output: {int.class, Boolean.class}
- Parameters:
parameters- array of parameter instances under question.filters- filters to use.- Returns:
- Injects free array of class instances.
-
inject
public static Object[] inject(Parameter[] parameters, Set<InjectableParameter> filters, Object[] args, Method injectionMethod, ITestContext context, ITestResult testResult) Injects appropriate arguments.- Parameters:
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.- Returns:
- injected arguments.
-
inject
public static Object[] inject(Parameter[] parameters, Set<InjectableParameter> filters, Object[] args, Constructor<?> constructor, ITestContext context, ITestResult testResult) Injects appropriate arguments.- Parameters:
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.- Returns:
- injected arguments.
-