1 package org.testng; 2 3 import org.testng.internal.MethodInstance; 4 5 import java.util.Collections; 6 import java.util.List; 7 8 /** 9 * A method interceptor that preserves the order in which test classes were found in 10 * the <test> tag. 11 * 12 * @author cbeust 13 * 14 */ 15 class PreserveOrderMethodInterceptor implements IMethodInterceptor { 16 p(List<IMethodInstance> methods, String s)17 private void p(List<IMethodInstance> methods, String s) { 18 System.out.println("[PreserveOrderMethodInterceptor] " + s); 19 for (IMethodInstance mi : methods) { 20 System.out.println(" " + mi.getMethod().getMethodName() 21 + " index:" + mi.getMethod().getTestClass().getXmlClass().getIndex()); 22 } 23 } 24 25 @Override intercept(List<IMethodInstance> methods, ITestContext context)26 public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) { 27 // p(methods, "Before"); 28 Collections.sort(methods, MethodInstance.SORT_BY_INDEX); 29 // p(methods, "After"); 30 return methods; 31 } 32 33 } 34