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,88 @@
package fabrik.simulator.pic16f84;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import fabrik.simulator.pic16f84.interfaces.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class CommandsTests {
PICComponents picComponents;
public CommandsTests() {}
@BeforeEach
void resetComponents() {
picComponents = new PICComponents();
}
@Test
@DisplayName("Execution Time wird korrekt addiert")
void executionTimeIsAddedCorrectly() {
TimerInterface timerMock = mock(TimerInterface.class);
picComponents.registerComponent(TimerInterface.class, timerMock);
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
CommandInterface commands = new Commands();
picComponents.registerComponent(CommandInterface.class, commands);
picComponents.initAll();
commands.addExecutionTime(5);
assertEquals(5, commands.getTotalExecutionTime());
}
@Test
@DisplayName("Execution Time wird korrekt zurückgesetzt")
void executionTimeResetWorks() {
TimerInterface timerMock = mock(TimerInterface.class);
picComponents.registerComponent(TimerInterface.class, timerMock);
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
CommandInterface commands = new Commands();
picComponents.registerComponent(CommandInterface.class, commands);
picComponents.initAll();
commands.addExecutionTime(5);
commands.resetTotalExecutionTime();
assertEquals(0, commands.getTotalExecutionTime());
}
@Test
@DisplayName("Execution Time Faktor wird berücksichtigt")
void executionTimeMultiplierIsUsed() {
TimerInterface timerMock = mock(TimerInterface.class);
picComponents.registerComponent(TimerInterface.class, timerMock);
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
CommandInterface commands = new Commands();
picComponents.registerComponent(CommandInterface.class, commands);
picComponents.initAll();
commands.addExecutionTime(5);
commands.setExecutionTimeMultiplier("100 HZ");
assertEquals(5 * 40, commands.getTotalExecutionTime());
}
@Test
@DisplayName("Decode mit ungültigem Opcode wirft keine Exception")
void decodeInvalidOpcodeDoesNotCrash() {
CommandInterface commands = new Commands();
assertDoesNotThrow(() -> commands.decode(1));
}
}