try { invoker.prepare(); return (StepExecution) invoker.invoke();
/** * Discover a {@link JobExecution} as a field in the test case or create * one if none is available. * * @param testContext the current test context * @return a {@link JobExecution} */ protected JobExecution getJobExecution(TestContext testContext) { Object target = testContext.getTestInstance(); ExtractorMethodCallback method = new ExtractorMethodCallback(JobExecution.class, "getJobExecution"); ReflectionUtils.doWithMethods(target.getClass(), method); if (method.getName() != null) { HippyMethodInvoker invoker = new HippyMethodInvoker(); invoker.setTargetObject(target); invoker.setTargetMethod(method.getName()); try { invoker.prepare(); return (JobExecution) invoker.invoke(); } catch (Exception e) { throw new IllegalArgumentException("Could not create job execution from method: " + method.getName(), e); } } return MetaDataInstanceFactory.createJobExecution(); }
@Test public void testTwoArgsOfSameTypeWithInexactMatch() throws Exception { HippyMethodInvoker invoker = new HippyMethodInvoker(); invoker.setTargetMethod("duplicate"); invoker.setTargetObject(new PlainPojo()); invoker.setArguments(new Object[] { "2", "foo" }); invoker.prepare(); assertEquals("foo.2", invoker.invoke()); }
@Test public void testOverloadedMethodUsingInputWithoutExactMatch() throws Exception { HippyMethodInvoker invoker = new HippyMethodInvoker(); invoker.setTargetMethod("foo"); @SuppressWarnings("unused") class OverloadingPojo { public Class<?> foo(List<?> arg) { return List.class; } public Class<?> foo(Set<?> arg) { return Set.class; } } TreeSet<Object> arg = new TreeSet<>(); OverloadingPojo target = new OverloadingPojo(); assertEquals(target.foo(arg), Set.class); invoker.setTargetObject(target); invoker.setArguments(new Object[] { arg }); invoker.prepare(); assertEquals(invoker.invoke(), Set.class); }