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

    final Bucket bucket = new Bucket();
    bucket.setIdentifier("b2");
    bucket.setName("My Bucket");
    bucket.setDescription("This is my bucket.");
    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setCreated(new Date());
    when(metadataService.getBucketsByName(bucket.getName())).thenReturn(Collections.singletonList(existingBucket));
    // should throw exception since a bucket with the same name exists
    registryService.createBucket(bucket);
}