### Question:
ProjectSorter { public static List<Project> getSortedProjects( Collection<Project> projects, Logger logger ) { DAG dag = new DAG(); Map<String, Project> projectMap = new HashMap<String, Project>(); for ( Project project : projects ) { String id = getProjectId( project ); if ( dag.getVertex( id ) != null ) { logger.warn( "Project '" + id + "' is duplicated in the reactor." ); } dag.addVertex( id ); projectMap.put( id, project ); } for ( Project project : projects ) { String id = getProjectId( project ); String projectGroupId = "[" + project.getProjectGroup().getId() + "]"; for ( Object o : project.getDependencies() ) { ProjectDependency dependency = (ProjectDependency) o; String dependencyId = projectGroupId + ":" + getDependencyId( dependency ); if ( dag.getVertex( dependencyId ) != null ) { try { dag.addEdge( id, dependencyId ); } catch ( CycleDetectedException e ) { logger.warn( "Ignore cycle detected in project dependencies: " + e.getMessage() ); } } } ProjectDependency parent = project.getParent(); if ( parent != null ) { String parentId = projectGroupId + ":" + getDependencyId( parent ); if ( dag.getVertex( parentId ) != null ) { if ( dag.hasEdge( parentId, id ) ) { dag.removeEdge( parentId, id ); } try { dag.addEdge( id, parentId ); } catch ( CycleDetectedException e ) { logger.warn( "Ignore cycle detected in project parent: " + e.getMessage() ); } } } } List<Project> sortedProjects = new ArrayList<Project>(); for ( Object o : TopologicalSorter.sort( dag ) ) { String id = (String) o; sortedProjects.add( projectMap.get( id ) ); } return sortedProjects; } private  ProjectSorter(); static List<Project> getSortedProjects( Collection<Project> projects, Logger logger );  }### Answer:
@Test public void testBasicNestedProjectStructure() throws Exception { List<Project> list = new ArrayList<Project>(); Project top = getNewProject( "top" ); list.add( top ); Project c1 = getNewProject( "c1" ); c1.setParent( generateProjectDependency( top ) ); list.add( c1 ); Project c2 = getNewProject( "c2" ); c2.setParent( generateProjectDependency( top ) ); c2.setDependencies( Collections.singletonList( generateProjectDependency( c1 ) ) ); list.add( c2 ); List<Project> sortedList = ProjectSorter.getSortedProjects( list, null ); assertNotNull( sortedList ); Project p1 = sortedList.get( 0 ); assertEquals( top.getArtifactId(), p1.getArtifactId() ); Project p2 = sortedList.get( 1 ); assertEquals( c1.getArtifactId(), p2.getArtifactId() ); Project p3 = sortedList.get( 2 ); assertEquals( c2.getArtifactId(), p3.getArtifactId() ); }