Unit Tests

This commit is contained in:
2025-04-25 15:18:36 +02:00
parent ca36cffd47
commit ac854ed4f1
13 changed files with 399 additions and 39 deletions

View File

@ -0,0 +1,50 @@
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 PICComponents picComponents;
@BeforeEach
void resetComponents() {
picComponents = new PICComponents();
}
@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);
CommandInterface mockCommands = mock(CommandInterface.class);
when(
mockCommands.getExecutionTimeMultiplier()
).thenReturn(
1.0
);
picComponents.registerComponent(CommandInterface.class, mockCommands);
WatchdogTimerInterface watchDogTimer = new WatchdogTimer();
picComponents.registerComponent(WatchdogTimerInterface.class, watchDogTimer);
picComponents.initAll();
watchDogTimer.enable();
watchDogTimer.testAndTrigger();
assertEquals(1, watchDogTimer.get());
}
}