@Test
  public void testRunFailWithoutRetry() throws RetryLaterException {
    final TaskModel taskModelMock = mock(TaskModel.class);
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final DefaultSendOrderCancelRequestToDataHubHelper cSVHelperMock =
        mock(DefaultSendOrderCancelRequestToDataHubHelper.class);
    final TaskService paramTaskService = null;
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);

    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);
    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(cSVHelperMock.createAndSendRawItem(orderCancelRecordEntryMock))
        .thenReturn(new DefaultSendToDataHubResult(HttpStatus.FORBIDDEN, ""));
    when(modificationRecordMock.getOrder()).thenReturn(order);
    when(taskModelMock.getRetry()).thenReturn(Integer.valueOf(11));

    cut.setModelService(modelService);
    cut.setOrderCancelRequestCSVHelper(cSVHelperMock);
    cut.run(paramTaskService, taskModelMock);

    verify(cSVHelperMock).createAndSendRawItem(orderCancelRecordEntryMock);
    verify(modelService).save(order);
    assertEquals(OrderStatus.CANCELLING, order.getStatus());
  }
  @Test
  public void testRunFailWithRetry() {
    final TaskModel taskModelMock = mock(TaskModel.class);
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final DefaultSendOrderCancelRequestToDataHubHelper cSVHelperMock =
        mock(DefaultSendOrderCancelRequestToDataHubHelper.class);
    final TaskService paramTaskService = null;
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);

    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);
    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(cSVHelperMock.createAndSendRawItem(orderCancelRecordEntryMock))
        .thenReturn(new DefaultSendToDataHubResult(HttpStatus.FORBIDDEN, ""));
    when(modificationRecordMock.getOrder()).thenReturn(order);

    cut.setModelService(modelService);
    cut.setOrderCancelRequestCSVHelper(cSVHelperMock);
    try {
      cut.run(paramTaskService, taskModelMock);
    } catch (final RetryLaterException e) {
      verify(cSVHelperMock).createAndSendRawItem(orderCancelRecordEntryMock);
      verify(modelService).save(order);
      assertEquals(OrderStatus.CANCELLING, order.getStatus());
      assertEquals(SendOrderCancelRequestAsCSVTaskRunner.DEFAULT_RETRY_DELAY, e.getDelay());
      return;
    }
    fail("RetryLaterException missing");
  }
  @Test
  public void testHandleError() {
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);
    final TaskModel taskModelMock = mock(TaskModel.class);

    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(modificationRecordMock.getOrder()).thenReturn(order);
    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);

    cut.setModelService(modelService);
    cut.handleError(null, taskModelMock, null);

    verify(modelService).save(order);
    assertEquals(OrderStatus.CANCELLING, order.getStatus());
  }
  @Test
  public void testRunSuccess() throws RetryLaterException {
    final TaskModel taskModelMock = mock(TaskModel.class);
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final DefaultSendOrderCancelRequestToDataHubHelper cSVHelperMock =
        mock(DefaultSendOrderCancelRequestToDataHubHelper.class);
    final TaskService paramTaskService = null;

    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);
    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(cSVHelperMock.createAndSendRawItem(orderCancelRecordEntryMock))
        .thenReturn(new DefaultSendToDataHubResult(HttpStatus.OK, ""));

    cut.setOrderCancelRequestCSVHelper(cSVHelperMock);
    cut.run(paramTaskService, taskModelMock);

    verify(cSVHelperMock).createAndSendRawItem(orderCancelRecordEntryMock);
  }