diff --git a/Roboterfabrik/src/Domäne/RobotFactory.java b/Roboterfabrik/src/Domäne/RobotFactory.java index 2272cd8..a36ca30 100644 --- a/Roboterfabrik/src/Domäne/RobotFactory.java +++ b/Roboterfabrik/src/Domäne/RobotFactory.java @@ -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 roboterLager = new HashMap<>(); public RobotFactory (String name) { diff --git a/Roboterfabrik/src/Domäne/Roboter.java b/Roboterfabrik/src/Domäne/Roboter.java index bd66ea1..b10ce57 100644 --- a/Roboterfabrik/src/Domäne/Roboter.java +++ b/Roboterfabrik/src/Domäne/Roboter.java @@ -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! diff --git a/Roboterfabrik/src/Domäne/RoboterTest.java b/Roboterfabrik/src/Domäne/RoboterTest.java new file mode 100644 index 0000000..c73d010 --- /dev/null +++ b/Roboterfabrik/src/Domäne/RoboterTest.java @@ -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()); + + } + }