@Test
public void testExecute() throws Exception
{

    // Set up expected values.
    String jobDefinitionNamespace = "jobDefinitionNamespace";
    String jobDefinitionName = "jobDefinitionName";
    String processDefinitionId = "processDefinitionId";
    String processDefinitionKey = String.format("%s.%s", jobDefinitionNamespace, jobDefinitionName);
    String updatedBy = "updatedBy";
    JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
    jobDefinitionEntity.setUpdatedBy(updatedBy);
    // Mock dependency methods.
    when(delegateExecution.getProcessDefinitionId()).thenReturn(processDefinitionId);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getKey()).thenReturn(processDefinitionKey);
    when(activitiService.getProcessDefinitionById(any())).thenReturn(processDefinition);
    when(jobDefinitionDaoHelper.getJobDefinitionEntity(any(), any())).thenReturn(jobDefinitionEntity);
    // Execute test method.
    baseJavaDelegate.execute(delegateExecution);
    // Verify dependencies were invoked correctly.
    InOrder inOrder = inOrder(configurationDaoHelper, activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper, activitiRuntimeHelper);
    inOrder.verify(configurationDaoHelper).checkNotAllowedMethod(baseJavaDelegate.getClass().getCanonicalName());
    inOrder.verify(activitiService).getProcessDefinitionById(processDefinitionId);
    inOrder.verify(jobDefinitionDaoHelper).getJobDefinitionEntity(jobDefinitionNamespace, jobDefinitionName);
    inOrder.verify(userNamespaceAuthorizationHelper).buildNamespaceAuthorizations(applicationUserUserIdEq(updatedBy));
    inOrder.verify(activitiRuntimeHelper).setTaskSuccessInWorkflow(delegateExecution);
    inOrder.verifyNoMoreInteractions();
    verifyNoMoreInteractions(configurationDaoHelper, activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper, activitiRuntimeHelper);
    // Assert that security context is cleared at the end of execute.
    assertNull(SecurityContextHolder.getContext().getAuthentication());
}