MavenComponentMaintenanceFacet extends DefaultComponentMaintenanceImpl { @TransactionalDeleteBlob @Override protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlob) { StorageTx tx = UnitOfWork.currentTx(); Asset asset = tx.findAsset(assetId); if (asset == null) { return Collections.emptySet(); } Set<String> deletedAssets = new HashSet<>(super.deleteAssetTx(assetId, deleteBlob)); final EntityId componentId = asset.componentId(); if (componentId != null) { Component component = tx.findComponent(componentId); if (component != null && !tx.browseAssets(component).iterator().hasNext()) { deletedAssets.addAll(deleteComponentTx(componentId, deleteBlob).getAssets()); } } return deletedAssets; }    }
@Test public void deleteComponentIfLastAssetDeleted() { when(asset.componentId()).thenReturn(entityId); underTest.deleteAssetTx(entityId, true); verify(storageTx).deleteComponent(component, true); }
@Test public void doNotDeleteComponentWhenOtherAssetsExist() { when(storageTx.browseAssets(component)).thenReturn(singletonList(asset)); underTest.deleteAssetTx(entityId, true); verify(storageTx, never()).deleteComponent(component, true); }