From 5a29be4c674df19f3a9e64e3f69d855471c8d2b6 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 21 Mar 2018 14:47:22 +0100 Subject: [PATCH] Use Jid in pubsub.Subscription --- .../jivesoftware/smackx/pubsub/Subscription.java | 14 ++++++++------ .../pubsub/provider/SubscriptionProvider.java | 4 +++- .../smackx/pubsub/provider/PubSubProviderTest.java | 8 +++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java index c11c9836b..c0eb5e26c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; + /** * Represents a subscription to node for both requests and replies. * @@ -25,7 +27,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; */ public class Subscription extends NodeExtension { - protected String jid; + protected Jid jid; protected String id; protected State state; protected boolean configRequired = false; @@ -41,7 +43,7 @@ public class Subscription extends NodeExtension * * @param subscriptionJid The subscriber JID */ - public Subscription(String subscriptionJid) + public Subscription(Jid subscriptionJid) { this(subscriptionJid, null, null, null); } @@ -53,7 +55,7 @@ public class Subscription extends NodeExtension * @param subscriptionJid The subscriber JID * @param nodeId The node id */ - public Subscription(String subscriptionJid, String nodeId) + public Subscription(Jid subscriptionJid, String nodeId) { this(subscriptionJid, nodeId, null, null); } @@ -67,7 +69,7 @@ public class Subscription extends NodeExtension * @param subscriptionId The id of this subscription * @param state The current state of the subscription */ - public Subscription(String jid, String nodeId, String subscriptionId, State state) + public Subscription(Jid jid, String nodeId, String subscriptionId, State state) { super(PubSubElementType.SUBSCRIPTION, nodeId); this.jid = jid; @@ -86,7 +88,7 @@ public class Subscription extends NodeExtension * @param state The current state of the subscription * @param configRequired Is configuration required to complete the subscription */ - public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired) + public Subscription(Jid jid, String nodeId, String subscriptionId, State state, boolean configRequired) { super(PubSubElementType.SUBSCRIPTION, nodeId); this.jid = jid; @@ -100,7 +102,7 @@ public class Subscription extends NodeExtension * * @return The JID */ - public String getJid() + public Jid getJid() { return jid; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java index b18b30887..ac432305b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java @@ -19,9 +19,11 @@ package org.jivesoftware.smackx.pubsub.provider; import java.io.IOException; import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.pubsub.Subscription; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -36,7 +38,7 @@ public class SubscriptionProvider extends ExtensionElementProvider @Override public Subscription parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - String jid = parser.getAttributeValue(null, "jid"); + Jid jid = ParserUtils.getJidAttribute(parser); String nodeId = parser.getAttributeValue(null, "node"); String subId = parser.getAttributeValue(null, "subid"); String state = parser.getAttributeValue(null, "subscription"); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java index 08e7a5c96..14e2ea2ae 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2014 Florian Schmaus + * Copyright 2014-2018 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,9 @@ */ package org.jivesoftware.smackx.pubsub.provider; +import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import java.util.List; @@ -53,12 +55,12 @@ public class PubSubProviderTest { assertEquals(2, subscriptions.size()); Subscription sub1 = subscriptions.get(0); - assertEquals("foo@example.org/Smack", sub1.getJid()); + assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid())); assertEquals(Subscription.State.subscribed, sub1.getState()); assertEquals("58C1A6F99F2A7", sub1.getId()); Subscription sub2 = subscriptions.get(1); - assertEquals("julia@example.org/Smack", sub2.getJid()); + assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid())); assertEquals(Subscription.State.subscribed, sub2.getState()); assertEquals("58C18F8917321", sub2.getId()); }