/** * 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(); }
/** * {@inheritDoc} */ @Override public Object[] getConformingArguments() { if (getConforms() == null) { 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() ); }
/** * {@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; }
/** * {@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 match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.exactMatch(parameters, getContext().getArguments()); }
/** {@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; }
/** * {@inheritDoc} * * @see ReflectionRecipes#matchArrayEnding(Class[], Object[]) */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.matchArrayEnding(parameters, getContext().getArguments()); }
/** {@inheritDoc} */ @Override public Object[] getConformingArguments() { if (getConforms() == null) { 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()); }
/** * 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(); }
/** {@inheritDoc} */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.exactMatch(parameters, getContext().getArguments()); }
@Test(dataProvider = "methodParamPairs") public void testMatcher(final String methodName, final Object[] params, final ITestContext iTestContext, final ITestResult iTestResult) { final Method method = getMethod(methodName); final MethodMatcher matcher = new DataProviderMethodMatcher( new MethodMatcherContext(method, params, iTestContext, iTestResult)); try { method.invoke(new TestMethodMatcher(), matcher.getConformingArguments()); } catch (final Throwable throwable) { System.out.println("methodParamPairs failure"); throwable.printStackTrace(); Assert.fail("methodParamPairs failure"); } }
/** * {@inheritDoc} * * @see ReflectionRecipes#matchArrayEnding(Class[], Object[]) */ @Override protected boolean match(final Parameter[] parameters, final Object[] arguments) { return ReflectionRecipes.matchArrayEnding(parameters, getContext().getArguments()); }
@Test(dataProvider = "methodParamFailingPairs") public void testNegativeCaseMatcher(final String methodName, final Object[] params, final ITestContext iTestContext, final ITestResult iTestResult) { final Method method = getMethod(methodName); final MethodMatcher matcher = new DataProviderMethodMatcher( new MethodMatcherContext(method, params, iTestContext, iTestResult)); Assert.assertFalse(matcher.conforms()); try { method.invoke(new TestMethodMatcher(), matcher.getConformingArguments()); Assert.fail(); } catch (final Throwable throwable) { throwable.printStackTrace(); //noop } }