### Question:
FailureProvider extends NonzaProvider<Failure> { @Override public Failure parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { Failure.CompressFailureError compressFailureError = null; StanzaError stanzaError = null; XmlEnvironment failureXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); switch (eventType) { case START_ELEMENT: String name = parser.getName(); String namespace = parser.getNamespace(); switch (namespace) { case Failure.NAMESPACE: compressFailureError = Failure.CompressFailureError.valueOf(name.replace("-", "_")); if (compressFailureError == null) { LOGGER.warning("Unknown element in " + Failure.NAMESPACE + ": " + name); } break; case StreamOpen.CLIENT_NAMESPACE: case StreamOpen.SERVER_NAMESPACE: switch (name) { case StanzaError.ERROR: stanzaError = PacketParserUtils.parseError(parser, failureXmlEnvironment); break; default: LOGGER.warning("Unknown element in " + namespace + ": " + name); break; } break; } break; case END_ELEMENT: if (parser.getDepth() == initialDepth) { break outerloop; } break; default: } } return new Failure(compressFailureError, stanzaError); } private  FailureProvider(); @Override Failure parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment); static final FailureProvider INSTANCE; }### Answer:
@Test public void simpleFailureTest() throws Exception { final String xml = "<failure xmlns='http: final XmlPullParser parser = PacketParserUtils.getParserFor(xml); final Failure failure = FailureProvider.INSTANCE.parse(parser); assertEquals(Failure.CompressFailureError.processing_failed, failure.getCompressFailureError()); }
@Test public void withStanzaErrrorFailureTest() throws Exception { final String xml = "<failure xmlns='http: + "<setup-failed/>" + "<error xmlns='jabber:client' type='modify'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</failure>"; final XmlPullParser parser = PacketParserUtils.getParserFor(xml); final Failure failure = FailureProvider.INSTANCE.parse(parser); assertEquals(Failure.CompressFailureError.setup_failed, failure.getCompressFailureError()); final StanzaError error = failure.getStanzaError(); assertEquals(Condition.bad_request, error.getCondition()); }