DatastoreStorage implements Closeable { Optional<Workflow> workflow(WorkflowId workflowId) throws IOException { final Optional<Entity> entityOptional = getWorkflowOpt(datastore, datastore::newKeyFactory, workflowId); if (entityOptional.isPresent()) { return Optional.of(parseWorkflowJson(entityOptional.get(), workflowId)); } else { return Optional.empty(); } } DatastoreStorage(CheckedDatastore datastore); @VisibleForTesting  DatastoreStorage(CheckedDatastore datastore,
                   Function<CheckedDatastoreTransaction, DatastoreStorageTransaction> storageTransactionFactory,
                   ExecutorService executor, Logger log); @Override void close(); void updateNextNaturalTrigger(WorkflowId workflowId, TriggerInstantSpec triggerSpec); Map<WorkflowId, Workflow> workflows(); Map<WorkflowId, Workflow> workflows(Set<WorkflowId> workflowIds); List<Workflow> workflows(String componentId); T runInTransactionWithRetries(TransactionFunction<T, E> f);  }
@Test public void shouldReturnEmptyOptionalWhenWorkflowIdDoesNotExist() throws Exception { Optional<Workflow> retrieved = storage.workflow(WorkflowId.create("foo", "bar")); assertThat(retrieved, is(Optional.empty())); }