@Test
public void testProcessScheduledMessageRetry() {

    final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    final Date scheduledRetryTime = calendar.getTime();
    // since the retryCount is smaller than the maxRetries, the message
    // should be retried
    final RetryHeader retryHeader = new RetryHeader(0, 1, scheduledRetryTime);
    final String exceptionMessage = "message";
    final OsgpException exception = new OsgpException(ComponentType.OSGP_CORE, exceptionMessage);
    final ProtocolResponseMessage message = new ProtocolResponseMessage.Builder()
            .deviceMessageMetadata(DEVICE_MESSAGE_DATA).domain(DOMAIN).domainVersion(DOMAIN_VERSION).result(result)
            .dataObject(DATA_OBJECT).scheduled(true).retryHeader(retryHeader).osgpException(exception).build();
    final ScheduledTask scheduledTask = new ScheduledTask(DEVICE_MESSAGE_DATA, DOMAIN, DOMAIN, DATA_OBJECT,
            SCHEDULED_TIME);
    when(this.scheduledTaskRepository.findByCorrelationUid(anyString())).thenReturn(scheduledTask);
    this.deviceResponseMessageService.processMessage(message);
    // check if the message is not send and the task is not deleted
    verify(this.domainResponseMessageSender, never()).send(message);
    verify(this.scheduledTaskRepository, never()).delete(scheduledTask);
    verify(this.scheduledTaskRepository).save(scheduledTask);
    // check if the scheduled time is updated to the message retry time
    assertEquals(new Timestamp(scheduledRetryTime.getTime()), scheduledTask.getscheduledTime());
    assertTrue(scheduledTask.getErrorLog().contains(exceptionMessage));
}