/** * 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(); }