@Test
public void testRunFunctionalException() throws FunctionalException, UnknownHostException {

    final List<ScheduledTask> scheduledTasks = new ArrayList<>();
    final ScheduledTask scheduledTask = new ScheduledTask(DEVICE_MESSAGE_DATA, DOMAIN, DOMAIN, DATA_OBJECT,
            SCHEDULED_TIME);
    scheduledTasks.add(scheduledTask);
    when(this.scheduledTaskRepository.findByStatusAndScheduledTimeLessThan(any(ScheduledTaskStatusType.class),
            any(Timestamp.class), any(Pageable.class))).thenReturn(scheduledTasks)
                    .thenReturn(new ArrayList<ScheduledTask>());
    final Device device = new Device();
    device.updateRegistrationData(InetAddress.getByName("127.0.0.1"), "deviceType");
    when(this.deviceRepository.findByDeviceIdentification(anyString())).thenReturn(device);
    when(this.scheduledTaskRepository.save(any(ScheduledTask.class))).thenReturn(scheduledTask);
    when(this.schedulingConfig.scheduledTaskPageSize()).thenReturn(30);
    doThrow(new FunctionalException(FunctionalExceptionType.ARGUMENT_NULL, ComponentType.OSGP_CORE))
            .when(this.deviceRequestMessageService).processMessage(any(ProtocolRequestMessage.class));
    this.scheduler.run();
    // check if task is deleted
    verify(this.scheduledTaskRepository).delete(scheduledTask);
}