@Test
public void test_sort_plugins_with_dependencies()
{

    Plugin1 plugin1 = new Plugin1(); // declare P2 as dependent
    Plugin2 plugin2 = new Plugin2();
    Plugin3 plugin3 = new Plugin3(); // declare P2 as required and declare P4 as dependent
    Plugin4 plugin4 = new Plugin4();
    List<Plugin> plugins = Lists.newArrayList(plugin4, plugin2, plugin3, plugin1);
    FacetRegistry facetRegistry = new FacetRegistry(plugins);
    PluginSortStrategy strategy = new PluginSortStrategy(facetRegistry, plugins);
    List<Plugin> orderedPlugins = strategy.sortPlugins();
    // Assert the old order
    assertThat(plugins).containsSequence(plugin4, plugin2, plugin3, plugin1);
    // Assert the new order
    assertThat(orderedPlugins).containsSequence(plugin1, plugin2, plugin3, plugin4);
}