@Test
public void getWorkflowDefinitionStatisticsWorks() {

  WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(null).setStatus(created).build();
  long id = instanceDao.insertWorkflowInstance(i1);
  Map<String, Map<String, WorkflowDefinitionStatistics>> stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null,
      null, null, null);
  Map<String, WorkflowDefinitionStatistics> stateStats = stats.get("CreateLoan");
  assertThat(stateStats.get(executing.name()), is(nullValue()));
  assertThat(stateStats.get(inProgress.name()).queuedInstances, is(2L));
  assertThat(stateStats.get(inProgress.name()).allInstances, is(2L));
  assertThat(stateStats.get(created.name()).queuedInstances, is(0L));
  assertThat(stateStats.get(created.name()).allInstances, is(1L));
  WorkflowInstance i2 = new WorkflowInstance.Builder().setId(id).setNextActivation(now().minusDays(1)).build();
  instanceDao.updateNotRunningWorkflowInstance(i2);
  stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null, null, null, null);
  stateStats = stats.get("CreateLoan");
  assertThat(stateStats.get(executing.name()), is(nullValue()));
  assertThat(stateStats.get(inProgress.name()).queuedInstances, is(2L));
  assertThat(stateStats.get(inProgress.name()).allInstances, is(2L));
  assertThat(stateStats.get(created.name()).queuedInstances, is(1L));
  assertThat(stateStats.get(created.name()).allInstances, is(1L));
}