### Question:
AAICreateTasks { protected int calculateUnusedIndex(TreeSet<Integer> moduleIndices, int nullIndexFound) { Integer[] temp = new Integer[moduleIndices.size() + nullIndexFound]; Integer[] array = moduleIndices.toArray(temp); int result = 0; for (int i = 0; i < array.length; i++, result++) { if (Integer.valueOf(result) != array[i]) { if (nullIndexFound > 0) { nullIndexFound--; i--; } else { break; } } } return result; }  void createServiceInstance(BuildingBlockExecution execution); void createServiceSubscription(BuildingBlockExecution execution); void createProject(BuildingBlockExecution execution); void createOwningEntity(BuildingBlockExecution execution); void createVnf(BuildingBlockExecution execution); void createPnf(BuildingBlockExecution execution); void createPlatformForNetwork(BuildingBlockExecution execution); void createPlatform(BuildingBlockExecution execution); List<String> splitCDL(String str); void createLineOfBusiness(BuildingBlockExecution execution); void createLineOfBusinessForNetwork(BuildingBlockExecution execution); void createVolumeGroup(BuildingBlockExecution execution); void createVfModule(BuildingBlockExecution execution); void connectVfModuleToVolumeGroup(BuildingBlockExecution execution); void createNetwork(BuildingBlockExecution execution); void createCustomer(BuildingBlockExecution execution); void createNetworkCollection(BuildingBlockExecution execution); void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution); void connectNetworkToTenant(BuildingBlockExecution execution); void connectNetworkToCloudRegion(BuildingBlockExecution execution); void connectVnfToCloudRegion(BuildingBlockExecution execution); void connectVnfToTenant(BuildingBlockExecution execution); void connectNetworkToNetworkCollectionServiceInstance(BuildingBlockExecution execution); void connectNetworkToNetworkCollectionInstanceGroup(BuildingBlockExecution execution); void createConfiguration(BuildingBlockExecution execution); void createInstanceGroupVnf(BuildingBlockExecution execution); void createNetworkPolicies(BuildingBlockExecution execution);  }### Answer:
@Test public void calculateUnusedIndexTest() { TreeSet<Integer> a = new TreeSet<>(Arrays.asList(0, 1, 3)); TreeSet<Integer> b = new TreeSet<>(Arrays.asList(0, 1, 8)); TreeSet<Integer> c = new TreeSet<>(Arrays.asList(0, 2, 4)); assertEquals(2, aaiCreateTasks.calculateUnusedIndex(a, 0)); assertEquals(5, aaiCreateTasks.calculateUnusedIndex(a, 2)); assertEquals(4, aaiCreateTasks.calculateUnusedIndex(b, 2)); assertEquals(3, aaiCreateTasks.calculateUnusedIndex(b, 1)); assertEquals(5, aaiCreateTasks.calculateUnusedIndex(c, 2)); assertEquals(9, aaiCreateTasks.calculateUnusedIndex(c, 6)); assertEquals(1, aaiCreateTasks.calculateUnusedIndex(c, 0)); }