package org.dromara.mqtt;

import org.dromara.mqtt.config.properties.MqttProperties;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@Tag("dev")
class MqttCommandRetryTaskTest {

    @Test
    void retryExpiredCommandsSkipsRetryBeforeStartupCleanupIsReady() {
        MqttCommandAckService ackService = mock(MqttCommandAckService.class);
        when(ackService.isStartupCleanupReady()).thenReturn(false);
        MqttCommandRetryTask task = new MqttCommandRetryTask(ackService, new MqttProperties());

        task.retryExpiredCommands();

        verify(ackService, never()).retryExpiredCommands();
    }

    @Test
    void retryExpiredCommandsRetriesAfterStartupCleanupIsReady() {
        MqttCommandAckService ackService = mock(MqttCommandAckService.class);
        when(ackService.isStartupCleanupReady()).thenReturn(true);
        MqttCommandRetryTask task = new MqttCommandRetryTask(ackService, new MqttProperties());

        task.retryExpiredCommands();

        verify(ackService).retryExpiredCommands();
    }
}
