/** * 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 (matchingMatcher != null) { return matchingMatcher.getConformingArguments(); } throw new MethodMatcherException("Data provider mismatch", getContext().getMethod(), 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()); } }
/** * 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(); }
@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"); } }
@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 } }