ComponentRelationship { public void sort(LinkedList<String> componentsOrder) { for (String dep : dependents) { int targetIndex = index(componentsOrder, target); int depIndex = index(componentsOrder, dep); if (depIndex > targetIndex) { componentsOrder.add(targetIndex, dep); componentsOrder.remove(depIndex + 1); } } } private  ComponentRelationship(String target, List<String> dependents); static ComponentRelationshipBuilder component(String componentName); void inject(Map<String, SystemComponent> components); void sort(LinkedList<String> componentsOrder);  }
@Test public void sort() { ComponentRelationship r1 = ComponentRelationship.component("A").using("B", "C"); LinkedList<String> componentOrder = new LinkedList<>(Arrays.asList("A", "B", "C")); r1.sort(componentOrder); assertThat(componentOrder).isEqualTo(Arrays.asList("B", "C", "A")); }