@Test public void byNameAndTextRec() { Element control = doc.createElement(FOO); Element child = doc.createElement(BAR); control.appendChild(child); child.appendChild(doc.createTextNode(BAR)); Element equal = doc.createElement(FOO); Element child2 = doc.createElement(BAR); equal.appendChild(child2); child2.appendChild(doc.createTextNode(BAR)); Element equalC = doc.createElement(FOO); Element child3 = doc.createElement(BAR); equalC.appendChild(child3); child3.appendChild(doc.createCDATASection(BAR)); Element noText = doc.createElement(FOO); Element differentLevel = doc.createElement(FOO); differentLevel.appendChild(doc.createTextNode(BAR)); Element differentElement = doc.createElement(FOO); Element child4 = doc.createElement(FOO); differentElement.appendChild(child4); child4.appendChild(doc.createTextNode(BAR)); Element differentText = doc.createElement(FOO); Element child5 = doc.createElement(BAR); differentText.appendChild(child5); child5.appendChild(doc.createTextNode(FOO)); ElementSelector s = new ByNameAndTextRecSelector(); assertTrue(s.canBeCompared(control, equal)); assertTrue(s.canBeCompared(control, equalC)); assertFalse(s.canBeCompared(control, noText)); assertFalse(s.canBeCompared(control, differentLevel)); assertFalse(s.canBeCompared(control, differentElement)); assertFalse(s.canBeCompared(control, differentText)); }
@Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!ElementSelectors.byNameAndText.canBeCompared(controlElement, testElement)) { return false; } NodeList controlChildren = controlElement.getChildNodes(); NodeList testChildren = testElement.getChildNodes(); final int controlLen = controlChildren.getLength(); final int testLen = testChildren.getLength(); int controlIndex, testIndex; for (controlIndex = testIndex = 0; controlIndex < controlLen && testIndex < testLen; ) { Map.Entry<Integer, Node> control = findNonText(controlChildren, controlIndex, controlLen); controlIndex = control.getKey(); Node c = control.getValue(); if (isText(c)) { break; } Map.Entry<Integer, Node> test = findNonText(testChildren, testIndex, testLen); testIndex = test.getKey(); Node t = test.getValue(); if (isText(t)) { break; } if (c.getNodeType() != t.getNodeType()) { return false; } if (c instanceof Element && !canBeCompared((Element) c, (Element) t)) { return false; } controlIndex++; testIndex++; } if (controlIndex < controlLen) { Map.Entry<Integer, Node> p = findNonText(controlChildren, controlIndex, controlLen); controlIndex = p.getKey(); if (controlIndex < controlLen) { return false; } } if (testIndex < testLen) { Map.Entry<Integer, Node> p = findNonText(testChildren, testIndex, testLen); testIndex = p.getKey(); if (testIndex < testLen) { return false; } } return true; }
ByNameAndTextRecSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!ElementSelectors.byNameAndText.canBeCompared(controlElement, testElement)) { return false; } NodeList controlChildren = controlElement.getChildNodes(); NodeList testChildren = testElement.getChildNodes(); final int controlLen = controlChildren.getLength(); final int testLen = testChildren.getLength(); int controlIndex, testIndex; for (controlIndex = testIndex = 0; controlIndex < controlLen && testIndex < testLen; ) { Map.Entry<Integer, Node> control = findNonText(controlChildren, controlIndex, controlLen); controlIndex = control.getKey(); Node c = control.getValue(); if (isText(c)) { break; } Map.Entry<Integer, Node> test = findNonText(testChildren, testIndex, testLen); testIndex = test.getKey(); Node t = test.getValue(); if (isText(t)) { break; } if (c.getNodeType() != t.getNodeType()) { return false; } if (c instanceof Element && !canBeCompared((Element) c, (Element) t)) { return false; } controlIndex++; testIndex++; } if (controlIndex < controlLen) { Map.Entry<Integer, Node> p = findNonText(controlChildren, controlIndex, controlLen); controlIndex = p.getKey(); if (controlIndex < controlLen) { return false; } } if (testIndex < testLen) { Map.Entry<Integer, Node> p = findNonText(testChildren, testIndex, testLen); testIndex = p.getKey(); if (testIndex < testLen) { return false; } } return true; } }
ByNameAndTextRecSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!ElementSelectors.byNameAndText.canBeCompared(controlElement, testElement)) { return false; } NodeList controlChildren = controlElement.getChildNodes(); NodeList testChildren = testElement.getChildNodes(); final int controlLen = controlChildren.getLength(); final int testLen = testChildren.getLength(); int controlIndex, testIndex; for (controlIndex = testIndex = 0; controlIndex < controlLen && testIndex < testLen; ) { Map.Entry<Integer, Node> control = findNonText(controlChildren, controlIndex, controlLen); controlIndex = control.getKey(); Node c = control.getValue(); if (isText(c)) { break; } Map.Entry<Integer, Node> test = findNonText(testChildren, testIndex, testLen); testIndex = test.getKey(); Node t = test.getValue(); if (isText(t)) { break; } if (c.getNodeType() != t.getNodeType()) { return false; } if (c instanceof Element && !canBeCompared((Element) c, (Element) t)) { return false; } controlIndex++; testIndex++; } if (controlIndex < controlLen) { Map.Entry<Integer, Node> p = findNonText(controlChildren, controlIndex, controlLen); controlIndex = p.getKey(); if (controlIndex < controlLen) { return false; } } if (testIndex < testLen) { Map.Entry<Integer, Node> p = findNonText(testChildren, testIndex, testLen); testIndex = p.getKey(); if (testIndex < testLen) { return false; } } return true; }  }
ByNameAndTextRecSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!ElementSelectors.byNameAndText.canBeCompared(controlElement, testElement)) { return false; } NodeList controlChildren = controlElement.getChildNodes(); NodeList testChildren = testElement.getChildNodes(); final int controlLen = controlChildren.getLength(); final int testLen = testChildren.getLength(); int controlIndex, testIndex; for (controlIndex = testIndex = 0; controlIndex < controlLen && testIndex < testLen; ) { Map.Entry<Integer, Node> control = findNonText(controlChildren, controlIndex, controlLen); controlIndex = control.getKey(); Node c = control.getValue(); if (isText(c)) { break; } Map.Entry<Integer, Node> test = findNonText(testChildren, testIndex, testLen); testIndex = test.getKey(); Node t = test.getValue(); if (isText(t)) { break; } if (c.getNodeType() != t.getNodeType()) { return false; } if (c instanceof Element && !canBeCompared((Element) c, (Element) t)) { return false; } controlIndex++; testIndex++; } if (controlIndex < controlLen) { Map.Entry<Integer, Node> p = findNonText(controlChildren, controlIndex, controlLen); controlIndex = p.getKey(); if (controlIndex < controlLen) { return false; } } if (testIndex < testLen) { Map.Entry<Integer, Node> p = findNonText(testChildren, testIndex, testLen); testIndex = p.getKey(); if (testIndex < testLen) { return false; } } return true; }  @Override boolean canBeCompared(Element controlElement,
                                 Element testElement); }
ByNameAndTextRecSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!ElementSelectors.byNameAndText.canBeCompared(controlElement, testElement)) { return false; } NodeList controlChildren = controlElement.getChildNodes(); NodeList testChildren = testElement.getChildNodes(); final int controlLen = controlChildren.getLength(); final int testLen = testChildren.getLength(); int controlIndex, testIndex; for (controlIndex = testIndex = 0; controlIndex < controlLen && testIndex < testLen; ) { Map.Entry<Integer, Node> control = findNonText(controlChildren, controlIndex, controlLen); controlIndex = control.getKey(); Node c = control.getValue(); if (isText(c)) { break; } Map.Entry<Integer, Node> test = findNonText(testChildren, testIndex, testLen); testIndex = test.getKey(); Node t = test.getValue(); if (isText(t)) { break; } if (c.getNodeType() != t.getNodeType()) { return false; } if (c instanceof Element && !canBeCompared((Element) c, (Element) t)) { return false; } controlIndex++; testIndex++; } if (controlIndex < controlLen) { Map.Entry<Integer, Node> p = findNonText(controlChildren, controlIndex, controlLen); controlIndex = p.getKey(); if (controlIndex < controlLen) { return false; } } if (testIndex < testLen) { Map.Entry<Integer, Node> p = findNonText(testChildren, testIndex, testLen); testIndex = p.getKey(); if (testIndex < testLen) { return false; } } return true; }  @Override boolean canBeCompared(Element controlElement,
                                 Element testElement);  }