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

    final BucketEntity bucketToUpdate = new BucketEntity();
    bucketToUpdate.setId("b1");
    bucketToUpdate.setName("My Bucket");
    bucketToUpdate.setDescription("This is my bucket");
    bucketToUpdate.setCreated(new Date());
    when(metadataService.getBucketById(bucketToUpdate.getId())).thenReturn(bucketToUpdate);
    final BucketEntity otherBucket = new BucketEntity();
    otherBucket.setId("b2");
    otherBucket.setName("My Bucket #2");
    otherBucket.setDescription("This is my bucket");
    otherBucket.setCreated(new Date());
    when(metadataService.getBucketsByName(otherBucket.getName())).thenReturn(Collections.singletonList(otherBucket));
    // should fail because other bucket has the same name
    final Bucket updatedBucket = new Bucket();
    updatedBucket.setIdentifier(bucketToUpdate.getId());
    updatedBucket.setName("My Bucket #2");
    updatedBucket.setDescription(bucketToUpdate.getDescription());
    registryService.updateBucket(updatedBucket);
}