RobotFactoryTest überprüft zufällige Id-Vergabe
parent
9ee42e098f
commit
a89876eacf
|
@ -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<Roboter> list = new ArrayList<Roboter>();
|
||||
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<Roboter>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue