@Test(dataProvider = "methodInputParameters") public void testFilters(final Parameter[] parameters) { System.out.println("In: " + Arrays.asList(parameters)); final Parameter[] parameters1 = ReflectionRecipes.filter(parameters, InjectableParameter.Assistant.ALL_INJECTS); System.out.println("Out: " + Arrays.asList(parameters1)); Assert.assertEquals(parameters1.length, 2); Assert.assertEquals(parameters1[0].getType(), int.class); Assert.assertEquals(parameters1[1].getType(), Boolean.class); }
@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] ); } } }
@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] ); } } }
/** * {@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 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; }