@Test
public void testProcessScheduledMessageFailed() {

    final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    final Date scheduledRetryTime = calendar.getTime();
    // since the retryCount equals the maxRetries, the message should fail
    final RetryHeader retryHeader = new RetryHeader(1, 1, scheduledRetryTime);
    final ProtocolResponseMessage message = new ProtocolResponseMessage.Builder()
            .deviceMessageMetadata(DEVICE_MESSAGE_DATA)
            .domain(DOMAIN)
            .domainVersion(DOMAIN_VERSION)
            .result(result)
            .dataObject(DATA_OBJECT)
            .scheduled(true)
            .retryHeader(retryHeader)
            .build();
    final ScheduledTask scheduledTask = new ScheduledTask(DEVICE_MESSAGE_DATA, DOMAIN, DOMAIN, DATA_OBJECT,
            SCHEDULED_TIME);
    when(this.scheduledTaskService.findByCorrelationUid(anyString())).thenReturn(scheduledTask);
    this.deviceResponseMessageService.processMessage(message);
    // check if message is sent and task is deleted
    verify(this.domainResponseMessageSender).send(message);
    verify(this.scheduledTaskService).deleteScheduledTask(scheduledTask);
}