/** * Constructs a context for MethodMatchers. * * @param method current method. * @param arguments user arguments. * @param testContext current test context. * @param testResult current test results. */ public MethodMatcherContext( final Method method, final Object[] arguments, final ITestContext testContext, final ITestResult testResult) { this.method = method; this.methodParameter = ReflectionRecipes.getMethodParameters(method); this.arguments = arguments; this.testContext = testContext; this.testResult = testResult; }
/** * Constructs a context for MethodMatchers. * * @param method current method. * @param arguments user arguments. * @param testContext current test context. * @param testResult current test results. */ public MethodMatcherContext( final Method method, final Object[] arguments, final ITestContext testContext, final ITestResult testResult) { this.method = method; this.methodParameter = ReflectionRecipes.getMethodParameters(method); this.arguments = arguments; this.testContext = testContext; this.testResult = testResult; }
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); }
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); }
/** * @return An array of parameters suitable to invoke this method, possibly * picked from the property file */ private static Object[] createParametersForMethod(Method method, Class<?>[] parameterTypes, String[] optionalValues, String methodAnnotation, String[] parameterNames, MethodParameters params, XmlSuite xmlSuite) { if (parameterTypes.length == 0) { return new Object[0]; } checkParameterTypes(method.getName(), parameterTypes, methodAnnotation, parameterNames); List<Object> vResult = Lists.newArrayList(); List<Object> consParams = createParams(method.getName(), "method", methodAnnotation, parameterTypes, optionalValues, parameterNames, params, xmlSuite); if (canInject(methodAnnotation)) { Parameter[] paramsArray = ReflectionRecipes.getMethodParameters(method); Object[] inject = ReflectionRecipes.inject(paramsArray, InjectableParameter.Assistant.ALL_INJECTS, consParams.toArray(new Object[consParams.size()]), params.currentTestMethod, params.context, params.testResult); if (inject != null) { vResult.addAll(Arrays.asList(inject)); } } else { vResult.addAll(consParams); } return vResult.toArray(new Object[vResult.size()]); }
private static Parameter[] getMethodParameters(final Class<?> clazz, final String methodName) { Method method = null; Parameter[] parameters = null; for (final Method m : clazz.getMethods()) { if (m.getName().equals(methodName)) { method = m; } } if (method != null) { parameters = ReflectionRecipes.getMethodParameters(method); } return parameters; }
private static Parameter[] extractParameters(ConstructorOrMethod method) { if (method.getMethod() != null) { return ReflectionRecipes.getMethodParameters(method.getMethod()); } return ReflectionRecipes.getConstructorParameters(method.getConstructor()); }
@Test(dataProvider = "exactMatchDP") public void exactMatchTest(final Object[][] expected, @NoInjection final Method method) { if (expected != null) { final Parameter[] methodParameters = ReflectionRecipes.getMethodParameters(method); Assert.assertNotNull(methodParameters); final Parameter[] filteredParameters = ReflectionRecipes.filter(methodParameters, InjectableParameter.Assistant.ALL_INJECTS); Assert.assertNotNull(filteredParameters); for (final Object[] expect : expected) { Assert.assertNotNull(expect); Assert.assertEquals(expect.length, 2); Assert.assertNotNull(expect[0]); Assert.assertTrue(expect[0] instanceof Object[]); Assert.assertNotNull(expect[1]); Assert.assertTrue(expect[1] instanceof Boolean); Assert.assertEquals( ReflectionRecipes.exactMatch(filteredParameters, (Object[]) expect[0]), expect[1] ); } } }
@Test(dataProvider = "matchArrayEndingDP") public void matchArrayEndingTest(final Object[][] expected, @NoInjection final Method method) { if (expected != null) { final Parameter[] methodParameters = ReflectionRecipes.getMethodParameters(method); Assert.assertNotNull(methodParameters); final Parameter[] filteredParameters = ReflectionRecipes.filter(methodParameters, InjectableParameter.Assistant.ALL_INJECTS); Assert.assertNotNull(filteredParameters); for (final Object[] expect : expected) { Assert.assertNotNull(expect); Assert.assertEquals(expect.length, 2); Assert.assertNotNull(expect[0]); Assert.assertTrue(expect[0] instanceof Object[]); Assert.assertNotNull(expect[1]); Assert.assertTrue(expect[1] instanceof Boolean); Assert.assertEquals( ReflectionRecipes.matchArrayEnding(filteredParameters, (Object[]) expect[0]), expect[1] ); } } }