XMLNameConstraint implements XMLConstraint { @Override public boolean isValidElement(Element element) { final String v = XMLUtil.getAttributeValueWithDefault(element, null, XMLUtil.ATTR_NAME); return v == this.value || (v != null && v.equals(this.value)); } XMLNameConstraint(String value); @Override boolean isValidElement(Element element);  }
@Test public void isValidElement_valid() { Element element = mock(Element.class); when(element.getAttribute(anyString())).then((inv) -> { if (XMLUtil.ATTR_NAME.equals(inv.getArgument(0))) { return this.name; } 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 (XMLUtil.ATTR_NAME.equals(inv.getArgument(0))) { return UUID.randomUUID().toString(); } fail("Invalid attribute name"); return null; }); assertFalse(this.constraint.isValidElement(element)); }