package fabrik.simulator.pic16f84;

import fabrik.simulator.pic16f84.interfaces.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class WatchDogTimerTests {
    private PICComponentLocator picComponents;

    @BeforeEach
    void resetComponents() {
        picComponents = new PICComponentLocator();
    }

    @Test
    @DisplayName("WatchDogTimer testet ob er triggern soll, triggert korrekt nicht")
    void watchDogIncrementWithoutTriggering() {
        PreScalerInterface mockPreScaler = mock(PreScalerInterface.class);
        when(
                mockPreScaler.isPrescalerOnTimer()
        ).thenReturn(
                true
        );
        picComponents.registerComponent(PreScalerInterface.class, mockPreScaler);


        ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
        when(
                mockExecutionTime.getExecutionTimeMultiplier()
        ).thenReturn(
                1.0
        );
        picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);

        WatchdogTimerInterface watchDogTimer = new WatchdogTimer();
        picComponents.registerComponent(WatchdogTimerInterface.class, watchDogTimer);
        picComponents.initAll();

        watchDogTimer.enable();
        watchDogTimer.testAndTrigger();


        assertEquals(1, watchDogTimer.get());
    }
}