### Question:
StorageLocationManagerImpl implements StorageLocationManager { @Override public List<StorageLocation> listAvailableStorageLocations(PID pid) { List<PID> ancestors = pathFactory.getAncestorPids(pid); ancestors.add(pid); return new ArrayList<>(ancestors.stream() .limit(COLLECTION_PATH_DEPTH + 1l) .map(pidToStorageLocation::get) .filter(Objects::nonNull) .collect(Collectors.toSet())); } StorageLocationManagerImpl(); void init(); @Override StorageLocation getDefaultStorageLocation(PID pid); @Override List<StorageLocation> listAvailableStorageLocations(PID pid); @Override StorageLocation getStorageLocation(PID pid); @Override StorageLocation getStorageLocation(RepositoryObject repoObj); @Override StorageLocation getStorageLocationById(String id); @Override StorageLocation getStorageLocationForUri(URI uri); void setPathFactory(ContentPathFactory pathFactory); void setRepositoryObjectLoader(RepositoryObjectLoader repositoryObjectLoader); void setConfigPath(String configPath); void setMappingPath(String mappingPath);  }### Answer:
@Test public void listAvailableStorageLocationsFromAncestor() throws Exception { PID unitPid = makePid(); mockAncestors(unitPid, getContentRootPid()); helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE); helper.addMapping(getContentRootPid().getId(), LOC1_ID); initializeManager(); List<StorageLocation> locs = locManager.listAvailableStorageLocations(unitPid); assertEquals(1, locs.size()); assertIsLocation1(locs.get(0)); }
@Test public void listAvailableStorageLocationsNoneAvailable() throws Exception { PID unitPid = makePid(); mockAncestors(unitPid, getContentRootPid()); initializeManager(); List<StorageLocation> locs = locManager.listAvailableStorageLocations(unitPid); assertEquals(0, locs.size()); }
@Test public void listAvailableStorageLocationsMultiple() throws Exception { PID unitPid = makePid(); mockAncestors(unitPid, getContentRootPid()); helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE); helper.addStorageLocation(LOC2_ID, LOC2_NAME, LOC2_BASE); helper.addMapping(getContentRootPid().getId(), LOC1_ID); helper.addMapping(unitPid.getId(), LOC2_ID); initializeManager(); List<StorageLocation> locs = locManager.listAvailableStorageLocations(unitPid); assertEquals(2, locs.size()); StorageLocation loc1 = findStorageLocationById(locs, LOC1_ID); assertIsLocation1(loc1); StorageLocation loc2 = findStorageLocationById(locs, LOC2_ID); assertIsLocation2(loc2); }
@Test public void listAvailableStorageLocationsDuplicateLocation() throws Exception { PID unitPid = makePid(); mockAncestors(unitPid, getContentRootPid()); helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE); helper.addMapping(getContentRootPid().getId(), LOC1_ID); helper.addMapping(unitPid.getId(), LOC1_ID); initializeManager(); List<StorageLocation> locs = locManager.listAvailableStorageLocations(unitPid); assertEquals(1, locs.size()); assertIsLocation1(locs.get(0)); }
@Test public void listAvailableStorageLocationsAssignedAfterCollection() throws Exception { PID unitPid = makePid(); PID collPid = makePid(); PID folderPid = makePid(); mockAncestors(folderPid, getContentRootPid(), unitPid, collPid); helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE); helper.addStorageLocation(LOC2_ID, LOC2_NAME, LOC2_BASE); helper.addMapping(collPid.getId(), LOC1_ID); helper.addMapping(folderPid.getId(), LOC2_ID); initializeManager(); List<StorageLocation> locs = locManager.listAvailableStorageLocations(folderPid); assertEquals(1, locs.size()); assertIsLocation1(locs.get(0)); }