|
25 | 25 | import org.mockito.Mockito; |
26 | 26 | import org.mockito.invocation.InvocationOnMock; |
27 | 27 | import org.mockito.stubbing.Answer; |
| 28 | +import org.w3c.dom.Attr; |
28 | 29 | import org.w3c.dom.Document; |
29 | 30 | import org.w3c.dom.Element; |
30 | 31 | import org.w3c.dom.Node; |
@@ -128,6 +129,35 @@ static void byNameAndText_SingleLevel(ElementSelector s, Document doc) { |
128 | 129 | .canBeCompared(control, differentNS)); |
129 | 130 | } |
130 | 131 |
|
| 132 | + @Test public void byNameAndAllAttributesWithFilter() { |
| 133 | + Element control = doc.createElement(FOO); |
| 134 | + control.setAttribute(BAR, BAR); |
| 135 | + Element equal = doc.createElement(FOO); |
| 136 | + equal.setAttribute(BAR, BAR); |
| 137 | + equal.setAttribute("x", "y"); |
| 138 | + Element noAttributes = doc.createElement(FOO); |
| 139 | + Element differentValue = doc.createElement(FOO); |
| 140 | + differentValue.setAttribute(BAR, FOO); |
| 141 | + Element differentName = doc.createElement(FOO); |
| 142 | + differentName.setAttribute(FOO, FOO); |
| 143 | + Element differentNS = doc.createElement(FOO); |
| 144 | + differentNS.setAttributeNS(SOME_URI, BAR, BAR); |
| 145 | + Predicate<Attr> filter = new Predicate<Attr>() { |
| 146 | + @Override |
| 147 | + public boolean test(Attr a) { |
| 148 | + return BAR.equals(a.getName()); |
| 149 | + } |
| 150 | + }; |
| 151 | + ElementSelector es = ElementSelectors.byNameAndAllAttributes(filter); |
| 152 | + |
| 153 | + assertTrue(es.canBeCompared(control, equal)); |
| 154 | + assertFalse(es.canBeCompared(control, noAttributes)); |
| 155 | + assertFalse(es.canBeCompared(noAttributes, control)); |
| 156 | + assertFalse(es.canBeCompared(control, differentValue)); |
| 157 | + assertFalse(es.canBeCompared(control, differentName)); |
| 158 | + assertFalse(es.canBeCompared(control, differentNS)); |
| 159 | + } |
| 160 | + |
131 | 161 | @Test public void byNameAndAttributes_NamePart() { |
132 | 162 | pureElementNameComparisons(ElementSelectors |
133 | 163 | .byNameAndAttributes(new String[] {})); |
|
0 commit comments