parent
91e1c5afa0
commit
87815a7318
|
@ -5,17 +5,13 @@ import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
|||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
public class C3PO extends Roboter {
|
||||
private String name;
|
||||
private int id;
|
||||
//static int idZähler = 10000;
|
||||
private RobotType robotType;
|
||||
//RobotException fehler;
|
||||
|
||||
public C3PO(String name, int id) {
|
||||
super(name);
|
||||
this.robotType = robotType.C3PO;
|
||||
this.robotType = RobotType.C3PO;
|
||||
this.id = id;
|
||||
//idZähler++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,9 +47,9 @@ public class C3PO extends Roboter {
|
|||
throw fehler;
|
||||
|
||||
}
|
||||
|
||||
public RobotType getRobotType() {
|
||||
return this.robotType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,21 +7,16 @@ public class Nexus6 extends Roboter {
|
|||
|
||||
private String name;
|
||||
private int id;
|
||||
//RobotException fehler;
|
||||
private static Nexus6 PRIS;
|
||||
private RobotType robotType;
|
||||
|
||||
|
||||
private Nexus6() {
|
||||
super("Pris");
|
||||
this.id = 19_281_982;
|
||||
robotType = RobotType.NEXUS6;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Nexus6 getInstance() {
|
||||
if (PRIS == null) {
|
||||
PRIS = new Nexus6();
|
||||
|
@ -35,11 +30,11 @@ public class Nexus6 extends Roboter {
|
|||
power = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
||||
@Override
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
|
@ -54,11 +49,8 @@ public class Nexus6 extends Roboter {
|
|||
fehler = new RobotIllegalStateException("Roboter ausgeschaltet und Defekt!", this.name);
|
||||
throw fehler;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public RobotType getRobotType() {
|
||||
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
package Domäne;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import tpe.exceptions.roboter.Robot;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
public class R2D2 extends Roboter {
|
||||
private int id;
|
||||
//private static int idZähler = 0;
|
||||
private RobotType robotType;
|
||||
//RobotException fehler;
|
||||
|
||||
public R2D2(String name, int id) {
|
||||
super(name);
|
||||
this.robotType = RobotType.R2D2;
|
||||
this.id = id;
|
||||
//idZähler++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,6 +44,7 @@ public class R2D2 extends Roboter {
|
|||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RobotType getRobotType() {
|
||||
return this.robotType;
|
||||
}
|
||||
|
|
|
@ -21,14 +21,12 @@ public RobotFactory (String name) {
|
|||
roboter = new R2D2(name, idVergeben(0, 9999));
|
||||
roboterLager.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
}
|
||||
else if (RobotType.C3PO == robotType) {
|
||||
} else if (RobotType.C3PO == robotType) {
|
||||
roboter = new C3PO(name, idVergeben(10000, 19999));
|
||||
roboterLager.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
|
||||
}
|
||||
else
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -39,6 +37,7 @@ public RobotFactory (String name) {
|
|||
public Roboter findeRoboter(int id) {
|
||||
return roboterLager.get(id);
|
||||
}
|
||||
|
||||
private int idVergeben(int min, int max) {
|
||||
|
||||
int randomValue = (int) (Math.random() * (max - min)) + min;
|
||||
|
@ -54,6 +53,7 @@ public RobotFactory (String name) {
|
|||
boolean zustand = r.isPowerOn();
|
||||
return zustand;
|
||||
}
|
||||
|
||||
public boolean schalterAnAus(int id) {
|
||||
Roboter r = findeRoboter(id);
|
||||
r.triggerPowerSwitch();
|
||||
|
@ -68,6 +68,7 @@ public RobotFactory (String name) {
|
|||
return ausgabe;
|
||||
|
||||
}
|
||||
|
||||
public RobotException letzterFehler(int id) {
|
||||
Roboter r = findeRoboter(id);
|
||||
return r.getLastException();
|
||||
|
|
|
@ -10,11 +10,11 @@ import tpe.exceptions.roboter.exceptions.RobotException;
|
|||
class RobotFactoryTest {
|
||||
private static RobotFactory rf;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
static void initRobotFactory() {
|
||||
rf = new RobotFactory("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void smokeTest() {
|
||||
assertNotNull(rf);
|
||||
|
|
|
@ -93,4 +93,3 @@ public abstract class Roboter implements Robot {
|
|||
|
||||
public abstract RobotType getRobotType();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class RoboterTest {
|
|||
assertEquals(robi.getName(), "Test2");
|
||||
assertEquals(10000, robi.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void triggerPowerSwitchTest() {
|
||||
Roboter r2d2 = new R2D2("Test", 1);
|
||||
|
@ -31,6 +32,7 @@ class RoboterTest {
|
|||
assertTrue(c3po.isPowerOn());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLastExceptionTest() {
|
||||
Roboter r2d2 = new R2D2("Test", 1);
|
||||
|
@ -39,8 +41,10 @@ class RoboterTest {
|
|||
try {
|
||||
r2d2.think(zahlen);
|
||||
} catch (RobotException e) {
|
||||
} assertNotNull(r2d2.getLastException());
|
||||
}
|
||||
assertNotNull(r2d2.getLastException());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nexus6SingletonTest() {
|
||||
Roboter pris = Nexus6.getInstance();
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
package facade;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import Domäne.C3PO;
|
||||
import Domäne.R2D2;
|
||||
import Domäne.RobotFactory;
|
||||
import Domäne.RobotType;
|
||||
import Domäne.Roboter;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public class Factorysystem {
|
||||
private RobotFactory robotFactory;
|
||||
|
||||
|
||||
public Factorysystem(String name) {
|
||||
this.robotFactory = new RobotFactory(name);
|
||||
}
|
||||
|
|
|
@ -4,17 +4,17 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
|
||||
class SystemTest {
|
||||
|
||||
private static Factorysystem fs;
|
||||
|
||||
@BeforeAll
|
||||
static void initFactorysystem() {
|
||||
fs = new Factorysystem("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void smokeTest() {
|
||||
assertNotNull(fs);
|
||||
|
@ -27,7 +27,8 @@ class SystemTest {
|
|||
int id2 = fs.roboterAnlegen("Test2", 2);
|
||||
assertEquals("RoboterType: " + "R2D2" + "; Name: " + "Test" + "; Seriennummer: " + id, fs.roboterDaten(id));
|
||||
assertEquals("RoboterType: " + "C3PO" + "; Name: " + "Test2" + "; Seriennummer: " + id2, fs.roboterDaten(id2));
|
||||
assertEquals("RoboterType: " + "NEXUS6" + "; Name: " +"Pris" + "; Seriennummer: " + 19281982,fs.roboterDaten(19281982));
|
||||
assertEquals("RoboterType: " + "NEXUS6" + "; Name: " + "Pris" + "; Seriennummer: " + 19281982,
|
||||
fs.roboterDaten(19281982));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,6 +51,7 @@ class SystemTest {
|
|||
assertNotNull(fs.fehlerAuslesen(id));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void sprechenTest() throws RobotException {
|
||||
int id = fs.roboterAnlegen("Test", 1);
|
||||
|
|
Loading…
Reference in New Issue