@Test
public void updateWorkflowInstanceWorks() {

  WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42).build();
  WorkflowInstanceAction a = new WorkflowInstanceAction.Builder().setType(externalChange).setWorkflowInstanceId(i.id).build();
  when(workflowInstanceDao.getWorkflowInstanceState(i.id)).thenReturn("currentState");
  when(workflowInstanceDao.updateNotRunningWorkflowInstance(any(WorkflowInstance.class))).thenReturn(true);
  when(workflowInstanceDao.getWorkflowInstanceType(42)).thenReturn(i.type);
  assertThat(service.updateWorkflowInstance(i, a), is(true));
  verify(workflowInstanceDao).updateNotRunningWorkflowInstance(stored.capture());
  assertThat(stored.getValue().status, is(inProgress));
  verify(workflowInstanceDao).insertWorkflowInstanceAction(stored2.capture(), storedAction.capture());
  assertThat(storedAction.getValue().state, is("currentState"));
}