DefaultPluginContext implements PluginContext { @Override @Nullable public <T> T getPlugin(String pluginName) { Objects.requireNonNull(pluginName, "Plugin name to lookup cannot be null"); if (registry.containsKey(pluginName)) { return (T) registry.get(pluginName); } return null; } 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 shouldRetrievePluginFromName() { registry.put("test", plugin); final TestPlugin test = context.getPlugin("test"); assertTrue(registry.containsKey("test")); assertEquals(plugin, test); }
@Test public void shouldRetrievePluginFromClass() { registry.put("test", plugin); final TestPlugin test = context.getPlugin(TestPlugin.class); assertTrue(registry.containsKey("test")); assertEquals(plugin, test); }
@Test public void shouldRetrievePluginFromInterface() { registry.put("test", plugin); final TestInterface test = context.getPlugin(TestInterface.class); assertTrue(registry.containsKey("test")); assertEquals(plugin, test); }
@Test public void shouldRetrievePluginFromSuperclass() { registry.put("test", plugin); final TestSuperclass test = context.getPlugin(TestSuperclass.class); assertTrue(registry.containsKey("test")); assertEquals(plugin, test); }