PluginManager extends HasEventBus { public static PluginManager getInstance() { if (ourInstance == null) { ourInstance = new PluginManager(); } return ourInstance; } private  PluginManager(); static PluginManager getInstance(); void loadPlugins(); void unloadPlugins(); WeakReference<T> getContext(String id); static final Logger logger; }
@Test public void testDependenciesSortList() { PluginManager manager = PluginManager.getInstance(); try { Method sort = manager.getClass().getDeclaredMethod("sortDependencies", Iterable.class); sort.setAccessible(true); List<Plugin> plugins = new ArrayList<>(); plugins.add(new PluginA()); plugins.add(new PluginB()); plugins.add(new PluginC()); plugins.add(new PluginD()); plugins.add(new PluginE()); plugins.add(new PluginF()); plugins.add(new PluginG()); Collection<? extends Plugin> sortPlugins = (Collection<? extends Plugin>) sort.invoke(manager, plugins); StringBuilder actual = new StringBuilder(); for (Plugin plugin : sortPlugins) { actual.append(plugin.getPluginInfo().getId()); } TestCase.assertEquals("GBCDFEA", actual.toString()); } catch (NoSuchMethodException e) { e.printStackTrace(); TestCase.fail(); } catch (InvocationTargetException e) { e.printStackTrace(); TestCase.fail(); } catch (IllegalAccessException e) { e.printStackTrace(); TestCase.fail(); } }