Sortieren R2D2tests

master
azadehobenland 2023-01-09 11:50:10 +01:00
parent 023365e653
commit b646f251a5
5 changed files with 79 additions and 4 deletions

View File

@ -18,5 +18,21 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.7.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.0/junit-jupiter-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.0/junit-platform-commons-1.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.0/junit-jupiter-params-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.0/junit-jupiter-engine-5.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.0/junit-platform-engine-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -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<RobotException> 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;
}

View File

@ -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:

View File

@ -26,4 +26,5 @@ public class FactoryTest {
}

View File

@ -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<SystemOutRule, OutputCapture> {
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));
}
}