/** Clone an XmlClass by copying all its components. */ @Override public Object clone() { XmlClass result = new XmlClass(getName(), getIndex(), loadClasses()); result.setExcludedMethods(getExcludedMethods()); result.setIncludedMethods(getIncludedMethods()); return result; }
/** * @param methods The methods we want to represent * @param srcXmlTest * @return A list of XmlClass objects (each representing a <class> tag) based on the parameter * methods */ private List<XmlClass> createXmlClasses(List<ITestNGMethod> methods, XmlTest srcXmlTest) { List<XmlClass> result = Lists.newArrayList(); Map<Class, Set<ITestNGMethod>> methodsMap = Maps.newHashMap(); for (ITestNGMethod m : methods) { Object[] instances = m.getInstances(); Class clazz = instances == null || instances.length == 0 || instances[0] == null ? m.getRealClass() : instances[0].getClass(); Set<ITestNGMethod> methodList = methodsMap.get(clazz); if (null == methodList) { methodList = new HashSet<ITestNGMethod>(); methodsMap.put(clazz, methodList); } methodList.add(m); } // Ideally, we should preserve each parameter in each class but putting them // all in the same bag for now Map<String, String> parameters = Maps.newHashMap(); for (XmlClass c : srcXmlTest.getClasses()) { parameters.putAll(c.getLocalParameters()); } int index = 0; for (Map.Entry<Class, Set<ITestNGMethod>> entry : methodsMap.entrySet()) { Class clazz = entry.getKey(); Set<ITestNGMethod> methodList = entry.getValue(); // @author Borojevic // Need to check all the methods, not just @Test ones. XmlClass xmlClass = new XmlClass(clazz.getName(), index++, false /* don't load classes */); List<XmlInclude> methodNames = Lists.newArrayList(methodList.size()); int ind = 0; for (ITestNGMethod m : methodList) { methodNames.add( new XmlInclude(m.getMethod().getName(), m.getFailedInvocationNumbers(), ind++)); } xmlClass.setIncludedMethods(methodNames); xmlClass.setParameters(parameters); result.add(xmlClass); } return result; }