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