From a89876eacf97234cf4ce7ec28d5e034ccb5a4060 Mon Sep 17 00:00:00 2001 From: KDippold <2023962@stud.hs-mannheim.de> Date: Sun, 8 Jan 2023 02:00:01 +0100 Subject: [PATCH] =?UTF-8?q?RobotFactoryTest=20=C3=BCberpr=C3=BCft=20zuf?= =?UTF-8?q?=C3=A4llige=20Id-Vergabe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Domäne/RobotFactoryTest.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Roboterfabrik/src/Domäne/RobotFactoryTest.java b/Roboterfabrik/src/Domäne/RobotFactoryTest.java index fc653f2..0c76b35 100644 --- a/Roboterfabrik/src/Domäne/RobotFactoryTest.java +++ b/Roboterfabrik/src/Domäne/RobotFactoryTest.java @@ -1,12 +1,21 @@ package Domäne; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import tpe.exceptions.roboter.exceptions.RobotException; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) class RobotFactoryTest { private static RobotFactory rf; @@ -15,12 +24,14 @@ class RobotFactoryTest { rf = new RobotFactory("Test"); } + @Order(1) @Test void smokeTest() { assertNotNull(rf); assertEquals(1, rf.getRoboterLagerSize()); } + @Order(2) @Test void addRoboterTest() { int id = rf.addRobot(RobotType.R2D2, "Test"); @@ -29,6 +40,7 @@ class RobotFactoryTest { assertEquals(3, rf.getRoboterLagerSize()); } + @Order(3) @Test void zustandTest() { int id = rf.addRobot(RobotType.R2D2, "Test"); @@ -38,18 +50,45 @@ class RobotFactoryTest { } + @Order(4) @Test void aufrufSpeakAndThinkTest() throws RobotException { int id = rf.addRobot(RobotType.R2D2, "Test"); + int id2 = rf.addRobot(RobotType.C3PO, "Test2"); rf.schalterAnAus(id); + rf.schalterAnAus(id2); int[] zahlen = { 5, 8, 4, 3, 7 }; assertEquals("3, 4, 5, 7, 8, ", rf.aufrufSpeakAndThink(id, zahlen)); + assertEquals("8; 7; 5; 4; 3; ", rf.aufrufSpeakAndThink(id2, zahlen)); } + @Order(5) @Test void datenDesRobotersTest() { int id = rf.addRobot(RobotType.R2D2, "Test"); assertEquals("RoboterType: " + "R2D2" + "; Name: " + "Test" + "; Seriennummer: " + id, rf.datenDesRoboters(id)); } + @Order(6) + @Test + void idVergebenTest() { + rf = new RobotFactory("Test2"); + ArrayList list = new ArrayList(); + for (int i = 0; i < 10000; i++) { + list.add(rf.findeRoboter(rf.addRobot(RobotType.R2D2, "Test" + i))); + } + for (Roboter r : list) { + assertTrue(r.getId() < 10000 && r.getId() >= 0); + } + rf = new RobotFactory("Test2"); + list = new ArrayList(); + for (int i = 0; i < 10000; i++) { + list.add(rf.findeRoboter(rf.addRobot(RobotType.C3PO, "Test" + i))); + } + for (Roboter r : list) { + assertTrue(r.getId() >= 10000 && r.getId() <= 19999); + } + + } + }