@Test
public void shouldTailPaginateWorkflowInstancesData() throws Exception {

  sinceVersion(Api.Version.V3);
  // Set the next natural trigger
  final WorkflowState workflowState = WorkflowState.builder()
      .nextNaturalTrigger(ParameterUtil.parseDate("2016-08-14"))
      .build();
  storage.patchState(WORKFLOW.id(), workflowState);
  WorkflowInstance wfi1 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-11");
  WorkflowInstance wfi2 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-12");
  WorkflowInstance wfi3 = WorkflowInstance.create(WORKFLOW.id(), "2016-08-13");
  storage.writeEvent(create(Event.triggerExecution(wfi1, NATURAL_TRIGGER, TRIGGER_PARAMETERS), 0L, ms("07:00:00")));
  storage.writeEvent(create(Event.triggerExecution(wfi2, NATURAL_TRIGGER, TRIGGER_PARAMETERS), 0L, ms("07:00:00")));
  storage.writeEvent(create(Event.triggerExecution(wfi3, NATURAL_TRIGGER, TRIGGER_PARAMETERS), 0L, ms("07:00:00")));
  Response<ByteString> response = awaitResponse(
      serviceHelper.request("GET", path("/foo/bar/instances?limit=2&tail=true")));
  assertThat(response, hasStatus(withCode(Status.OK)));
  assertJson(response, "[*]", hasSize(2));
  assertJson(response, "[0].workflow_instance.parameter", is("2016-08-12"));
  assertJson(response, "[1].workflow_instance.parameter", is("2016-08-13"));
}