ScopedSet implements ScopeSubscriber, Set<E> { public boolean remove(final Object o) { if (!contains(o)) { return false; } view.remove(o); for (ScopedCollectionItem<E> item : stack) { if (item.remove(o)) { return true; } } return false; } ScopedSet(final ScopeObserver scopeObserver); void addScopedSetObserver(final ScopedSetObserver<E> obs); void removeScopedSetObserver(final ScopedSetObserver<E> obs); void close(); void enterScope(final Scope previous, final Scope next); void exitScope(final Scope previous, final Scope next); boolean add(final E e); boolean addAll(final Collection<? extends E> c); void clear(); boolean contains(final Object o); boolean containsAll(final Collection<?> c); boolean isEmpty(); Iterator<E> iterator(); boolean remove(final Object o); boolean removeAll(final Collection<?> c); boolean retainAll(final Collection<?> c); int size(); Object[] toArray(); T[] toArray(final T[] a);  }
@Test public void testRemove() { final ScopedSet<String> set = new ScopedSet<String>(observer); final String test1 = "test1"; final String test2 = "test2"; final String test3 = "test2"; Assert.assertFalse(set.contains(test1)); Assert.assertFalse(set.contains(test2)); set.add(test1); set.add(test2); Assert.assertTrue(set.contains(test1)); Assert.assertTrue(set.contains(test2)); Assert.assertEquals(2, set.size()); set.add(test3); Assert.assertTrue(set.contains(test1)); Assert.assertTrue(set.contains(test2)); Assert.assertEquals(2, set.size()); set.enterScope(Scope.SESSION, Scope.DOCUMENT); final String test4 = "test4"; set.add(test4); set.add(test3); Assert.assertTrue(set.contains(test1)); Assert.assertTrue(set.contains(test2)); Assert.assertTrue(set.contains(test4)); Assert.assertEquals(3, set.size()); set.remove(test1); Assert.assertFalse("'" + test1 + "' should no longr be in set", set.contains(test1)); Assert.assertTrue(set.contains(test2)); Assert.assertTrue(set.contains(test4)); Assert.assertEquals(2, set.size()); set.remove(test2); Assert.assertFalse(set.contains(test1)); Assert.assertFalse(set.contains(test2)); Assert.assertTrue(set.contains(test4)); Assert.assertEquals(1, set.size()); set.remove(test4); Assert.assertFalse(set.contains(test1)); Assert.assertFalse(set.contains(test2)); Assert.assertFalse(set.contains(test4)); Assert.assertEquals(0, set.size()); }