DefaultPluginContext implements PluginContext { @Override public Collection<PluginRef> getAllPlugins() { final ArrayList<PluginRef> plugins = new ArrayList<>(); for (Map.Entry<String, Object> entry : registry.entrySet()) { plugins.add(PluginRef.of(entry.getValue(), entry.getKey())); } return plugins; } DefaultPluginContext();  DefaultPluginContext(Map<String, Object> registry); @Override @Nullable T getPlugin(String pluginName); @Override @Nullable T getPlugin(Class<T> pluginClass); @Override Collection<PluginRef> getAllPlugins(); @Override void addPlugin(T plugin); @Override void addPlugin(String name, T plugin); @Override @Nullable T removePlugin(T plugin); @Override @Nullable T removePlugin(String pluginName); @Override boolean hasPlugin(String pluginName); @Override boolean hasPlugin(Class<T> pluginClass);  }
@Test public void shouldRetrieveAllThePlugins() throws Exception { registry.put("test", plugin); registry.put("optional", optionalPlugin); final List<PluginRef> all = (List<PluginRef>) context.getAllPlugins(); assertFalse(all.isEmpty()); for (int i = 0; i < all.size(); i++) { switch (i) { case 0: { final PluginRef ref = all.get(i); assertEquals("test", ref.getName()); assertEquals(plugin, ref.get()); assertEquals(TestPlugin.class, ref.getType()); break; } case 1: { final PluginRef ref = all.get(i); assertEquals("optional", ref.getName()); assertEquals(optionalPlugin, ref.get()); assertEquals(OptionalPlugin.class, ref.getType()); break; } } } }