From c13f4ccac35f16278b658fa40b997ffa4ddd5320 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 25 Aug 2021 22:52:26 +0200 Subject: [PATCH] [mam] Fix MamPrfsIQProviderTest Parsers handed over to IQ providers should be positioned at the IQ child element when being invoked. Therefore we remove the wrapping in some test XML. Also make checkMamPrefsIQProvider() a paramterized test. --- .../mam/provider/MamPrefsIQProvider.java | 2 ++ .../smackx/mam/MamPrefIQProviderTest.java | 36 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java index 664b3e657..604b644ca 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/provider/MamPrefsIQProvider.java @@ -41,6 +41,8 @@ import org.jxmpp.jid.impl.JidCreate; */ public class MamPrefsIQProvider extends IQProvider { + public static final MamPrefsIQProvider INSTANCE = new MamPrefsIQProvider(); + @Override public MamPrefsIQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { String defaultBehaviorString = parser.getAttributeValue("", "default"); diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mam/MamPrefIQProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mam/MamPrefIQProviderTest.java index cd5d4c0ca..956d2057b 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mam/MamPrefIQProviderTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mam/MamPrefIQProviderTest.java @@ -19,54 +19,62 @@ package org.jivesoftware.smackx.mam; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.util.List; import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.parsing.SmackParsingException; +import org.jivesoftware.smack.test.util.SmackTestUtil; +import org.jivesoftware.smack.test.util.SmackTestUtil.XmlPullParserKind; import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.xml.XmlPullParser; +import org.jivesoftware.smack.xml.XmlPullParserException; import org.jivesoftware.smackx.mam.element.MamPrefsIQ; import org.jivesoftware.smackx.mam.provider.MamPrefsIQProvider; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.jxmpp.jid.Jid; public class MamPrefIQProviderTest extends MamTest { - private static final String exampleMamPrefsIQ1 = "" + "" + private static final String exampleMamPrefsIQ1 = "" + "" + "romeo@montague.lit" + "" + "" - + "montague@montague.lit" + "" + "" + ""; + + "montague@montague.lit" + "" + ""; - private static final String exampleMamPrefsIQ2 = "" + "" + private static final String exampleMamPrefsIQ2 = "" + "" + "romeo@montague.lit" + "montague@montague.lit" + "" - + "" + "" + "" + ""; + + "" + "" + ""; - private static final String exampleMamPrefsIQ3 = "" + "" + "" - + ""; + private static final String exampleMamPrefsIQ3 = "" + ""; private static final String exampleMamPrefsResultIQ = "" + "" + "" + "romeo@montague.lit" + "" + "" + "sarasa@montague.lit" + "montague@montague.lit" + "" + "" + ""; - @Test - public void checkMamPrefsIQProvider() throws Exception { - XmlPullParser parser1 = PacketParserUtils.getParserFor(exampleMamPrefsIQ1); - MamPrefsIQ mamPrefIQ1 = new MamPrefsIQProvider().parse(parser1); + @ParameterizedTest + @EnumSource(value = SmackTestUtil.XmlPullParserKind.class) + public void checkMamPrefsIQProvider(XmlPullParserKind parserKind) + throws XmlPullParserException, IOException, SmackParsingException { + XmlPullParser parser1 = SmackTestUtil.getParserFor(exampleMamPrefsIQ1, parserKind); + MamPrefsIQ mamPrefIQ1 = MamPrefsIQProvider.INSTANCE.parse(parser1); assertEquals(IQ.Type.set, mamPrefIQ1.getType()); assertEquals(mamPrefIQ1.getAlwaysJids().get(0).toString(), "romeo@montague.lit"); assertEquals(mamPrefIQ1.getNeverJids().get(0).toString(), "montague@montague.lit"); - XmlPullParser parser2 = PacketParserUtils.getParserFor(exampleMamPrefsIQ2); - MamPrefsIQ mamPrefIQ2 = new MamPrefsIQProvider().parse(parser2); + XmlPullParser parser2 = SmackTestUtil.getParserFor(exampleMamPrefsIQ2, parserKind); + MamPrefsIQ mamPrefIQ2 = MamPrefsIQProvider.INSTANCE.parse(parser2); assertEquals(IQ.Type.set, mamPrefIQ2.getType()); assertEquals(mamPrefIQ2.getAlwaysJids().get(0).toString(), "romeo@montague.lit"); assertEquals(mamPrefIQ2.getAlwaysJids().get(1).toString(), "montague@montague.lit"); assertTrue(mamPrefIQ2.getNeverJids().isEmpty()); - XmlPullParser parser3 = PacketParserUtils.getParserFor(exampleMamPrefsIQ3); - MamPrefsIQ mamPrefIQ3 = new MamPrefsIQProvider().parse(parser3); + XmlPullParser parser3 = SmackTestUtil.getParserFor(exampleMamPrefsIQ3, parserKind); + MamPrefsIQ mamPrefIQ3 = MamPrefsIQProvider.INSTANCE.parse(parser3); assertEquals(IQ.Type.set, mamPrefIQ3.getType()); }