ScopedCollection implements ScopeSubscriber, Collection<E> { public boolean add(final E e) { needRecreatedView = true; final ScopedCollectionItem<E> collection = getTopmostCollection(); return collection.add(e); } ScopedCollection(final ScopeObserver scopeObserver); 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 testAdd() { ScopedCollection<String> collection = new ScopedCollection<String>(observer); String test1 = "test1"; String test2 = "test2"; Assert.assertFalse(collection.contains(test1)); Assert.assertFalse(collection.contains(test2)); collection.add(test1); collection.add(test2); Assert.assertTrue(collection.contains(test1)); Assert.assertTrue(collection.contains(test2)); Assert.assertEquals(2, collection.size()); collection.enterScope(Scope.SESSION, Scope.DOCUMENT); String test3 = "test3"; collection.add(test3); Assert.assertTrue(collection.contains(test1)); Assert.assertTrue(collection.contains(test2)); Assert.assertTrue(collection.contains(test3)); Assert.assertEquals(3, collection.size()); collection.exitScope(Scope.DOCUMENT, Scope.SESSION); Assert.assertTrue(collection.contains(test1)); Assert.assertTrue(collection.contains(test2)); Assert.assertFalse(collection.contains(test3)); Assert.assertEquals(2, collection.size()); }