added tests for Nexus6 and RobotBluePrint

main
zlohbierdcul 2023-01-06 19:05:34 +01:00
parent b18663a28e
commit 9422e5c6ae
4 changed files with 117 additions and 19 deletions

View File

@ -1,26 +1,36 @@
import de.hsmannheim.informatik.name.domain.RobotFactory; import de.hsmannheim.informatik.name.domain.RobotFactory;
import de.hsmannheim.informatik.name.domain.RobotType; import de.hsmannheim.informatik.name.domain.RobotType;
import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import de.hsmannheim.informatik.name.domain.requirements.Robot;
import java.util.Random; import java.util.Random;
public class Main { public class Main {
public static void main(String[] args) throws RobotIllegalStateException { // public static void main(String[] args) throws RobotException {
RobotFactory rf = new RobotFactory(); // RobotFactory rf = new RobotFactory();
RobotType R2D2 = RobotType.R2D2; // RobotType R2D2 = RobotType.R2D2;
RobotType C3P0 = RobotType.C3P0; // RobotType C3P0 = RobotType.C3P0;
for (int i = 0; i < 10000; i++) { //// for (int i = 0; i < 10000; i++) {
if(rf.getRobot(R2D2, "TestR2D2") == null){ //// if(rf.getRobot(R2D2, "TestR2D2") == null){
System.out.println("Error"); //// System.out.println("Error");
} //// }
} //// }
System.out.println("finished R2D2"); // Robot r1 = rf.getRobot(R2D2, "R2Test");
for (int i = 0; i < 10000; i++) { // System.out.println(r1.getName());
if(rf.getRobot(C3P0, "TestC3P0") == null){ // try{
System.out.println("Error"); // r1.think(new int[]{1,2,42,5});
} // } catch (RobotException re) {
} // System.err.println(re.getRobotName());
System.out.println("finished C3P0"); // }
System.out.println("finished"); // System.out.println("finished R2D2");
} // for (int i = 0; i < 10000; i++) {
// if(rf.getRobot(C3P0, "TestC3P0") == null){
// System.out.println("Error");
// }
// }
// System.out.println("finished C3P0");
// System.out.println("finished");
// }
} }

View File

@ -27,4 +27,5 @@ class RobotFactoryTest {
assertInstanceOf(C3PO.class, rf.getRobot(R2D2, "Test")); assertInstanceOf(C3PO.class, rf.getRobot(R2D2, "Test"));
assertNull( rf.getRobot(R2D2, "TestC3P0")); assertNull( rf.getRobot(R2D2, "TestC3P0"));
} }
} }

View File

@ -0,0 +1,34 @@
package de.hsmannheim.informatik.name.domain.bladerunner;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class NexusTest {
@Test
public void toManyNexusTest() throws RobotIllegalStateException {
Nexus6 n1 = Nexus6.getInstance();
assertEquals(n1, Nexus6.getInstance());
}
@Test
public void nexusThinkTest() throws RobotIllegalStateException {
Nexus6 n1 = Nexus6.getInstance();
assertThrows(RobotIllegalStateException.class, () -> n1.think(new int[]{1,2,3,4}));
}
@Test
public void nexusSpeakTest() throws RobotIllegalStateException {
Nexus6 n1 = Nexus6.getInstance();
assertThrows(RobotIllegalStateException.class, () -> n1.speak(new int[]{1,2,3,4}));
}
@Test
public void testPowerSwitch() throws RobotIllegalStateException {
Nexus6 n1 = Nexus6.getInstance();
n1.triggerPowerSwitch();
assertFalse(n1.isPowerOn());
}
}

View File

@ -0,0 +1,53 @@
package de.hsmannheim.informatik.name.domain.starwars;
import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class GetterTest {
@Test
public void getIDTest() throws RobotIllegalStateException {
C3PO c1 = new C3PO(10001, "C3PO");
assertEquals(10001, c1.getId());
}
@Test
public void getNameTest() throws RobotIllegalStateException {
C3PO c1 = new C3PO(10001, "C3PO");
assertEquals("C3PO", c1.getName());
}
@Test
public void powerSwitchTest() throws RobotIllegalStateException {
C3PO c1 = new C3PO(10001, "C3PO");
assertFalse(c1.isPowerOn());
c1.triggerPowerSwitch();
assertTrue(c1.isPowerOn());
}
@Test
public void getLastExceptionTest() throws RobotIllegalStateException {
C3PO c1 = new C3PO(10001, "C3PO");
try {
c1.think(new int[]{42});
} catch (RobotException e) {
assertEquals(e, c1.getLastException());
}
}
@Test
public void getNameFromExceptionTest() throws RobotIllegalStateException {
C3PO c1 = new C3PO(10001, "C3PO");
try {
c1.think(new int[]{42});
} catch (RobotException e) {
assertEquals(c1.getName(), e.getRobotName());
}
}
}