@Test public void byNameAndAttributesControlNS() { Element control = doc.createElement(FOO); control.setAttributeNS(SOME_URI, BAR, BAR); Element equal = doc.createElement(FOO); equal.setAttributeNS(SOME_URI, BAR, BAR); Element noAttributes = doc.createElement(FOO); Element differentValue = doc.createElement(FOO); differentValue.setAttributeNS(SOME_URI, BAR, FOO); Element differentName = doc.createElement(FOO); differentName.setAttributeNS(SOME_URI, FOO, FOO); Element differentNS = doc.createElement(FOO); differentNS.setAttributeNS(SOME_URI + "2", BAR, BAR); Element noNS = doc.createElement(FOO); noNS.setAttribute(BAR, BAR); assertTrue(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, equal)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, noAttributes)); assertTrue(ElementSelectors.byNameAndAttributesControlNS(FOO) .canBeCompared(control, noAttributes)); assertTrue(ElementSelectors.byNameAndAttributesControlNS(new String[] {}) .canBeCompared(control, noAttributes)); assertTrue(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(noAttributes, control)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(noAttributes, noNS)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, differentValue)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, differentName)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, differentNS)); assertFalse(ElementSelectors.byNameAndAttributesControlNS(BAR) .canBeCompared(control, noNS)); }
public static ElementSelector byNameAndAttributesControlNS(final String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection<String> qs = Arrays.asList(attribs); if (any(qs, new IsNullPredicate())) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet<String> as = new HashSet<String>(qs); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!byName.canBeCompared(controlElement, testElement)) { return false; } Map<QName, String> cAttrs = Nodes.getAttributes(controlElement); Map<String, QName> qNameByLocalName = new HashMap<String, QName>(); for (QName q : cAttrs.keySet()) { String local = q.getLocalPart(); if (as.contains(local)) { qNameByLocalName.put(local, q); } } for (String a : as) { QName q = qNameByLocalName.get(a); if (q == null) { qNameByLocalName.put(a, new QName(a)); } } return mapsEqualForKeys(cAttrs, Nodes.getAttributes(testElement), qNameByLocalName.values()); } }; }
ElementSelectors { public static ElementSelector byNameAndAttributesControlNS(final String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection<String> qs = Arrays.asList(attribs); if (any(qs, new IsNullPredicate())) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet<String> as = new HashSet<String>(qs); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!byName.canBeCompared(controlElement, testElement)) { return false; } Map<QName, String> cAttrs = Nodes.getAttributes(controlElement); Map<String, QName> qNameByLocalName = new HashMap<String, QName>(); for (QName q : cAttrs.keySet()) { String local = q.getLocalPart(); if (as.contains(local)) { qNameByLocalName.put(local, q); } } for (String a : as) { QName q = qNameByLocalName.get(a); if (q == null) { qNameByLocalName.put(a, new QName(a)); } } return mapsEqualForKeys(cAttrs, Nodes.getAttributes(testElement), qNameByLocalName.values()); } }; } }
ElementSelectors { public static ElementSelector byNameAndAttributesControlNS(final String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection<String> qs = Arrays.asList(attribs); if (any(qs, new IsNullPredicate())) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet<String> as = new HashSet<String>(qs); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!byName.canBeCompared(controlElement, testElement)) { return false; } Map<QName, String> cAttrs = Nodes.getAttributes(controlElement); Map<String, QName> qNameByLocalName = new HashMap<String, QName>(); for (QName q : cAttrs.keySet()) { String local = q.getLocalPart(); if (as.contains(local)) { qNameByLocalName.put(local, q); } } for (String a : as) { QName q = qNameByLocalName.get(a); if (q == null) { qNameByLocalName.put(a, new QName(a)); } } return mapsEqualForKeys(cAttrs, Nodes.getAttributes(testElement), qNameByLocalName.values()); } }; } private  ElementSelectors(); }
ElementSelectors { public static ElementSelector byNameAndAttributesControlNS(final String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection<String> qs = Arrays.asList(attribs); if (any(qs, new IsNullPredicate())) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet<String> as = new HashSet<String>(qs); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!byName.canBeCompared(controlElement, testElement)) { return false; } Map<QName, String> cAttrs = Nodes.getAttributes(controlElement); Map<String, QName> qNameByLocalName = new HashMap<String, QName>(); for (QName q : cAttrs.keySet()) { String local = q.getLocalPart(); if (as.contains(local)) { qNameByLocalName.put(local, q); } } for (String a : as) { QName q = qNameByLocalName.get(a); if (q == null) { qNameByLocalName.put(a, new QName(a)); } } return mapsEqualForKeys(cAttrs, Nodes.getAttributes(testElement), qNameByLocalName.values()); } }; } private  ElementSelectors(); static ElementSelector byNameAndAttributes(String... attribs); static ElementSelector byNameAndAttributesControlNS(final String... attribs); static ElementSelector byNameAndAttributes(final QName... attribs); static ElementSelector not(final ElementSelector es); static ElementSelector or(final ElementSelector... selectors); static ElementSelector and(final ElementSelector... selectors); static ElementSelector xor(final ElementSelector es1,
                                      final ElementSelector es2); static ElementSelector conditionalSelector(final Predicate<? super Element> predicate,
                                                      final ElementSelector es); static ElementSelector selectorForElementNamed(final String expectedName,
                                                          final ElementSelector es); static ElementSelector selectorForElementNamed(final QName expectedName,
                                                          final ElementSelector es); static ElementSelector byXPath(String xpath, ElementSelector childSelector); static ElementSelector byXPath(final String xpath,
                                          Map<String, String> prefix2Uri,
                                          ElementSelector childSelector); static ConditionalSelectorBuilder conditionalBuilder(); }
ElementSelectors { public static ElementSelector byNameAndAttributesControlNS(final String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection<String> qs = Arrays.asList(attribs); if (any(qs, new IsNullPredicate())) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet<String> as = new HashSet<String>(qs); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { if (!byName.canBeCompared(controlElement, testElement)) { return false; } Map<QName, String> cAttrs = Nodes.getAttributes(controlElement); Map<String, QName> qNameByLocalName = new HashMap<String, QName>(); for (QName q : cAttrs.keySet()) { String local = q.getLocalPart(); if (as.contains(local)) { qNameByLocalName.put(local, q); } } for (String a : as) { QName q = qNameByLocalName.get(a); if (q == null) { qNameByLocalName.put(a, new QName(a)); } } return mapsEqualForKeys(cAttrs, Nodes.getAttributes(testElement), qNameByLocalName.values()); } }; } private  ElementSelectors(); static ElementSelector byNameAndAttributes(String... attribs); static ElementSelector byNameAndAttributesControlNS(final String... attribs); static ElementSelector byNameAndAttributes(final QName... attribs); static ElementSelector not(final ElementSelector es); static ElementSelector or(final ElementSelector... selectors); static ElementSelector and(final ElementSelector... selectors); static ElementSelector xor(final ElementSelector es1,
                                      final ElementSelector es2); static ElementSelector conditionalSelector(final Predicate<? super Element> predicate,
                                                      final ElementSelector es); static ElementSelector selectorForElementNamed(final String expectedName,
                                                          final ElementSelector es); static ElementSelector selectorForElementNamed(final QName expectedName,
                                                          final ElementSelector es); static ElementSelector byXPath(String xpath, ElementSelector childSelector); static ElementSelector byXPath(final String xpath,
                                          Map<String, String> prefix2Uri,
                                          ElementSelector childSelector); static ConditionalSelectorBuilder conditionalBuilder(); static final ElementSelector Default; static final ElementSelector byName; static final ElementSelector byNameAndText; static final ElementSelector byNameAndAllAttributes; }