### Question:
RegistryService { public Bucket getBucket(final String bucketIdentifier) { if (bucketIdentifier == null) { throw new IllegalArgumentException("Bucket identifier cannot be null"); } final BucketEntity bucket = metadataService.getBucketById(bucketIdentifier); if (bucket == null) { LOGGER.warn("The specified bucket id [{}] does not exist.", bucketIdentifier); throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry."); } return BucketMappings.map(bucket); } @Autowired  RegistryService(final MetadataService metadataService,
                           final FlowPersistenceProvider flowPersistenceProvider,
                           final BundlePersistenceProvider bundlePersistenceProvider,
                           final FlowContentSerializer flowContentSerializer,
                           final Validator validator,
                           final RegistryUrlAliasService registryUrlAliasService); Bucket createBucket(final Bucket bucket); Bucket getBucket(final String bucketIdentifier); void verifyBucketExists(final String bucketIdentifier); Bucket getBucketByName(final String bucketName); List<Bucket> getBuckets(); List<Bucket> getBuckets(final Set<String> bucketIds); Bucket updateBucket(final Bucket bucket); Bucket deleteBucket(final String bucketIdentifier); List<BucketItem> getBucketItems(final String bucketIdentifier); List<BucketItem> getBucketItems(final Set<String> bucketIdentifiers); VersionedFlow createFlow(final String bucketIdentifier, final VersionedFlow versionedFlow); VersionedFlow getFlow(final String bucketIdentifier, final String flowIdentifier); VersionedFlow getFlow(final String flowIdentifier); void verifyFlowExists(final String flowIdentifier); List<VersionedFlow> getFlows(final String bucketId); VersionedFlow updateFlow(final VersionedFlow versionedFlow); VersionedFlow deleteFlow(final String bucketIdentifier, final String flowIdentifier); VersionedFlowSnapshot createFlowSnapshot(final VersionedFlowSnapshot flowSnapshot); VersionedFlowSnapshot getFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version); SortedSet<VersionedFlowSnapshotMetadata> getFlowSnapshots(final String bucketIdentifier, final String flowIdentifier); VersionedFlowSnapshotMetadata getLatestFlowSnapshotMetadata(final String bucketIdentifier, final String flowIdentifier); VersionedFlowSnapshotMetadata getLatestFlowSnapshotMetadata(final String flowIdentifier); VersionedFlowSnapshotMetadata deleteFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version); VersionedFlowDifference getFlowDiff(final String bucketIdentifier, final String flowIdentifier,
                                               final Integer versionA, final Integer versionB); Set<String> getBucketFields(); Set<String> getBucketItemFields(); Set<String> getFlowFields();  }### Answer:
@Test(expected = ResourceNotFoundException.class) public void testGetBucketDoesNotExist() { when(metadataService.getBucketById(any(String.class))).thenReturn(null); registryService.getBucket("does-not-exist"); }
@Test public void testGetExistingBucket() { 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 Bucket bucket = registryService.getBucket(existingBucket.getId()); assertNotNull(bucket); assertEquals(existingBucket.getId(), bucket.getIdentifier()); assertEquals(existingBucket.getName(), bucket.getName()); assertEquals(existingBucket.getDescription(), bucket.getDescription()); assertEquals(existingBucket.getCreated().getTime(), bucket.getCreatedTimestamp()); }