From 18d9be00995a42e68492d64d2d6b67ef1dfc7c3a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 4 Mar 2015 13:08:35 +0100 Subject: [PATCH] Add CapsExtensionProviderTest --- .../smack/test/util/TestUtils.java | 23 ++++++++++ .../provider/CapsExtensionProviderTest.java | 44 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProviderTest.java diff --git a/smack-core/src/test/java/org/jivesoftware/smack/test/util/TestUtils.java b/smack-core/src/test/java/org/jivesoftware/smack/test/util/TestUtils.java index 4da7b1f05..c1c03bf00 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/test/util/TestUtils.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/test/util/TestUtils.java @@ -20,7 +20,10 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smack.util.ParserUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -40,6 +43,10 @@ final public class TestUtils { return getParser(stanza, "presence"); } + public static XmlPullParser getParser(String string) { + return getParser(string, null); + } + public static XmlPullParser getParser(String string, String startTag) { return getParser(new StringReader(string), startTag); } @@ -49,6 +56,9 @@ final public class TestUtils { try { parser = PacketParserUtils.newXmppParser(reader); if (startTag == null) { + while (parser.getEventType() != XmlPullParser.START_TAG) { + parser.next(); + } return parser; } boolean found = false; @@ -68,4 +78,17 @@ final public class TestUtils { return parser; } + public static EE parseExtensionElement(String elementString) + throws XmlPullParserException, IOException, SmackException { + return parseExtensionElement(getParser(elementString)); + } + + @SuppressWarnings("unchecked") + public static EE parseExtensionElement(XmlPullParser parser) + throws XmlPullParserException, IOException, SmackException { + ParserUtils.assertAtStartTag(parser); + final String elementName = parser.getName(); + final String namespace = parser.getNamespace(); + return (EE) PacketParserUtils.parseExtensionElement(elementName, namespace, parser); + } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProviderTest.java new file mode 100644 index 000000000..88e8afa98 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProviderTest.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.caps.provider; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.test.util.TestUtils; +import org.jivesoftware.smackx.InitExtensions; +import org.jivesoftware.smackx.caps.packet.CapsExtension; +import org.junit.Test; +import org.xmlpull.v1.XmlPullParserException; + +public class CapsExtensionProviderTest extends InitExtensions { + + @Test + public void parseTest() throws XmlPullParserException, IOException, SmackException { + // @formatter:off + final String capsExtensionString = + ""; + // @formatter:on + CapsExtension capsExtension = TestUtils.parseExtensionElement(capsExtensionString); + assertNotNull(capsExtension); + } +}