ProviderStack { public int addProvider(T provider) { if (provider == null) { throw new IllegalArgumentException("provider to add cannot be null"); } int position = 0; refresh(); int providerOrder = 0; if (provider instanceof NotProvider) { throw new IllegalArgumentException("Cannot place anything that implements NotProvider into the provider stack, failure for: " + provider); } if (provider instanceof OrderedService) { providerOrder = ((OrderedService)provider).getOrder(); } providers.add( new ProviderHolder<T>(provider) ); if (providerOrder > 0) { Collections.sort(this.providers, new ProviderStackComparator()); } return position; } 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 testAddProvider() { 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()); List<Provider> l = providers.getProviders(); assertEquals("aaa", l.get(0).getPrefix()); assertEquals("bbb", l.get(1).getPrefix()); assertEquals("ccc", l.get(2).getPrefix()); assertEquals("ddd", l.get(3).getPrefix()); Provider p5 = new UnorderedProvider("eee"); providers.addProvider( p5 ); assertEquals(5, providers.size()); l = providers.getProviders(); assertEquals("aaa", l.get(0).getPrefix()); assertEquals("bbb", l.get(1).getPrefix()); assertEquals("ccc", l.get(2).getPrefix()); assertEquals("ddd", l.get(3).getPrefix()); assertEquals("eee", l.get(4).getPrefix()); Provider p6 = new OrderedProvider("ab6", 3); providers.addProvider( p6 ); assertEquals(6, providers.size()); l = providers.getProviders(); assertEquals("aaa", l.get(0).getPrefix()); assertEquals("ab6", l.get(1).getPrefix()); assertEquals("bbb", l.get(2).getPrefix()); assertEquals("ccc", l.get(3).getPrefix()); assertEquals("ddd", l.get(4).getPrefix()); assertEquals("eee", l.get(5).getPrefix()); Provider p7 = new OrderedProvider("bc7", 6); providers.addProvider( p7 ); assertEquals(7, providers.size()); l = providers.getProviders(); assertEquals("aaa", l.get(0).getPrefix()); assertEquals("ab6", l.get(1).getPrefix()); assertEquals("bbb", l.get(2).getPrefix()); assertEquals("bc7", l.get(3).getPrefix()); assertEquals("ccc", l.get(4).getPrefix()); assertEquals("ddd", l.get(5).getPrefix()); assertEquals("eee", l.get(6).getPrefix()); l = null; p5 = p6 = p7 = null; providers.clear(); providers = null; }