diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-03-10 10:46:58 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-10 10:50:34 (GMT) |
commit | dcc9d6b81d73f42db35c6e26a91e029a117289e1 (patch) | |
tree | d7d9ceb34c98b016b9c0030f2ff160115c201cda /test | |
parent | 8f112a856705b800d1a8797bec5d9396a9c00b34 (diff) | |
download | stroke-dcc9d6b81d73f42db35c6e26a91e029a117289e1.zip stroke-dcc9d6b81d73f42db35c6e26a91e029a117289e1.tar.bz2 |
Fix BlockListImpl logic and add unit test.
As per swiften patch 'Fix notification logic for signals in BlockListImpl'
(4455c20085834098f6d9aa872db3115d466e7004). Fix the logic in the BlockListImpl
class and add a unit test for it.
Test-information: Unit tests pass ok.
Change-Id: I739d1febb2cf728ff00c132a00adb2f7f144b739
Diffstat (limited to 'test')
-rw-r--r-- | test/com/isode/stroke/client/BlockListImplTest.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/test/com/isode/stroke/client/BlockListImplTest.java b/test/com/isode/stroke/client/BlockListImplTest.java new file mode 100644 index 0000000..74eeecb --- /dev/null +++ b/test/com/isode/stroke/client/BlockListImplTest.java @@ -0,0 +1,99 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.client; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import org.junit.Before; +import org.junit.Test; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.signals.Slot1; + +public class BlockListImplTest { + + private final BlockListImpl blockList_ = new BlockListImpl(); + private final List<JID> addedJIDs_ = new ArrayList<JID>(); + private final List<JID> removedJIDs_ = new ArrayList<JID>(); + + @Before + public void setUp() { + blockList_.addItem(new JID("a@example.com")); + blockList_.addItem(new JID("b@example.com")); + + blockList_.onItemAdded.connect(new Slot1<JID>() { + + @Override + public void call(JID jid) { + handleBlockListItemAdded(jid); + } + + }); + + blockList_.onItemRemoved.connect(new Slot1<JID>() { + + @Override + public void call(JID jid) { + handleBlockListItemRemoved(jid); + } + + }); + } + + @Test + public void testSetItemsToSubset() { + Vector<JID> subset = new Vector<JID>(); + subset.add(new JID("a@example.com")); + + blockList_.setItems(subset); + + assertEquals(0, addedJIDs_.size()); + assertEquals(1, removedJIDs_.size()); + } + + @Test + public void testSetItemsToSuperset() { + Vector<JID> superset = new Vector<JID>(); + superset.add(new JID("a@example.com")); + superset.add(new JID("b@example.com")); + superset.add(new JID("c@example.com")); + + blockList_.setItems(superset); + + assertEquals(1, addedJIDs_.size()); + assertEquals(0, removedJIDs_.size()); + } + + @Test + public void testSetItemsAllDifferent() { + Vector<JID> newBlockList = new Vector<JID>(); + newBlockList.add(new JID("x@example.com")); + newBlockList.add(new JID("y@example.com")); + newBlockList.add(new JID("z@example.com")); + + blockList_.setItems(newBlockList); + + assertEquals(3, addedJIDs_.size()); + assertEquals(2, removedJIDs_.size()); + } + + private void handleBlockListItemAdded(JID jid) { + addedJIDs_.add(jid); + } + + private void handleBlockListItemRemoved(JID jid) { + removedJIDs_.add(jid); + } + +} |