/** * {@inheritDoc} * * @see ReflectionRecipes#matchArrayEnding(Class[], Object[]) */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.matchArrayEnding(parameters, getContext().getArguments()); }
/** * {@inheritDoc} */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.exactMatch(parameters, getContext().getArguments()); }
public DataProviderMethodMatcher(final MethodMatcherContext context) { super(context); this.directMethodMatcher = new DirectMethodMatcher(context); this.arrayEndingMethodMatcher = new ArrayEndingMethodMatcher(context); }
/** * {@inheritDoc} */ @Override public Object[] getConformingArguments(){ if (getConforms() == null) { conforms(); } if (matchingMatcher != null) { return matchingMatcher.getConformingArguments(); } throw new MethodMatcherException("Data provider mismatch", getContext().getMethod(), getContext().getArguments()); } }
/** * {@inheritDoc} */ @Override protected boolean hasConformance() { boolean matching = false; for (final Set<InjectableParameter> injects : getConformanceInjectsOrder()) { final Parameter[] parameters = ReflectionRecipes.filter(getContext().getMethodParameter(), injects); matching = match(parameters, getContext().getArguments()); if (matching) { conformingParameters = parameters; break; } } return matching; }
/** * Gets an array of parameter values returned by data provider or the ones that * are injected based on parameter type. The method also checks for {@code NoInjection} * annotation * * @param parameterValues parameter values from a data provider * @param method method to be invoked * @param context test context */ public static Object[] injectParameters(Object[] parameterValues, Method method, ITestContext context) throws TestNGException { MethodMatcherContext matcherContext = new MethodMatcherContext(method, parameterValues, context, null); final MethodMatcher matcher = new DataProviderMethodMatcher(matcherContext); return matcher.getConformingArguments(); }
/** * @return matches or not * @see #matchArrayEnding(Class[], Object[]) */ public static boolean matchArrayEnding(final Parameter[] parameters, final Object[] param) { return matchArrayEnding(classesFromParameters(parameters), param); }
/** * Matches an array of parameters to an array of instances. * * @return matches or not * @see #exactMatch(Class[], Object[]) */ public static boolean exactMatch(final Parameter[] parameters, final Object[] args) { return exactMatch(classesFromParameters(parameters), args); }
public static String generateMessage(final String message, final Method method, final Object[] args) { Parameter[] parameter = null; String name = null; if (method != null) { parameter = ReflectionRecipes.getMethodParameters(method); name = method.getName(); } return generateMessage(message, name, "Method", parameter, args); }
/** * Matches an array of parameters to an array of instances. * * @return matches or not * @see #lenientMatch(Class[], Object[]) */ public static boolean lenientMatch(final Parameter[] parameters, final Object[] args) { return lenientMatch(classesFromParameters(parameters), args); }
/** * {@inheritDoc} */ @Override protected boolean hasConformance() { boolean matching = false; if (directMethodMatcher.conforms()) { matching = true; matchingMatcher = directMethodMatcher; } else if (arrayEndingMethodMatcher.conforms()) { matching = true; matchingMatcher = arrayEndingMethodMatcher; } return matching; }
static String generateMessage(final String message, final Constructor constructor, final Object[] args) { Parameter[] parameter = null; String name = null; if (constructor != null) { parameter = ReflectionRecipes.getConstructorParameters(constructor); name = constructor.getName(); } return generateMessage(message, name, "Constructor", parameter, args); }
/** * Extracts class instances from parameters. * * @param parameters an array of parameters. * @return parameter types. */ public static Class<?>[] classesFromParameters(final Parameter[] parameters) { final Class<?>[] classes = new Class<?>[parameters.length]; int i = 0; for (final Parameter parameter : parameters) { classes[i] = parameter.getType(); i++; } return classes; }
private static Parameter[] getParameters(Class<?>[] parametersTypes, final Annotation[][] parametersAnnotations) { final Parameter[] parameters = new Parameter[parametersTypes.length]; for (int i = 0; i < parametersTypes.length; i++) { parameters[i] = new Parameter(i, parametersTypes[i], parametersAnnotations[i]); } return parameters; }
public Parameter(final int index, final Class<?> type, final Annotation[] declaredAnnotations) { this.index = index; this.type = type; this.declaredAnnotations = declaredAnnotations; this.declaredAnnotationsMap = declaredAnnotations(declaredAnnotations); }
/** * {@inheritDoc} */ @Override public Annotation[] getAnnotations() { // For parameter all annotations are declared. return getDeclaredAnnotations(); }
/** * {@inheritDoc} */ @Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { return getAnnotation(annotationClass) != null; }
/** * {@inheritDoc} */ @Override public boolean conforms() { boolean hasConformance = false; try { hasConformance = hasConformance(); } finally { conforms = hasConformance ? Boolean.TRUE : Boolean.FALSE; } return hasConformance; }
public MethodMatcherException(final String message, final Method method, final Object[] args) { this(generateMessage(message, method, args)); }
/** * {@inheritDoc} * * @see ReflectionRecipes#matchArrayEnding(Class[], Object[]) */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.matchArrayEnding(parameters, getContext().getArguments()); }