@Test
public void testCleanupS3StorageUnit()
{

    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey =
        new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);
    // Create a 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 mocks
    BusinessObjectDataEntity businessObjectDataEntity = mock(BusinessObjectDataEntity.class);
    // Mock the external calls.
    when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
    when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(mockBusinessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
    when(businessObjectDataEntity.getLatestVersion()).thenReturn(true);
    when(mockBusinessObjectDataDao.getBusinessObjectDataMaxVersion(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_MAX_VERSION);
    when(mockBusinessObjectDataDao.getBusinessObjectDataByAltKey(
        new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(),
            businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(),
            businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(),
            businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION))).thenReturn(businessObjectDataEntity);
    // Call the method under test.
    cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
    // Verify the external calls.
    verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(businessObjectDataEntity).getStorageUnits();
    verify(mockBusinessObjectDataDao).delete(businessObjectDataEntity);
    verify(mockNotificationEventService)
        .processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey,
            STORAGE_NAME, null, StorageUnitStatusEntity.DISABLED);
    verify(mockNotificationEventService)
        .processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, businessObjectDataKey, null,
            BusinessObjectDataStatusEntity.DELETED);
    verify(businessObjectDataEntity).getBusinessObjectDataChildren();
    verify(businessObjectDataEntity).getBusinessObjectDataParents();
    verify(businessObjectDataEntity).getLatestVersion();
    verify(mockBusinessObjectDataDao).getBusinessObjectDataMaxVersion(businessObjectDataKey);
    verify(mockBusinessObjectDataDao).getBusinessObjectDataByAltKey(
        new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(),
            businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(),
            businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(),
            businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION));
    verify(businessObjectDataEntity).setLatestVersion(true);
    verify(mockBusinessObjectDataDao).saveAndRefresh(businessObjectDataEntity);
    verifyNoMoreInteractions(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}