Sortieren R2D2tests
parent
023365e653
commit
b646f251a5
|
@ -18,5 +18,21 @@
|
||||||
<SOURCES />
|
<SOURCES />
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</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>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -4,12 +4,14 @@ import roboter.exceptions.RobotException;
|
||||||
import roboter.exceptions.RobotIllegalStateException;
|
import roboter.exceptions.RobotIllegalStateException;
|
||||||
import roboter.exceptions.RobotException;
|
import roboter.exceptions.RobotException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Nexus6 implements Robot {
|
public class Nexus6 implements Robot {
|
||||||
|
|
||||||
private int id = 19281982;
|
private int id = 19281982;
|
||||||
private String name = "pris";
|
private String name = "pris";
|
||||||
private boolean isPowerOn = false;
|
private boolean isPowerOn = false;
|
||||||
|
ArrayList<RobotException> exceptionList=new ArrayList<>();
|
||||||
|
|
||||||
private static Nexus6 instance = new Nexus6();
|
private static Nexus6 instance = new Nexus6();
|
||||||
|
|
||||||
|
@ -48,19 +50,24 @@ public class Nexus6 implements Robot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RobotException getLastException() {
|
public RobotException getLastException() {
|
||||||
return null;
|
return exceptionList.get(exceptionList.size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String speak(int[] zahlen) throws RobotIllegalStateException {
|
public String speak(int[] zahlen) throws RobotIllegalStateException {
|
||||||
throw new RobotIllegalStateException(this);
|
var newException = new RobotIllegalStateException(this);
|
||||||
|
exceptionList.add(newException);
|
||||||
|
throw newException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotIllegalStateException {
|
public int[] think(int[] zahlen) throws RobotIllegalStateException {
|
||||||
throw new RobotIllegalStateException(this);
|
var newException2=new RobotIllegalStateException(this);
|
||||||
|
exceptionList.add(newException2);
|
||||||
|
throw newException2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,13 @@ public class RobotFactory {
|
||||||
private static int R2D2Id=0;
|
private static int R2D2Id=0;
|
||||||
private static int C2POId=10000;
|
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){
|
public static Robot getRobot(Typ typ,String name){
|
||||||
switch (typ){
|
switch (typ){
|
||||||
case R2D2:
|
case R2D2:
|
||||||
|
|
|
@ -26,4 +26,5 @@ public class FactoryTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue