/** * Apply the method interceptor (if applicable) to the list of methods. */ private ITestNGMethod[] intercept(ITestNGMethod[] methods) { List<IMethodInstance> methodInstances = MethodHelper.methodsToMethodInstances(Arrays.asList(methods)); // add built-in interceptor (PreserveOrderMethodInterceptor or InstanceOrderingMethodInterceptor at the end of the list m_methodInterceptors.add(builtinInterceptor); for (IMethodInterceptor m_methodInterceptor : m_methodInterceptors) { methodInstances = m_methodInterceptor.intercept(methodInstances, this); } List<ITestNGMethod> result = MethodHelper.methodInstancesToMethods(methodInstances); //Since an interceptor is involved, we would need to ensure that the ClassMethodMap object is in sync with the //output of the interceptor, else @AfterClass doesn't get executed at all when interceptors are involved. //so let's update the current classMethodMap object with the list of methods obtained from the interceptor. this.m_classMethodMap = new ClassMethodMap(result, null); ITestNGMethod[] resultArray = result.toArray(new ITestNGMethod[result.size()]); //Check if an interceptor had altered the effective test method count. If yes, then we need to //update our configurationGroupMethod object with that information. if (resultArray.length != m_groupMethods.getAllTestMethods().length) { m_groupMethods = new ConfigurationGroupMethods(resultArray, m_groupMethods.getBeforeGroupsMethods(), m_groupMethods.getAfterGroupsMethods()); } return resultArray; }
MethodHelper.methodsToMethodInstances(Arrays.asList(methods));
@Override public List<IWorker<ITestNGMethod>> createWorkers(Arguments arguments) { ListMultiMap<Object, ITestNGMethod> lmm = Maps.newSortedListMultiMap(); for (ITestNGMethod m : arguments.getMethods()) { lmm.put(m.getInstance(), m); } List<IWorker<ITestNGMethod>> result = Lists.newArrayList(); for (Map.Entry<Object, List<ITestNGMethod>> es : lmm.entrySet()) { List<IMethodInstance> methodInstances = MethodHelper.methodsToMethodInstances(es.getValue()); TestMethodWorker tmw = new TestMethodWorker(arguments.getInvoker(), methodInstances, arguments.getTestContext().getCurrentXmlTest().getSuite(), arguments.getTestContext().getCurrentXmlTest().getAllParameters(), arguments.getConfigMethods(), arguments.getClassMethodMap(), arguments.getTestContext(), arguments.getListeners()); result.add(tmw); } return result; } }
@Override public List<IWorker<ITestNGMethod>> createWorkers(Arguments arguments) { ListMultiMap<Object, ITestNGMethod> lmm = Maps.newSortedListMultiMap(); for (ITestNGMethod m : arguments.getMethods()) { lmm.put(m.getInstance(), m); } List<IWorker<ITestNGMethod>> result = Lists.newArrayList(); IInvoker invoker = arguments.getInvoker(); ITestInvoker testInvoker = invoker.getTestInvoker(); IConfigInvoker configInvoker = invoker.getConfigInvoker(); for (Map.Entry<Object, List<ITestNGMethod>> es : lmm.entrySet()) { List<IMethodInstance> methodInstances = MethodHelper.methodsToMethodInstances(es.getValue()); TestMethodWorker tmw = new TestMethodWorker( testInvoker, configInvoker, methodInstances, arguments.getTestContext().getCurrentXmlTest().getAllParameters(), arguments.getConfigMethods(), arguments.getClassMethodMap(), arguments.getTestContext(), arguments.getListeners()); result.add(tmw); } return result; } }