@Test
public void testGetLatestSnapshotMetadataWhenNoVersionsExist() {

    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);
    // return a flow with the existing snapshot when getFlowById is called
    final FlowEntity existingFlow = new FlowEntity();
    existingFlow.setId("flow1");
    existingFlow.setName("My Flow");
    existingFlow.setDescription("This is my flow.");
    existingFlow.setCreated(new Date());
    existingFlow.setModified(new Date());
    existingFlow.setBucketId(existingBucket.getId());
    when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
    final FlowSnapshotEntity existingSnapshot1 = new FlowSnapshotEntity();
    existingSnapshot1.setVersion(1);
    existingSnapshot1.setFlowId(existingFlow.getId());
    existingSnapshot1.setCreatedBy("user1");
    existingSnapshot1.setCreated(new Date());
    existingSnapshot1.setComments("This is snapshot 1");
    when(metadataService.getLatestSnapshot(existingFlow.getId())).thenReturn(null);
    try {
        registryService.getLatestFlowSnapshotMetadata(existingBucket.getId(), existingFlow.getId());
        Assert.fail("Should have thrown exception");
    } catch (ResourceNotFoundException e) {
        assertEquals("The specified flow ID has no versions", e.getMessage());
    }
}