### Question:
InputLogicParser { @SuppressWarnings("unchecked") public String parseWithName(Element root, String name) { if (root == null) { return ""; } StringBuilder parsedString = new StringBuilder(); List<Element> childrens = root.getChildren(); for (int i = 0; i < childrens.size(); i++) { String childName = childrens.get(i).getAttributeValue("name"); String min = childrens.get(i).getAttributeValue("min"); String wait = childrens.get(i).getAttributeValue("wait"); if (name == null || name.equals(childName)) { parsedString.append(parse(childrens.get(i), getOpt(childrens.get(i).getName()), min, wait)); } else { parsedString.append(parseWithName(childrens.get(i), name)); } } return parsedString.toString(); }  String parse(Element root); @SuppressWarnings("unchecked") String parseWithName(Element root, String name); String parse(Element root, String opt, String min, String wait); final static String COORD_INPUT_EVENTS_DATA_IN; final static String AND; final static String OR; final static String COMBINE; }### Answer:
@Test public void testWithName() throws JDOMException { String xml = "<input-logic>" + "<or name =\"test\" min=\"10\">" + "<data-in dataset=\"A\"/> " + "<data-in dataset=\"B\"/>" + "</or>" + "</input-logic>"; Element root = XmlUtils.parseXml(xml); InputLogicParser inputLogicParser = new InputLogicParser(); assertEquals( "(dependencyBuilder.input(\"A\").min(10).build() || dependencyBuilder.input(\"B\").min(10).build())", inputLogicParser.parseWithName(root, "test")); }
@Test public void testCombine() throws JDOMException { String xml = "<input-logic>" + "<combine name =\"test\" min=\"10\">" + "<data-in dataset=\"A\"/> " + "<data-in dataset=\"B\"/>" + "</combine>" + "</input-logic>"; Element root = XmlUtils.parseXml(xml); InputLogicParser inputLogicParser = new InputLogicParser(); assertEquals("(dependencyBuilder.combine(\"A\",\"B\").min(10).build())", inputLogicParser.parseWithName(root, "test")); }
@Test public void testWithNameNested() throws JDOMException { String xml = "<input-logic>" + "<and>" + "<or>" + "<data-in dataset=\"A\"/> " + "<data-in dataset=\"B\"/> " + "</or>" + "<or name=\"test\">" + "<data-in dataset=\"C\"/>" + "<data-in dataset=\"D\"/>" + "</or>" + "</and>" + "</input-logic>"; Element root = XmlUtils.parseXml(xml); InputLogicParser inputLogicParser = new InputLogicParser(); assertEquals("(dependencyBuilder.input(\"C\").build() || dependencyBuilder.input(\"D\").build())", inputLogicParser.parseWithName(root, "test")); }