@Test
public void shouldFailTriggerWFIfAlreadyActive() throws Exception {

  reset(storage);
  when(storage.getLatestStoredCounter(any())).thenReturn(Optional.empty());
  when(transaction.workflow(INSTANCE.workflowId())).thenReturn(Optional.of(WORKFLOW));
  DatastoreException datastoreException = new DatastoreException(1, "", "");
  TransactionException transactionException = spy(new TransactionException(datastoreException));
  when(transactionException.isAlreadyExists()).thenReturn(true);
  doThrow(transactionException).when(transaction).writeActiveState(any(), any());
  when(storage.runInTransactionWithRetries(any())).thenAnswer(a ->
      a.<TransactionFunction>getArgument(0).apply(transaction));
  try {
    stateManager.trigger(INSTANCE, TRIGGER1, PARAMETERS);
    fail();
  } catch (AlreadyInitializedException ignore) {
  }
}