From 50324c85929fba18525f6463abd8041becab337e Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 8 Jan 2023 19:56:31 +0100 Subject: [PATCH] =?UTF-8?q?C3PO=20JUnit=20Test=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/domain/C3POTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Robbie-Management-System/src/domain/C3POTest.java diff --git a/Robbie-Management-System/src/domain/C3POTest.java b/Robbie-Management-System/src/domain/C3POTest.java new file mode 100644 index 0000000..79bf8c4 --- /dev/null +++ b/Robbie-Management-System/src/domain/C3POTest.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 C3POTest { + + @Test + void testSetNameGetName() { + C3PO c = new C3PO("Test"); + assertEquals("Test", c.getName()); + c.setName("TestNeu"); + assertEquals("TestNeu", c.getName()); + } + + @Test + void testSetiDGetiD() { + C3PO c = new C3PO("Test"); + assertEquals(10000, c.getId()); + C3PO c2 = new C3PO("Test2"); + assertNotEquals(10001, c2.getId()); + c2.setiD(10002); + assertEquals(10002, c2.getId()); + } + + @Test + void testTriggerPowerSwitchIsPowerOn() { + C3PO c = new C3PO("Test"); + assertEquals(true, c.isPowerOn()); + c.triggerPowerSwitch(); + assertEquals(false, c.isPowerOn()); + } + + @Test + void testThinkSpeak() throws RobotException { + C3PO c = new C3PO("Test"); + int[] zahlen = {2,4,3,1,6,5}; + assertEquals("2; 4; 3; 1; 6; 5", c.speak(zahlen)); + int[] zahlenNeu = {6,5,4,3,2,1}; + Assert.assertArrayEquals(zahlenNeu, c.think(zahlen)); + assertEquals("6; 5; 4; 3; 2; 1", c.speak(c.think(zahlen))); + } + + @Test + void testGetLastException() throws RobotException { + C3PO c = new C3PO("Test"); + int[] zahlen = {42,4,3,1,6,5}; + c.think(zahlen); + assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", c.getLastException().toString()); + c.speak(zahlen); + assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", c.getLastException().toString()); + c.triggerPowerSwitch(); + c.think(zahlen); + assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", c.getLastException().toString()); + c.speak(zahlen); + assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", c.getLastException().toString()); + } +}