@Test
public void shouldReturnErrorWhenFailedToDeleteWorkflow() throws Exception {

  sinceVersion(Api.Version.V3);
  doThrow(new IOException()).when(storage).delete(WORKFLOW.id());
  doAnswer(a -> {
    TransactionFunction<Object, Exception> tf = a.getArgument(0);
    return rawStorage.runInTransactionWithRetries(tx -> {
      var spiedTx = spy(tx);
      when(spiedTx.deleteWorkflow(any())).thenThrow(new IOException());
      return tf.apply(spiedTx);
    });
  }).when(storage).runInTransactionWithRetries(any());
  var response = awaitResponse(serviceHelper.request("DELETE", path("/foo/bar")));
  assertThat(response, hasStatus(withCode(Status.INTERNAL_SERVER_ERROR)));
}