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

    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);
    // setup a flow with the same name that already exists
    final FlowEntity flowWithSameName = new FlowEntity();
    flowWithSameName.setId("flow1");
    flowWithSameName.setName("Flow 1");
    flowWithSameName.setDescription("This is flow 1");
    flowWithSameName.setCreated(new Date());
    flowWithSameName.setModified(new Date());
    when(metadataService.getFlowsByName(existingBucket.getId(), flowWithSameName.getName())).thenReturn(Collections.singletonList(flowWithSameName));
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setIdentifier("flow2");
    versionedFlow.setName(flowWithSameName.getName());
    versionedFlow.setBucketIdentifier("b1");
    registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
}