diff --git a/src/Main.java b/src/Main.java index 29e86ec..5d7b247 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,26 +1,36 @@ import de.hsmannheim.informatik.name.domain.RobotFactory; 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.requirements.Robot; + import java.util.Random; public class Main { - public static void main(String[] args) throws RobotIllegalStateException { - RobotFactory rf = new RobotFactory(); - RobotType R2D2 = RobotType.R2D2; - RobotType C3P0 = RobotType.C3P0; - for (int i = 0; i < 10000; i++) { - if(rf.getRobot(R2D2, "TestR2D2") == null){ - System.out.println("Error"); - } - } - 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"); - } +// public static void main(String[] args) throws RobotException { +// RobotFactory rf = new RobotFactory(); +// RobotType R2D2 = RobotType.R2D2; +// RobotType C3P0 = RobotType.C3P0; +//// for (int i = 0; i < 10000; i++) { +//// if(rf.getRobot(R2D2, "TestR2D2") == null){ +//// System.out.println("Error"); +//// } +//// } +// Robot r1 = rf.getRobot(R2D2, "R2Test"); +// System.out.println(r1.getName()); +// try{ +// r1.think(new int[]{1,2,42,5}); +// } catch (RobotException re) { +// System.err.println(re.getRobotName()); +// } +// 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"); +// } } \ No newline at end of file diff --git a/tests/de/hsmannheim/informatik/name/domain/RobotFactoryTest.java b/tests/de/hsmannheim/informatik/name/domain/RobotFactoryTest.java index 7ada450..586e3bc 100644 --- a/tests/de/hsmannheim/informatik/name/domain/RobotFactoryTest.java +++ b/tests/de/hsmannheim/informatik/name/domain/RobotFactoryTest.java @@ -18,7 +18,7 @@ class RobotFactoryTest { assertNull( rf.getRobot(R2D2, "TestR2D2")); } @Test - public void toMuchC3P0() throws RobotIllegalStateException { + public void toMuchC3P0() throws RobotIllegalStateException { RobotFactory rf = new RobotFactory(); RobotType R2D2 = RobotType.C3P0; for (int i = 0; i < 9999; i++) { @@ -27,4 +27,5 @@ class RobotFactoryTest { assertInstanceOf(C3PO.class, rf.getRobot(R2D2, "Test")); assertNull( rf.getRobot(R2D2, "TestC3P0")); } + } \ No newline at end of file diff --git a/tests/de/hsmannheim/informatik/name/domain/bladerunner/NexusTest.java b/tests/de/hsmannheim/informatik/name/domain/bladerunner/NexusTest.java new file mode 100644 index 0000000..0056bf6 --- /dev/null +++ b/tests/de/hsmannheim/informatik/name/domain/bladerunner/NexusTest.java @@ -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()); + } + +} diff --git a/tests/de/hsmannheim/informatik/name/domain/starwars/GetterTest.java b/tests/de/hsmannheim/informatik/name/domain/starwars/GetterTest.java new file mode 100644 index 0000000..311f3aa --- /dev/null +++ b/tests/de/hsmannheim/informatik/name/domain/starwars/GetterTest.java @@ -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()); + } + } + + + +}