@Test
public void triggerShouldHandleThrowingOutputHandler() throws Exception {

  when(storage.getLatestStoredCounter(any())).thenReturn(Optional.of(-1L));
  when(transaction.workflow(INSTANCE.workflowId())).thenReturn(Optional.of(WORKFLOW));
  final RuntimeException rootCause = new RuntimeException("foo!");
  doThrow(rootCause).when(outputHandler).transitionInto(any(), any());
  try {
    stateManager.trigger(INSTANCE, TRIGGER1, PARAMETERS);
    fail();
  } catch (Exception e) {
    assertThat(Throwables.getRootCause(e), is(rootCause));
  }
}