ProviderStack { public Iterator<T> getIterator() { return new Iterator<T>() { protected ListIterator<ProviderHolder<T>> it = null; public synchronized boolean hasNext() { if (it == null) { it = providers.listIterator(); } return it.hasNext(); } public synchronized T next() { if (it == null) { it = providers.listIterator(); } T t = null; while (it.hasNext()) { ProviderHolder<T> holder = it.next(); t = holder.getProvider(); if (t != null) { break; } } if (t == null) { throw new NoSuchElementException("No more providers remain with valid weak references"); } return t; } public void remove() { it.remove(); } }; } ProviderStack();  ProviderStack(ServiceManager serviceManager, Class<T> providerType);  ProviderStack(T[] currentProviders); int addProvider(T provider); boolean removeProvider(final int position); boolean removeProvider(T provider); List<T> getProviders(); List<ProviderHolder<T>> getProviderHolders(); Iterator<T> getIterator(); T getProvider(final int position); ProviderHolder<T> getProviderHolder(final int position); int size(); void clear();  }
@Test public void testGetIterator() { ProviderStack<Provider> providers = new ProviderStack<Provider>(new Provider[] { new UnorderedProvider("ccc"), new UnorderedProvider("ddd"), new OrderedProvider("bbb", 5), new OrderedProvider("aaa", 2) }); assertNotNull(providers.hashCode()); assertNotNull(providers.toString()); assertEquals(4, providers.size()); Iterator<Provider> it = providers.getIterator(); assertNotNull(it); assertTrue(it.hasNext()); assertNotNull(it.next()); assertTrue(it.hasNext()); assertNotNull(it.next()); assertTrue(it.hasNext()); assertNotNull(it.next()); assertTrue(it.hasNext()); assertNotNull(it.next()); assertFalse(it.hasNext()); providers = new ProviderStack<Provider>(); it = providers.getIterator(); assertNotNull(it); assertFalse(it.hasNext()); it = null; providers.clear(); providers = null; }