diff --git a/RobotAbgabe.iml b/RobotAbgabe.iml
index 850fc7d..901477e 100644
--- a/RobotAbgabe.iml
+++ b/RobotAbgabe.iml
@@ -18,5 +18,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/roboter/Nexus6.java b/src/main/java/roboter/Nexus6.java
index dd1b97b..06cff81 100644
--- a/src/main/java/roboter/Nexus6.java
+++ b/src/main/java/roboter/Nexus6.java
@@ -4,12 +4,14 @@ import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
import roboter.exceptions.RobotException;
+import java.util.ArrayList;
+
public class Nexus6 implements Robot {
private int id = 19281982;
private String name = "pris";
private boolean isPowerOn = false;
-
+ ArrayList exceptionList=new ArrayList<>();
private static Nexus6 instance = new Nexus6();
@@ -48,19 +50,24 @@ public class Nexus6 implements Robot {
@Override
public RobotException getLastException() {
- return null;
+ return exceptionList.get(exceptionList.size()-1);
}
@Override
public String speak(int[] zahlen) throws RobotIllegalStateException {
- throw new RobotIllegalStateException(this);
+ var newException = new RobotIllegalStateException(this);
+ exceptionList.add(newException);
+ throw newException;
}
@Override
public int[] think(int[] zahlen) throws RobotIllegalStateException {
- throw new RobotIllegalStateException(this);
+ var newException2=new RobotIllegalStateException(this);
+ exceptionList.add(newException2);
+ throw newException2;
+
}
diff --git a/src/main/java/roboter/RobotFactory.java b/src/main/java/roboter/RobotFactory.java
index 5b2845c..af67b8a 100644
--- a/src/main/java/roboter/RobotFactory.java
+++ b/src/main/java/roboter/RobotFactory.java
@@ -4,6 +4,13 @@ public class RobotFactory {
private static int R2D2Id=0;
private static int C2POId=10000;
+ /**
+ * Dies ist eine Factory methode, mit der man einen Roboter
+ * mit einem bestimmten typ und namen generieren lassen kann
+ * @param typ Typ vom Roboter
+ * @param name Name vom Roboter
+ * @return ein Roboter Objekt
+ */
public static Robot getRobot(Typ typ,String name){
switch (typ){
case R2D2:
diff --git a/src/test/java/roboter/FactoryTest.java b/src/test/java/roboter/FactoryTest.java
index cad4339..f20de78 100644
--- a/src/test/java/roboter/FactoryTest.java
+++ b/src/test/java/roboter/FactoryTest.java
@@ -26,4 +26,5 @@ public class FactoryTest {
+
}
diff --git a/src/test/java/roboter/R2D2Test.java b/src/test/java/roboter/R2D2Test.java
new file mode 100644
index 0000000..12338e9
--- /dev/null
+++ b/src/test/java/roboter/R2D2Test.java
@@ -0,0 +1,44 @@
+package roboter;
+
+import org.junit.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DynamicNode;
+import roboter.exceptions.RobotException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Properties;
+
+
+
+public class R2D2Test {
+
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+ private final PrintStream originalOut = System.out;
+ private final PrintStream originalErr = System.err;
+
+ @Before
+ public void setStreams() {
+ System.setOut(new PrintStream(out));
+ System.setErr(new PrintStream(err));
+ }
+
+ @After
+ public void restoreInitialStreams() {
+ System.setOut(originalOut);
+ System.setErr(originalErr);
+ }
+
+
+ @Test
+ public void sortieren() throws RobotException {
+ var list = new int[]{12,6,7,10,18,2};
+ Robot robot= RobotFactory.getRobot(Typ.R2D2,"roboter2");
+
+
+ Assert.assertEquals("2,6,7,10,12,18",robot.speak(list));
+ }
+
+}