@Test
public void readUntilEndElementWithDepthTest() throws XMLStreamException {

    Map<String, Integer> depths = new HashMap<>();
    try (StringReader reader = new StringReader(XML)) {
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader);
        try {
            XmlUtil.readUntilEndElementWithDepth("a", xmlReader, elementDepth -> depths.put(xmlReader.getLocalName(), elementDepth));
        } finally {
            xmlReader.close();
        }
    }
    assertEquals(ImmutableMap.of("a", 0, "b", 1, "c", 2, "d", 1), depths);
}