diff options
author | Alan Young <consult.awy@gmail.com> | 2015-06-29 09:26:14 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-07-07 08:58:14 (GMT) |
commit | d32bc2d8ab89f9f9787f417d71055e2b88a3b92b (patch) | |
tree | 9a7dbb85b33805e0428e39efb3da9d1f127528c3 | |
parent | 1f31d8301bbb89a61235d575ac3c5a2061df3a69 (diff) | |
download | stroke-d32bc2d8ab89f9f9787f417d71055e2b88a3b92b.zip stroke-d32bc2d8ab89f9f9787f417d71055e2b88a3b92b.tar.bz2 |
Update Avatar access model.
Use the String avatar hash as the general handle for an avatar.
AvatarManager.getAvatar(JID jid) will return null if no
avatar is available.
AvatarManager.getAvatarPath() and AvatarStorage.getAvatarPath() are
deleted.
Make AvatarProvider & AvatarManager abstract classes instead of
interfaces so that their onAvatarChanged Signals are not static fields.
Implement delete() for AvatarManagerImpl and AvatarProvider & subclasses
so that signal connections can be released.
Add @Override annotations as appropriate.
Change-Id: Ia7c9d7607b642bb42c373f81dc6be9a60f0f2134
14 files changed, 141 insertions, 156 deletions
diff --git a/src/com/isode/stroke/avatars/AvatarManager.java b/src/com/isode/stroke/avatars/AvatarManager.java index 8bb8e71..10b2777 100755 --- a/src/com/isode/stroke/avatars/AvatarManager.java +++ b/src/com/isode/stroke/avatars/AvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,14 +11,11 @@ package com.isode.stroke.avatars; -import java.nio.file.Path; import com.isode.stroke.jid.JID; -import com.isode.stroke.base.ByteArray; import com.isode.stroke.signals.Signal1; -public interface AvatarManager { +public abstract class AvatarManager { - public ByteArray getAvatar(JID jid); - public Path getAvatarPath(JID jid); + public abstract String getAvatar(JID jid); public Signal1<JID> onAvatarChanged = new Signal1<JID>(); }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/AvatarManagerImpl.java b/src/com/isode/stroke/avatars/AvatarManagerImpl.java index b324b3e..7803670 100755 --- a/src/com/isode/stroke/avatars/AvatarManagerImpl.java +++ b/src/com/isode/stroke/avatars/AvatarManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,30 +11,22 @@ package com.isode.stroke.avatars; -import com.isode.stroke.avatars.AvatarManager; -import com.isode.stroke.avatars.CombinedAvatarProvider; -import com.isode.stroke.muc.MUCRegistry; -import com.isode.stroke.avatars.AvatarStorage; import com.isode.stroke.client.StanzaChannel; -import com.isode.stroke.vcards.VCardManager; -import com.isode.stroke.avatars.VCardUpdateAvatarManager; -import com.isode.stroke.avatars.VCardAvatarManager; -import com.isode.stroke.avatars.OfflineAvatarManager; import com.isode.stroke.crypto.CryptoProvider; -import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; -import com.isode.stroke.signals.Slot1; -import java.nio.file.*; +import com.isode.stroke.muc.MUCRegistry; import com.isode.stroke.signals.SignalConnection; +import com.isode.stroke.signals.Slot1; +import com.isode.stroke.vcards.VCardManager; -public class AvatarManagerImpl implements AvatarManager { +public class AvatarManagerImpl extends AvatarManager { - private CombinedAvatarProvider combinedAvatarProvider = new CombinedAvatarProvider(); + private final CombinedAvatarProvider combinedAvatarProvider = new CombinedAvatarProvider(); private AvatarStorage avatarStorage; private VCardUpdateAvatarManager vcardUpdateAvatarManager; private VCardAvatarManager vcardAvatarManager; private OfflineAvatarManager offlineAvatarManager; - private SignalConnection onAvatarChangedConnection; + private final SignalConnection onAvatarChangedConnection; public AvatarManagerImpl(VCardManager vcardManager, StanzaChannel stanzaChannel, AvatarStorage avatarStorage, CryptoProvider crypto) { this(vcardManager, stanzaChannel, avatarStorage, crypto, null); @@ -52,27 +44,22 @@ public class AvatarManagerImpl implements AvatarManager { combinedAvatarProvider.addProvider(offlineAvatarManager); onAvatarChangedConnection = combinedAvatarProvider.onAvatarChanged.connect(new Slot1<JID>() { - - public void call(JID p1) { - handleCombinedAvatarChanged(p1); - } + @Override public void call(JID p1) {handleCombinedAvatarChanged(p1);} }); } - - public Path getAvatarPath(JID jid) { - String hash = combinedAvatarProvider.getAvatarHash(jid); - if (hash != null && hash.length() != 0) { - return avatarStorage.getAvatarPath(hash); - } - return Paths.get(""); + + public void delete() { + onAvatarChangedConnection.disconnect(); + combinedAvatarProvider.delete(); } - public ByteArray getAvatar(JID jid) { + @Override + public String getAvatar(JID jid) { String hash = combinedAvatarProvider.getAvatarHash(jid); - if (hash != null && hash.length() != 0) { - return avatarStorage.getAvatar(hash); + if (hash != null && hash.length() != 0 && avatarStorage.hasAvatar(hash)) { + return hash; } - return new ByteArray(); + return null; } private void handleCombinedAvatarChanged(JID jid) { diff --git a/src/com/isode/stroke/avatars/AvatarMemoryStorage.java b/src/com/isode/stroke/avatars/AvatarMemoryStorage.java index a3ad6f0..10079ba 100755 --- a/src/com/isode/stroke/avatars/AvatarMemoryStorage.java +++ b/src/com/isode/stroke/avatars/AvatarMemoryStorage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,8 +14,7 @@ package com.isode.stroke.avatars; import com.isode.stroke.avatars.AvatarStorage; import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; -import java.nio.file.*; -import java.io.File; + import java.util.*; public class AvatarMemoryStorage implements AvatarStorage { @@ -23,35 +22,38 @@ public class AvatarMemoryStorage implements AvatarStorage { private Map<String, ByteArray> avatars = new HashMap<String, ByteArray>(); private Map<JID, String> jidAvatars = new HashMap<JID, String>(); + @Override public boolean hasAvatar(String hash) { return avatars.containsKey(hash); } + @Override public void addAvatar(String hash, ByteArray avatar) { avatars.put(hash, avatar); } - public ByteArray getAvatar(String hash) { - if(avatars.containsKey(hash)) { - return avatars.get(hash); - } else { - return new ByteArray(); - } - } - - public Path getAvatarPath(String hash) { - return (Paths.get("/avatars" + File.separator + hash)).toAbsolutePath(); + @Override + public String getAvatar(String hash) { + return avatars.containsKey(hash) ? hash : null; } + @Override public void setAvatarForJID(JID jid, String hash) { jidAvatars.put(jid, hash); } + @Override public String getAvatarForJID(JID jid) { if(jidAvatars.containsKey(jid)) { return jidAvatars.get(jid); } else { - return ""; + return null; } } + + // Used for test cases only + public ByteArray getAvatarBytes(String hash) { + return avatars.get(hash); + } + }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/AvatarProvider.java b/src/com/isode/stroke/avatars/AvatarProvider.java index 31fabb4..4618f19 100755 --- a/src/com/isode/stroke/avatars/AvatarProvider.java +++ b/src/com/isode/stroke/avatars/AvatarProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,8 +14,10 @@ package com.isode.stroke.avatars; import com.isode.stroke.signals.Signal1; import com.isode.stroke.jid.JID; -public interface AvatarProvider { +public abstract class AvatarProvider { + + public abstract String getAvatarHash(JID jid); + public abstract void delete(); - public String getAvatarHash(JID jid); public Signal1<JID> onAvatarChanged = new Signal1<JID>(); }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/AvatarStorage.java b/src/com/isode/stroke/avatars/AvatarStorage.java index 98f7e6f..2803006 100755 --- a/src/com/isode/stroke/avatars/AvatarStorage.java +++ b/src/com/isode/stroke/avatars/AvatarStorage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,15 +13,12 @@ package com.isode.stroke.avatars; import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; -import java.nio.file.Path; public interface AvatarStorage { public boolean hasAvatar(String hash); public void addAvatar(String hash, ByteArray avatar); - public ByteArray getAvatar(String hash); - public Path getAvatarPath(String hash); - + public String getAvatar(String hash); public void setAvatarForJID(JID jid, String hash); public String getAvatarForJID(JID jid); }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/CombinedAvatarProvider.java b/src/com/isode/stroke/avatars/CombinedAvatarProvider.java index 0426bd6..5520736 100755 --- a/src/com/isode/stroke/avatars/CombinedAvatarProvider.java +++ b/src/com/isode/stroke/avatars/CombinedAvatarProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -15,34 +15,39 @@ import com.isode.stroke.avatars.AvatarProvider; import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot1; import com.isode.stroke.jid.JID; + import java.util.logging.Logger; import java.util.*; -public class CombinedAvatarProvider implements AvatarProvider { +public class CombinedAvatarProvider extends AvatarProvider { - private Vector<AvatarProvider> providers = new Vector<AvatarProvider>(); + private final Vector<AvatarProvider> providers = new Vector<AvatarProvider>(); private Map<JID, String> avatars = new HashMap<JID, String>(); - private SignalConnection onAvatarChangedConnection_; + private final Map<AvatarProvider, SignalConnection> onAvatarChangedConnections_ = new HashMap<AvatarProvider, SignalConnection>(); private Logger logger_ = Logger.getLogger(this.getClass().getName()); + @Override public String getAvatarHash(JID jid) { return getCombinedAvatarAndCache(jid); } + private final Slot1<JID> onAvatarChangedSlot = new Slot1<JID>() { + @Override public void call(JID p1) {handleAvatarChanged(p1);} + }; + public void addProvider(AvatarProvider provider) { - onAvatarChangedConnection_ = provider.onAvatarChanged.connect(new Slot1<JID>() { - - public void call(JID p1) { - handleAvatarChanged(p1); - } - }); + if (!onAvatarChangedConnections_.containsKey(provider)) { + onAvatarChangedConnections_.put(provider, provider.onAvatarChanged.connect(onAvatarChangedSlot)); + } providers.add(provider); } - public void removeProvider(AvatarProvider provider) { - while(providers.contains(provider)) { - providers.remove(provider); - onAvatarChangedConnection_.disconnect(); + public void delete() { + for (SignalConnection connection : onAvatarChangedConnections_.values()) { + connection.disconnect(); + } + for (AvatarProvider provider : providers) { + provider.delete(); } } diff --git a/src/com/isode/stroke/avatars/DummyAvatarManager.java b/src/com/isode/stroke/avatars/DummyAvatarManager.java index f1dfe41..e27424b 100755 --- a/src/com/isode/stroke/avatars/DummyAvatarManager.java +++ b/src/com/isode/stroke/avatars/DummyAvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,26 +11,13 @@ package com.isode.stroke.avatars; -import com.isode.stroke.avatars.AvatarManager; -import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; -import java.nio.file.*; -import java.io.File; -import java.util.*; -public class DummyAvatarManager implements AvatarManager { +public class DummyAvatarManager extends AvatarManager { - private Map<JID, ByteArray> avatars = new HashMap<JID, ByteArray>(); - - public Path getAvatarPath(JID j) { - return (Paths.get("/avatars" + File.separator + j.toString())).toAbsolutePath(); + @Override + public String getAvatar(final JID j) { + return null; } - public ByteArray getAvatar(JID jid) { - if(avatars.containsKey(jid)) { - return avatars.get(jid); - } else { - return new ByteArray(); - } - } }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/NullAvatarManager.java b/src/com/isode/stroke/avatars/NullAvatarManager.java index e69ed46..9f53cab 100755 --- a/src/com/isode/stroke/avatars/NullAvatarManager.java +++ b/src/com/isode/stroke/avatars/NullAvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,18 +11,12 @@ package com.isode.stroke.avatars; -import com.isode.stroke.avatars.AvatarManager; -import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; -import java.nio.file.*; -public class NullAvatarManager implements AvatarManager { +public class NullAvatarManager extends AvatarManager { - public Path getAvatarPath(JID j) { - return Paths.get(""); - } - - public ByteArray getAvatar(JID jid) { - return new ByteArray(); + @Override + public String getAvatar(JID j) { + return null; } }
\ No newline at end of file diff --git a/src/com/isode/stroke/avatars/OfflineAvatarManager.java b/src/com/isode/stroke/avatars/OfflineAvatarManager.java index fe5de08..b5c909b 100755 --- a/src/com/isode/stroke/avatars/OfflineAvatarManager.java +++ b/src/com/isode/stroke/avatars/OfflineAvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -15,7 +15,7 @@ import com.isode.stroke.avatars.AvatarProvider; import com.isode.stroke.avatars.AvatarStorage; import com.isode.stroke.jid.JID; -public class OfflineAvatarManager implements AvatarProvider { +public class OfflineAvatarManager extends AvatarProvider { private AvatarStorage avatarStorage; @@ -23,12 +23,17 @@ public class OfflineAvatarManager implements AvatarProvider { this.avatarStorage = avatarStorage; } + @Override + public void delete() { + } + + @Override public String getAvatarHash(JID jid) { return avatarStorage.getAvatarForJID(jid); } public void setAvatar(JID jid, String hash) { - if (!getAvatarHash(jid).equals(hash)) { + if (!hash.equals(getAvatarHash(jid))) { avatarStorage.setAvatarForJID(jid, hash); onAvatarChanged.emit(jid); } diff --git a/src/com/isode/stroke/avatars/VCardAvatarManager.java b/src/com/isode/stroke/avatars/VCardAvatarManager.java index b2efcf2..83c8c64 100755 --- a/src/com/isode/stroke/avatars/VCardAvatarManager.java +++ b/src/com/isode/stroke/avatars/VCardAvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -20,17 +20,19 @@ import com.isode.stroke.avatars.AvatarStorage; import com.isode.stroke.muc.MUCRegistry; import com.isode.stroke.vcards.VCardManager; import com.isode.stroke.signals.Slot2; + import java.util.logging.Logger; + import com.isode.stroke.signals.SignalConnection; -public class VCardAvatarManager implements AvatarProvider { +public class VCardAvatarManager extends AvatarProvider { private VCardManager vcardManager_; private AvatarStorage avatarStorage_; private CryptoProvider crypto_; private MUCRegistry mucRegistry_; - private SignalConnection onVCardChangedConnection_; - private Logger logger_ = Logger.getLogger(this.getClass().getName()); + private final SignalConnection onVCardChangedConnection_; + private final Logger logger_ = Logger.getLogger(this.getClass().getName()); public VCardAvatarManager(VCardManager vcardManager, AvatarStorage avatarStorage, CryptoProvider crypto) { this(vcardManager, avatarStorage, crypto, null); @@ -42,13 +44,19 @@ public class VCardAvatarManager implements AvatarProvider { this.crypto_ = crypto; this.mucRegistry_ = mucRegistry; onVCardChangedConnection_ = vcardManager.onVCardChanged.connect(new Slot2<JID, VCard>() { - + @Override public void call(JID p1, VCard vcard) { handleVCardChanged(p1); } }); } + @Override + public void delete() { + onVCardChangedConnection_.disconnect(); + } + + @Override public String getAvatarHash(JID jid) { JID avatarJID = getAvatarJID(jid); String hash = vcardManager_.getPhotoHash(avatarJID); diff --git a/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java b/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java index ce61892..5328fb4 100755 --- a/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java +++ b/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,6 +13,7 @@ package com.isode.stroke.avatars; import java.util.Map; import java.util.HashMap; + import com.isode.stroke.avatars.AvatarProvider; import com.isode.stroke.jid.JID; import com.isode.stroke.elements.VCard; @@ -20,7 +21,6 @@ import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.ErrorPayload; import com.isode.stroke.elements.VCardUpdate; import com.isode.stroke.client.StanzaChannel; -import com.isode.stroke.vcards.GetVCardRequest; import com.isode.stroke.crypto.CryptoProvider; import com.isode.stroke.stringcodecs.Hexify; import com.isode.stroke.avatars.AvatarStorage; @@ -28,20 +28,21 @@ import com.isode.stroke.muc.MUCRegistry; import com.isode.stroke.vcards.VCardManager; import com.isode.stroke.signals.Slot2; import com.isode.stroke.signals.Slot1; + import java.util.logging.Logger; import com.isode.stroke.signals.SignalConnection; -public class VCardUpdateAvatarManager implements AvatarProvider { +public class VCardUpdateAvatarManager extends AvatarProvider { private VCardManager vcardManager_; private AvatarStorage avatarStorage_; private CryptoProvider crypto_; private MUCRegistry mucRegistry_; - private Map<JID, String> avatarHashes_ = new HashMap<JID, String>(); - private SignalConnection onPresenceReceivedConnection; - private SignalConnection onAvailableChangedConnection; - private SignalConnection onVCardChangedConnection; - private Logger logger_ = Logger.getLogger(this.getClass().getName()); + private final Map<JID, String> avatarHashes_ = new HashMap<JID, String>(); + private final SignalConnection onPresenceReceivedConnection; + private final SignalConnection onAvailableChangedConnection; + private final SignalConnection onVCardChangedConnection; + private final Logger logger_ = Logger.getLogger(this.getClass().getName()); public VCardUpdateAvatarManager(VCardManager vcardManager, StanzaChannel stanzaChannel, AvatarStorage avatarStorage, CryptoProvider crypto) { this(vcardManager, stanzaChannel, avatarStorage, crypto, null); @@ -53,25 +54,33 @@ public class VCardUpdateAvatarManager implements AvatarProvider { this.crypto_ = crypto; this.mucRegistry_ = mucRegistry; onPresenceReceivedConnection = stanzaChannel.onPresenceReceived.connect(new Slot1<Presence>() { - + @Override public void call(Presence p1) { handlePresenceReceived(p1); } }); onAvailableChangedConnection = stanzaChannel.onAvailableChanged.connect(new Slot1<Boolean>() { - + @Override public void call(Boolean b) { handleStanzaChannelAvailableChanged(b); } }); onVCardChangedConnection = vcardManager_.onVCardChanged.connect(new Slot2<JID, VCard>() { - + @Override public void call(JID p1, VCard vcard) { handleVCardChanged(p1, vcard); } }); } + + @Override + public void delete() { + onPresenceReceivedConnection.disconnect(); + onAvailableChangedConnection.disconnect(); + onVCardChangedConnection.disconnect(); + } + @Override public String getAvatarHash(JID jid) { if(avatarHashes_.containsKey(jid)) { return avatarHashes_.get(jid); diff --git a/test/com/isode/stroke/avatars/AvatarManagerImplTest.java b/test/com/isode/stroke/avatars/AvatarManagerImplTest.java index 7ee10fd..339ccf4 100644 --- a/test/com/isode/stroke/avatars/AvatarManagerImplTest.java +++ b/test/com/isode/stroke/avatars/AvatarManagerImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,31 +11,30 @@ package com.isode.stroke.avatars; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Vector; + import org.junit.Before; import org.junit.Test; -import java.util.Vector; -import com.isode.stroke.elements.VCardUpdate; -import com.isode.stroke.elements.Presence; + +import com.isode.stroke.base.ByteArray; +import com.isode.stroke.client.DummyStanzaChannel; +import com.isode.stroke.crypto.CryptoProvider; +import com.isode.stroke.crypto.JavaCryptoProvider; import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.VCard; -import com.isode.stroke.avatars.VCardUpdateAvatarManager; -import com.isode.stroke.avatars.VCardAvatarManager; -import com.isode.stroke.avatars.AvatarMemoryStorage; -import com.isode.stroke.vcards.VCardMemoryStorage; -import com.isode.stroke.vcards.VCardManager; +import com.isode.stroke.elements.VCardUpdate; +import com.isode.stroke.jid.JID; import com.isode.stroke.muc.MUCRegistry; import com.isode.stroke.queries.IQRouter; -import com.isode.stroke.client.DummyStanzaChannel; -import com.isode.stroke.crypto.JavaCryptoProvider; -import com.isode.stroke.crypto.CryptoProvider; import com.isode.stroke.stringcodecs.Hexify; -import com.isode.stroke.jid.JID; -import com.isode.stroke.base.ByteArray; -import com.isode.stroke.signals.SignalConnection; -import com.isode.stroke.signals.Slot1; +import com.isode.stroke.vcards.VCardManager; +import com.isode.stroke.vcards.VCardMemoryStorage; public class AvatarManagerImplTest { @@ -75,8 +74,8 @@ public class AvatarManagerImplTest { public void testGetSetAvatar() { /* initially we have no knowledge of the user or their avatar */ JID personJID = new JID("person@domain.com/theperson"); - ByteArray avatar = avatarManager.getAvatar(personJID.toBare()); - assertTrue(avatar.getSize() == 0); + String avatar = avatarManager.getAvatar(personJID.toBare()); + assertTrue(avatar == null); /* notify the 'owner' JID that our avatar has changed */ @@ -109,8 +108,8 @@ public class AvatarManagerImplTest { /* check hash through avatarManager that it received the correct photo */ - ByteArray reportedAvatar = avatarManager.getAvatar(personJID.toBare()); - assertEquals(fullAvatar.toString(), reportedAvatar.toString()); + String reportedAvatar = avatarManager.getAvatar(personJID.toBare()); + assertEquals(fullAvatar.toString(), avatarStorage.getAvatarBytes(reportedAvatar).toString()); /* send new presence to notify of blank avatar */ @@ -143,6 +142,6 @@ public class AvatarManagerImplTest { /* check hash through avatarManager that it received the correct photo */ reportedAvatar = avatarManager.getAvatar(personJID.toBare()); - assertEquals(blankAvatar.toString(), reportedAvatar.toString()); + assertNull(reportedAvatar); // Empty photo => empty hash => null Avatar } }
\ No newline at end of file diff --git a/test/com/isode/stroke/avatars/VCardAvatarManagerTest.java b/test/com/isode/stroke/avatars/VCardAvatarManagerTest.java index 56121ac..303ed1b 100755 --- a/test/com/isode/stroke/avatars/VCardAvatarManagerTest.java +++ b/test/com/isode/stroke/avatars/VCardAvatarManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -30,7 +30,6 @@ import com.isode.stroke.client.DummyStanzaChannel; import com.isode.stroke.crypto.JavaCryptoProvider; import com.isode.stroke.crypto.CryptoProvider; import com.isode.stroke.stringcodecs.Hexify; -import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot1; import com.isode.stroke.elements.IQ; @@ -59,9 +58,7 @@ public class VCardAvatarManagerTest { private String avatar1Hash; private Vector<JID> changes; private JID user1; - private JID user2; private CryptoProvider crypto; - private SignalConnection onAvatarChangedConnection; @Before public void setUp() { @@ -78,12 +75,11 @@ public class VCardAvatarManagerTest { avatar1Hash = Hexify.hexify(crypto.getSHA1Hash(avatar1)); changes = new Vector<JID>(); user1 = new JID("user1@bar.com/bla"); - user2 = new JID("user2@foo.com/baz"); } private VCardAvatarManager createManager() { VCardAvatarManager result = new VCardAvatarManager(vcardManager, avatarStorage, crypto, mucRegistry); - onAvatarChangedConnection = result.onAvatarChanged.connect(new Slot1<JID>() { + result.onAvatarChanged.connect(new Slot1<JID>() { public void call(JID j1) { handleAvatarChanged(j1); @@ -143,7 +139,7 @@ public class VCardAvatarManagerTest { assertNotNull(result); assertEquals(avatar1Hash, result); assertTrue(avatarStorage.hasAvatar(avatar1Hash)); - assertEquals(avatar1, avatarStorage.getAvatar(avatar1Hash)); + assertEquals(avatar1, avatarStorage.getAvatarBytes(avatar1Hash)); } @Test diff --git a/test/com/isode/stroke/avatars/VCardUpdateAvatarManagerTest.java b/test/com/isode/stroke/avatars/VCardUpdateAvatarManagerTest.java index 1030d5d..95ccf7a 100755 --- a/test/com/isode/stroke/avatars/VCardUpdateAvatarManagerTest.java +++ b/test/com/isode/stroke/avatars/VCardUpdateAvatarManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -23,7 +23,6 @@ import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.IQ; import com.isode.stroke.elements.VCard; import com.isode.stroke.avatars.VCardUpdateAvatarManager; -import com.isode.stroke.avatars.VCardAvatarManager; import com.isode.stroke.avatars.AvatarMemoryStorage; import com.isode.stroke.vcards.VCardMemoryStorage; import com.isode.stroke.vcards.VCardManager; @@ -35,7 +34,6 @@ import com.isode.stroke.crypto.CryptoProvider; import com.isode.stroke.stringcodecs.Hexify; import com.isode.stroke.jid.JID; import com.isode.stroke.base.ByteArray; -import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot1; public class VCardUpdateAvatarManagerTest { @@ -62,7 +60,6 @@ public class VCardUpdateAvatarManagerTest { private JID user1; private JID user2; private CryptoProvider crypto; - private SignalConnection onAvatarChangedConnection; @Before public void setUp() { @@ -84,7 +81,7 @@ public class VCardUpdateAvatarManagerTest { private VCardUpdateAvatarManager createManager() { VCardUpdateAvatarManager result = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, crypto, mucRegistry); - onAvatarChangedConnection = result.onAvatarChanged.connect(new Slot1<JID>() { + result.onAvatarChanged.connect(new Slot1<JID>() { public void call(JID j1) { handleAvatarChanged(j1); @@ -133,7 +130,7 @@ public class VCardUpdateAvatarManagerTest { assertNotNull(hash); assertEquals(avatar1Hash, hash); assertTrue(avatarStorage.hasAvatar(avatar1Hash)); - assertEquals(avatar1, avatarStorage.getAvatar(avatar1Hash)); + assertEquals(avatar1, avatarStorage.getAvatarBytes(avatar1Hash)); } @Test |