@Before
  public void setUp() {
    registrationApprovedAutomatedWorkflowTemplateJob =
        new RegistrationApprovedAutomatedWorkflowTemplateJob();

    registrationApprovedAutomatedWorkflowTemplateJob.setModelService(
        modelService = mock(ModelService.class));

    registrationApprovedAutomatedWorkflowTemplateJob.setWorkflowAttachmentService(
        workflowAttachmentService = mock(WorkflowAttachmentService.class));

    registrationApprovedAutomatedWorkflowTemplateJob.setUserService(
        userService = mock(UserService.class));

    customer = createCustomerModel();
    b2BCustomer = createB2BCustomerModel(customer);
    b2BRegistrationModel = createB2BRegistrationModel();
    b2bUnitModel = createB2BUnit();

    customers = Arrays.asList(customer);

    workflowActionModel = new WorkflowActionModel();

    workflowDecisionModel = new WorkflowDecisionModel();
    workflowDecisionModel.setName(DECISION_NAME, Locale.getDefault());

    workflowActionModel.setDecisions(Arrays.asList(workflowDecisionModel));
  }
  @Test
  public void testPerform() {

    attachments = Arrays.asList(customer, b2BRegistrationModel);

    Mockito.doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(final InvocationOnMock invocation) {
                customers = new LinkedList<>();

                return null;
              }
            })
        .when(modelService)
        .remove(customer);

    Mockito.doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(final InvocationOnMock invocation) {
                customers = new ArrayList<CustomerModel>();
                customers.add(b2BCustomer);

                return null;
              }
            })
        .when(modelService)
        .save(b2BCustomer);

    Mockito.doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(final InvocationOnMock invocation) {
                attachments = new LinkedList<ItemModel>();
                attachments =
                    Arrays.asList(createB2BCustomerModel(customers.get(0)), b2BRegistrationModel);

                return null;
              }
            })
        .when(workflowAttachmentService)
        .addItems(any(WorkflowModel.class), any(attachments.getClass()));

    workflowAttachmentService.addItems(workflowActionModel.getWorkflow(), attachments);

    when(userService.getUserForUID(b2BRegistrationModel.getEmail(), CustomerModel.class))
        .thenReturn(customer);

    final List<ItemModel> customerAsList = new LinkedList<ItemModel>();
    customerAsList.add(customer);
    when(workflowAttachmentService.getAttachmentsForAction(
            workflowActionModel, CustomerModel.class.getName()))
        .thenReturn(customerAsList);

    final List<ItemModel> b2BRegistrationModelAsList = new LinkedList<ItemModel>();
    b2BRegistrationModelAsList.add(b2BRegistrationModel);
    when(workflowAttachmentService.getAttachmentsForAction(
            workflowActionModel, B2BRegistrationModel.class.getName()))
        .thenReturn(b2BRegistrationModelAsList);

    when(modelService.create(B2BCustomerModel.class)).thenReturn(b2BCustomer);

    final WorkflowModel workflowModel = new WorkflowModel();
    workflowModel.setActions(Arrays.asList(workflowActionModel));

    workflowActionModel.setWorkflow(workflowModel);

    final WorkflowDecisionModel decision =
        registrationApprovedAutomatedWorkflowTemplateJob.perform(workflowActionModel);

    assertEquals("The right decision shoule be returned", decision, workflowDecisionModel);

    assertTrue(
        "B2BCustomer should have been created", attachments.get(0) instanceof B2BCustomerModel);

    assertEquals(
        "B2BCustomer should have been assigned a B2BUnit",
        ((B2BCustomerModel) attachments.get(0)).getDefaultB2BUnit().getName(),
        b2bUnitModel.getName());

    assertTrue(
        "b2BRegistrationModel should still be in workflow attachment",
        attachments.get(1).getClass().getName().endsWith("B2BRegistrationModel"));
  }