RoboterTest Klasse mit Tests erstellt.

master
Milan Lukic 2023-01-06 18:19:32 +01:00
parent c218cace87
commit 38341c1c60
3 changed files with 56 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import tpe.exceptions.roboter.exceptions.RobotException;
public class RobotFactory {
private String name;
private Roboter pris = Nexus6.getInstance();
private Roboter pris = Nexus6.getInstance();
private HashMap <Integer, Roboter> roboterLager = new HashMap<>();
public RobotFactory (String name) {

View File

@ -9,9 +9,9 @@ import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
public abstract class Roboter implements Robot {
final String name;
boolean power;
RobotException fehler;
protected final String name;
protected boolean power;
protected RobotException fehler;
// Roboter wird in einem ausgeschalteten Zustand instanziiert!

View File

@ -0,0 +1,52 @@
package Domäne;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import tpe.exceptions.roboter.exceptions.RobotException;
class RoboterTest {
@Test
void smokeTest() {
Roboter roboter = new R2D2("Test", 1);
assertEquals(roboter.getName(), "Test");
assertEquals(1,roboter.getId());
}
@Test
void triggerPowerSwitchTest() {
Roboter r2d2 = new R2D2("Test", 1);
Roboter c3po = new C3PO("Test", 15000);
assertFalse(r2d2.isPowerOn());
assertFalse(c3po.isPowerOn());
r2d2.triggerPowerSwitch();
assertTrue(r2d2.isPowerOn());
assertFalse(c3po.isPowerOn());
c3po.triggerPowerSwitch();
assertTrue(r2d2.isPowerOn());
assertTrue(c3po.isPowerOn());
}
void getLastExceptionTest() {
Roboter r2d2 = new R2D2("Test", 1);
int [] zahlen = {5,4,8,1};
assertNull(r2d2.getLastException());
try {
r2d2.think(zahlen);
} catch (RobotException e) {
} assertNotNull(r2d2.getLastException());
}
void nexus6SingletonTest() {
Roboter pris = Nexus6.getInstance();
Roboter pris2 = Nexus6.getInstance();
assertEquals(pris.hashCode(), pris2.hashCode());
assertEquals(pris, pris2);
assertFalse(pris.isPowerOn());
pris.triggerPowerSwitch();
assertFalse(pris.isPowerOn());
}
}