/** * 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; }
methodInstances = m_methodInterceptor.intercept(methodInstances, this);
methods = interceptor.newInstance().intercept(methods, context);