@Test
public void testCreateStorageUnitsFromEntities()
{

    // Create a business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey =
        new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE,
            SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage file entity with a file path that does not start with storage unit directory path.
    StorageFileEntity storageFileOneEntity = new StorageFileEntity();
    storageFileOneEntity.setStorageUnit(null);
    storageFileOneEntity.setPath(FILE_NAME);
    storageFileOneEntity.setFileSizeBytes(FILE_SIZE);
    storageFileOneEntity.setRowCount(ROW_COUNT);
    // Create a storage file entity with a file path that starts with the storage unit directory path.
    StorageFileEntity storageFileTwoEntity = new StorageFileEntity();
    storageFileTwoEntity.setStorageUnit(null);
    storageFileTwoEntity.setPath(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME_2);
    storageFileTwoEntity.setFileSizeBytes(FILE_SIZE_2);
    storageFileTwoEntity.setRowCount(ROW_COUNT_2);
    // Create an expiration timestamp for restoration.
    final Timestamp restoredExpirationOn = new Timestamp(new Date().getTime());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
    storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
    storageUnitEntity.setStorageFiles(Lists.newArrayList(storageFileOneEntity, storageFileTwoEntity));
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS);
    storageUnitEntity.setRestoreExpirationOn(restoredExpirationOn);
    // Mock the external calls.
    when(storageFileHelper.createStorageFileFromEntity(any(StorageFileEntity.class), eq(STORAGE_DIRECTORY_PATH))).thenCallRealMethod();
    // Call the method under test.
    List<StorageUnit> result =
        storageUnitHelper.createStorageUnitsFromEntities(Collections.singletonList(storageUnitEntity), NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY,
                NO_EXCLUDE_BUSINESS_OBJECT_DATA_STORAGE_FILES);
    // Verify the external calls.
    verify(storageFileHelper).createStorageFileFromEntity(storageFileOneEntity, STORAGE_DIRECTORY_PATH);
    verify(storageFileHelper).createStorageFileFromEntity(storageFileTwoEntity, STORAGE_DIRECTORY_PATH);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(Collections.singletonList(
        new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), new StorageDirectory(STORAGE_DIRECTORY_PATH), Lists
            .newArrayList(new StorageFile(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME, FILE_SIZE, ROW_COUNT),
                new StorageFile(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME_2, FILE_SIZE_2, ROW_COUNT_2)), STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY,
            STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, HerdDateUtils.getXMLGregorianCalendarValue(restoredExpirationOn))), result);
}