XMLValueConstraint implements XMLConstraint { @Override public boolean isValidElement(Element element) { final String sv = XMLUtil.getAttributeValueWithDefault(element, null, this.name); final E v = (sv == null) ? null : convertValue(sv); return v == this.value || (v != null && v.equals(this.value)); } XMLValueConstraint(String name, E value); @Override boolean isValidElement(Element element);  }
@Test public void isValidElement_valid() { Element element = mock(Element.class); when(element.getAttribute(anyString())).then((inv) -> { if (this.name.equals(inv.getArgument(0))) { return this.value.toString(); } fail("Invalid attribute name"); return null; }); assertTrue(this.constraint.isValidElement(element)); }
@Test public void isValidElement_invalid() { Element element = mock(Element.class); when(element.getAttribute(anyString())).then((inv) -> { if (this.name.equals(inv.getArgument(0))) { return UUID.randomUUID().toString(); } fail("Invalid attribute name"); return null; }); assertFalse(this.constraint.isValidElement(element)); }