From 11fd265348ca52b0e1c8dc65ee50cb220981c901 Mon Sep 17 00:00:00 2001 From: KDippold <2023962@stud.hs-mannheim.de> Date: Sun, 8 Jan 2023 01:10:45 +0100 Subject: [PATCH] C3PO Test --- Roboterfabrik/src/Domäne/C3POTest.java | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Roboterfabrik/src/Domäne/C3POTest.java diff --git a/Roboterfabrik/src/Domäne/C3POTest.java b/Roboterfabrik/src/Domäne/C3POTest.java new file mode 100644 index 0000000..f3fad3a --- /dev/null +++ b/Roboterfabrik/src/Domäne/C3POTest.java @@ -0,0 +1,56 @@ +package Domäne; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import tpe.exceptions.roboter.exceptions.RobotException; +import tpe.exceptions.roboter.exceptions.RobotIllegalStateException; +import tpe.exceptions.roboter.exceptions.RobotMagicValueException; + +class C3POTest { + + @Test + void getIdTest() { + C3PO test = new C3PO("test", 123); + assertEquals(123, test.getId()); + } + + @Test + void getRobotTypeTest() { + C3PO test = new C3PO("test", 123); + assertEquals(RobotType.C3PO, test.getRobotType()); + } + + @Test + void powerTest() { + C3PO test = new C3PO("test", 123); + int[] arr = { 1, 3, 5 }; + assertThrows(RobotIllegalStateException.class, () -> test.think(arr)); + } + + @Test + void magicValueTest() { + C3PO test = new C3PO("test", 123); + test.triggerPowerSwitch(); + int[] arr = { 1, 5, 42, 7, 15 }; + Throwable exception = assertThrows(RobotMagicValueException.class, () -> test.think(arr)); + assertEquals("Fehler! Zahl 42 im Array!", exception.getMessage()); + } + + @Test + void thinkTest() { + C3PO test = new C3PO("test", 123); + test.triggerPowerSwitch(); + int[] arr = { 1, 5, 43, 7, 15 }; + int[] ziel = { 43, 15, 7, 5, 1 }; + try { + assertArrayEquals(ziel, test.think(arr)); + } catch (RobotException e) { + e.printStackTrace(); + System.out.println("Zahlen im Array sind ungültig!"); + } + } +}