InstanceHelpers { public static List<Instance> buildHierarchicalList( Instance inst ) { List<Instance> instanceList = new ArrayList<> (); List<Instance> todo = new ArrayList<> (); if( inst != null ) todo.add( inst ); while( ! todo.isEmpty()) { Instance current = todo.remove( 0 ); instanceList.add( current ); todo.addAll( current.getChildren()); } return instanceList; } private  InstanceHelpers(); static String computeInstancePath( Instance inst ); static boolean haveSamePath( Instance i1, Instance i2 ); static String findInstanceName( String instancePath ); static List<Instance> buildHierarchicalList( Instance inst ); static void insertChild( Instance parent, Instance child ); static Map<String,String> findAllExportedVariables( Instance instance ); static Instance findInstanceByPath( AbstractApplication application, String instancePath ); static Instance findInstanceByPath( Instance rootInstance, String instancePath ); static List<Instance> findInstancesByComponentName( AbstractApplication application, String componentName ); static Instance findRootInstance( Instance instance ); static Instance findScopedInstance( Instance instance ); static List<Instance> findAllScopedInstances( AbstractApplication app ); static List<Instance> getAllInstances( AbstractApplication application ); static boolean tryToInsertChildInstance( AbstractApplication application, Instance parentInstance, Instance childInstance ); static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ); static File findInstanceDirectoryOnAgent( Instance instance ); static int countInstances( String instancePath ); static Instance replicateInstance( Instance instance ); static boolean isTarget( Instance instance ); static void removeOffScopeInstances( Instance scopedInstance ); static String findRootInstancePath( String scopedInstancePath ); static void fixOverriddenExports( Instance instance );  }
@Test public void testBuildHierarchicalList() { List<Instance> instances = InstanceHelpers.buildHierarchicalList( null ); Assert.assertEquals( 0, instances.size()); Instance instance_1 = new Instance( "inst 1" ); instances = InstanceHelpers.buildHierarchicalList( instance_1 ); Assert.assertEquals( 1, instances.size()); Assert.assertEquals( instance_1, instances.get( 0 )); Instance instance_1_1 = new Instance( "inst 11" ); InstanceHelpers.insertChild( instance_1, instance_1_1 ); instances = InstanceHelpers.buildHierarchicalList( instance_1 ); Assert.assertEquals( 2, instances.size()); Assert.assertEquals( instance_1, instances.get( 0 )); Assert.assertEquals( instance_1_1, instances.get( 1 )); Instance instance_1_2 = new Instance( "inst 12" ); InstanceHelpers.insertChild( instance_1, instance_1_2 ); Instance instance_1_1_1 = new Instance( "inst 111" ); InstanceHelpers.insertChild( instance_1_1, instance_1_1_1 ); Instance instance_1_2_1 = new Instance( "inst 121" ); InstanceHelpers.insertChild( instance_1_2, instance_1_2_1 ); instances = InstanceHelpers.buildHierarchicalList( instance_1 ); Assert.assertEquals( 5, instances.size()); Assert.assertEquals( instance_1, instances.get( 0 )); Assert.assertEquals( instance_1_1, instances.get( 1 )); Assert.assertEquals( instance_1_2, instances.get( 2 )); Assert.assertEquals( instance_1_1_1, instances.get( 3 )); Assert.assertEquals( instance_1_2_1, instances.get( 4 )); }