From a0f16fc80838d1169e721dea5732a3054737fd26 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 8 Jan 2023 20:02:57 +0100 Subject: [PATCH] =?UTF-8?q?R2D2=20JUnit=20Test=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/domain/R2D2Test.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Robbie-Management-System/src/domain/R2D2Test.java diff --git a/Robbie-Management-System/src/domain/R2D2Test.java b/Robbie-Management-System/src/domain/R2D2Test.java new file mode 100644 index 0000000..ba377a7 --- /dev/null +++ b/Robbie-Management-System/src/domain/R2D2Test.java @@ -0,0 +1,62 @@ +package domain; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import exceptions.RobotException; + +import org.junit.Assert; + +class R2D2Test { + + @Test + void testSetNameGetName() { + R2D2 r = new R2D2("Test"); + assertEquals("Test", r.getName()); + r.setName("TestNeu"); + assertEquals("TestNeu", r.getName()); + } + + @Test + void testSetiDGetiD() { + R2D2 r = new R2D2("Test"); + assertEquals(0, r.getId()); + R2D2 r2 = new R2D2("Test2"); + assertNotEquals(1, r2.getId()); + r2.setiD(2); + assertEquals(2, r2.getId()); + } + + @Test + void testTriggerPowerSwitchIsPowerOn() { + R2D2 r = new R2D2("Test"); + assertEquals(true, r.isPowerOn()); + r.triggerPowerSwitch(); + assertEquals(false, r.isPowerOn()); + } + + @Test + void testThinkSpeak() throws RobotException { + R2D2 r = new R2D2("Test"); + int[] zahlen = {2,4,3,1,6,5}; + assertEquals("2, 4, 3, 1, 6, 5", r.speak(zahlen)); + int[] zahlenNeu = {1,2,3,4,5,6}; + Assert.assertArrayEquals(zahlenNeu, r.think(zahlen)); + assertEquals("1, 2, 3, 4, 5, 6", r.speak(r.think(zahlen))); + } + + @Test + void testGetLastException() throws RobotException { + R2D2 r = new R2D2("Test"); + int[] zahlen = {42,4,3,1,6,5}; + r.think(zahlen); + assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", r.getLastException().toString()); + r.speak(zahlen); + assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", r.getLastException().toString()); + r.triggerPowerSwitch(); + r.think(zahlen); + assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", r.getLastException().toString()); + r.speak(zahlen); + assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", r.getLastException().toString()); + } +}