@Test
public void testDeleteFlowWithSnapshots() {

    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    final FlowEntity flowToDelete = new FlowEntity();
    flowToDelete.setId("flow1");
    flowToDelete.setName("My Flow");
    flowToDelete.setDescription("This is my flow.");
    flowToDelete.setCreated(new Date());
    flowToDelete.setModified(new Date());
    flowToDelete.setBucketId(existingBucket.getId());
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    when(metadataService.getFlowById(flowToDelete.getId())).thenReturn(flowToDelete);
    when(metadataService.getFlowsByName(flowToDelete.getName())).thenReturn(Collections.singletonList(flowToDelete));
    final VersionedFlow deletedFlow = registryService.deleteFlow(existingBucket.getId(), flowToDelete.getId());
    assertNotNull(deletedFlow);
    assertEquals(flowToDelete.getId(), deletedFlow.getIdentifier());
    verify(flowPersistenceProvider, times(1))
            .deleteAllFlowContent(flowToDelete.getBucketId(), flowToDelete.getId());
    verify(metadataService, times(1)).deleteFlow(flowToDelete);
}