@Test(expected = IllegalStateException.class)
public void testUpdateFlowWithSameNameAsExistingFlow() {

    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    final FlowEntity flowToUpdate = new FlowEntity();
    flowToUpdate.setId("flow1");
    flowToUpdate.setName("My Flow");
    flowToUpdate.setDescription("This is my flow.");
    flowToUpdate.setCreated(new Date());
    flowToUpdate.setModified(new Date());
    flowToUpdate.setBucketId(existingBucket.getId());
    when(metadataService.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
    final FlowEntity otherFlow = new FlowEntity();
    otherFlow.setId("flow2");
    otherFlow.setName("My Flow 2");
    otherFlow.setDescription("This is my flow 2.");
    otherFlow.setCreated(new Date());
    otherFlow.setModified(new Date());
    otherFlow.setBucketId(existingBucket.getId());
    when(metadataService.getFlowsByName(existingBucket.getId(), otherFlow.getName())).thenReturn(Collections.singletonList(otherFlow));
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setIdentifier(flowToUpdate.getId());
    versionedFlow.setBucketIdentifier(existingBucket.getId());
    versionedFlow.setName(otherFlow.getName());
    registryService.updateFlow(versionedFlow);
}