DatastoreStorage implements Closeable { public Map<WorkflowId, Workflow> workflows() throws IOException { var workflows = new HashMap<WorkflowId, Workflow>(); var query = Query.newEntityQueryBuilder().setKind(KIND_WORKFLOW).build(); datastore.query(query, entity -> { Workflow workflow; try { workflow = OBJECT_MAPPER.readValue(entity.getString(PROPERTY_WORKFLOW_JSON), Workflow.class); } catch (IOException e) { log.warn("Failed to read workflow {}.", entity.getKey(), e); return; } workflows.put(workflow.id(), workflow); }); return workflows; } 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 shouldReturnEmptyListIfComponentDoesNotExist() throws Exception { String componentId = "component"; List<Workflow> l = storage.workflows(componentId); assertThat(l, hasSize(0)); }