From 38341c1c606ea2b62e203180861e3ed8ab9d103a Mon Sep 17 00:00:00 2001 From: Milan Lukic <2122158@stud.hs-mannheim.de> Date: Fri, 6 Jan 2023 18:19:32 +0100 Subject: [PATCH] RoboterTest Klasse mit Tests erstellt. --- Roboterfabrik/src/Domäne/RobotFactory.java | 2 +- Roboterfabrik/src/Domäne/Roboter.java | 6 +-- Roboterfabrik/src/Domäne/RoboterTest.java | 52 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 Roboterfabrik/src/Domäne/RoboterTest.java 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()); + + } + }