### Question:
ParseStreamManagement { public static Failed failed(XmlPullParser parser) throws XmlPullParserException, IOException { ParserUtils.assertAtStartTag(parser); String name; StanzaError.Condition condition = null; List<StanzaErrorTextElement> textElements = new ArrayList<>(4); outerloop: while (true) { XmlPullParser.Event event = parser.next(); switch (event) { case START_ELEMENT: name = parser.getName(); String namespace = parser.getNamespace(); if (StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE.equals(namespace)) { if (name.equals(AbstractTextElement.ELEMENT)) { String lang = ParserUtils.getXmlLang(parser); String text = parser.nextText(); StanzaErrorTextElement stanzaErrorTextElement = new StanzaErrorTextElement(text, lang); textElements.add(stanzaErrorTextElement); } else { condition = StanzaError.Condition.fromString(name); } } break; case END_ELEMENT: name = parser.getName(); if (Failed.ELEMENT.equals(name)) { break outerloop; } break; default: break; } } ParserUtils.assertAtEndTag(parser); return new Failed(condition, textElements); }  static Enabled enabled(XmlPullParser parser); static Failed failed(XmlPullParser parser); static Resumed resumed(XmlPullParser parser); static AckAnswer ackAnswer(XmlPullParser parser); static AckRequest ackRequest(XmlPullParser parser);  }### Answer:
@Test public void testParseFailed() throws Exception { String failedStanza = XMLBuilder.create("failed") .a("xmlns", "urn:xmpp:sm:3") .asString(outputProperties); StreamManagement.Failed failedPacket = ParseStreamManagement.failed( PacketParserUtils.getParserFor(failedStanza)); assertNotNull(failedPacket); assertTrue(failedPacket.getStanzaErrorCondition() == null); }
@Test public void testParseFailedError() throws Exception { StanzaError.Condition errorCondition = StanzaError.Condition.unexpected_request; String failedStanza = XMLBuilder.create("failed") .a("xmlns", "urn:xmpp:sm:3") .element(errorCondition.toString(), StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE) .asString(outputProperties); StreamManagement.Failed failedPacket = ParseStreamManagement.failed( PacketParserUtils.getParserFor(failedStanza)); assertNotNull(failedPacket); assertTrue(failedPacket.getStanzaErrorCondition() == errorCondition); }
@Test public void testParseFailedWithTExt() throws XmlPullParserException, IOException { final String failedNonza = "<failed h='20' xmlns='urn:xmpp:sm:3'>" + "<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>" + "Previous session timed out" + "</text>" + "</failed>"; XmlPullParser parser = PacketParserUtils.getParserFor(failedNonza); StreamManagement.Failed failed = ParseStreamManagement.failed(parser); assertEquals(StanzaError.Condition.item_not_found, failed.getStanzaErrorCondition()); List<StanzaErrorTextElement> textElements = failed.getTextElements(); assertEquals(1, textElements.size()); StanzaErrorTextElement textElement = textElements.get(0); assertEquals("Previous session timed out", textElement.getText()); assertEquals("en", textElement.getLanguage()); }