org.testng.internal.reflect.AbstractNodeMethodMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testng Show documentation
Show all versions of testng Show documentation
Testing framework for Java
package org.testng.internal.reflect;
import org.testng.internal.ThreeStateBoolean;
import java.util.List;
import java.util.Set;
/**
* Created on 1/4/16.
*
* @author Nitin Verma
*/
public abstract class AbstractNodeMethodMatcher extends AbstractMethodMatcher {
private Parameter[] conformingParameters = null;
private Set conformingInjects = null;
public AbstractNodeMethodMatcher(final MethodMatcherContext context) {
super(context);
}
protected Parameter[] getConformingParameters() {
return conformingParameters;
}
protected Set getConformingInjects() {
return conformingInjects;
}
/**
* {@inheritDoc}
*/
@Override
protected boolean hasConformance() {
boolean matching = false;
for (final Set injects : getConformanceInjectsOrder()) {
final Parameter[] parameters = ReflectionRecipes.filter(getContext().getMethodParameter(), injects);
matching = match(parameters, getContext().getArguments());
if (matching) {
conformingParameters = parameters;
conformingInjects = injects;
break;
}
}
return matching;
}
/**
* @return injects to check against.
*/
protected abstract List> getConformanceInjectsOrder();
/**
* Checks if its possible to gives an array consumable by java method invoker.
*
* @param parameters array of parameter instances under question.
* @param arguments instances to be verified.
* @return matches or not
*/
protected abstract boolean match(final Parameter[] parameters, final Object[] arguments);
/**
* {@inheritDoc}
*/
@Override
public Object[] getConformingArguments() throws MethodMatcherException {
if (ThreeStateBoolean.NONE.equals(getConforms())) {
conforms();
}
if (getConformingParameters() == null) {
throw new MethodMatcherException(this.getClass().getSimpleName() + " mismatch", getContext().getMethod(),
getContext().getArguments());
}
return ReflectionRecipes.inject(
getContext().getMethodParameter(),
InjectableParameter.Assistant.ALL_INJECTS,
matchingArguments(getConformingParameters(), getContext().getArguments()),
getContext().getMethod(),
getContext().getTestContext(),
getContext().getTestResult()
);
}
/**
* If possible gives an array consumable by java method invoker.
*
* @param parameters array of parameter instances under question.
* @param arguments instances to conform.
* @return conforming argument array
*/
protected abstract Object[] matchingArguments(final Parameter[] parameters, final Object[] arguments);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy