@Test
public void testExecuteWithExceptionAndGetCreateTransactionException()
{

    // Mock dependencies.
    CommandConfig config = mock(CommandConfig.class);
    JobEntity job = mock(JobEntity.class);
    JobEntityManager jobEntityManager = mock(JobEntityManager.class);
    CommandContext commandContext = mock(CommandContext.class);
    //Save the command context to use later
    CommandContext commandContextSaved = Context.getCommandContext();
    Context.setCommandContext(commandContext);
    String jobId = "testId100";
    when(job.getId()).thenReturn(jobId);
    when(job.getProcessInstanceId()).thenReturn("testProcessId100");
    when(job.getRetries()).thenReturn(3);
    ExecuteAsyncJobCmd command = new ExecuteAsyncJobCmd(job);
    doThrow(CannotCreateTransactionException.class).when(job).execute(any());
    when(commandContext.getJobEntityManager()).thenReturn(jobEntityManager);
    when(jobEntityManager.findJobById(jobId)).thenReturn(job);
    try
    {
        herdCommandInvoker.execute(config, command);
        fail();
    }
    catch (CannotCreateTransactionException e)
    {
       //Get expected exception
    }
    finally
    {
        Context.setCommandContext(commandContextSaved);
    }
}