Drawers { @Pure public static synchronized Iterator<Drawer<?>> getAllDrawers() { if (iterable == null) { iterable = getDrawerProvidingService(); } return iterable.iterator(); } private  Drawers(); static synchronized void reload(); @Pure static synchronized Iterator<Drawer<?>> getAllDrawers(); static synchronized void setBackedDrawers(Iterable<Drawer<?>> drawers); @SuppressWarnings("unchecked") @Pure static synchronized ServiceLoader<Drawer<?>> getDrawerProvidingService(); @SuppressWarnings("unchecked") @Pure static synchronized Drawer<T> getDrawerFor(Class<? extends T> type); @Pure @SuppressWarnings("unchecked") static synchronized Drawer<? super T> getDrawerFor(T instance);  }
@Test public void getAllDrawers() { Iterator<Drawer<?>> iterator1 = Drawers.getAllDrawers(); assertNotNull(iterator1); assertTrue(iterator1.hasNext()); Drawer<?> d1 = iterator1.next(); assertTrue(iterator1.hasNext()); Drawer<?> d2 = iterator1.next(); assertTrue(iterator1.hasNext()); Drawer<?> d3 = iterator1.next(); assertTrue(iterator1.hasNext()); Drawer<?> d4 = iterator1.next(); assertTrue(iterator1.hasNext()); Drawer<?> d5 = iterator1.next(); assertFalse(iterator1.hasNext()); assertNotNull(d1); assertNotNull(d2); assertNotNull(d3); assertNotNull(d4); assertNotNull(d5); Set<Class<? extends Drawer<?>>> types = new HashSet<>(); types.add(MyDrawer1.class); types.add(MyDrawer2.class); types.add(MyDrawer3.class); types.add(MyDrawer4.class); types.add(ContDrawer1.class); assertTrue(types.remove(d1.getClass())); assertTrue(types.remove(d2.getClass())); assertTrue(types.remove(d3.getClass())); assertTrue(types.remove(d4.getClass())); assertTrue(types.remove(d5.getClass())); }