Exceptions geben den Namen des Roboters wieder, SystemTest erweitert
parent
9b093fba51
commit
7190a6a127
|
@ -1,10 +1,17 @@
|
|||
package facade;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
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 {
|
||||
|
||||
|
@ -37,6 +44,8 @@ class SystemTest {
|
|||
assertFalse(fs.zustandRoboter(id));
|
||||
fs.schalterBetätigen(id);
|
||||
assertTrue(fs.zustandRoboter(id));
|
||||
fs.schalterBetätigen(id);
|
||||
assertFalse(fs.zustandRoboter(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,10 +65,11 @@ class SystemTest {
|
|||
void sprechenTest() throws RobotException {
|
||||
int id = fs.roboterAnlegen("Test", 1);
|
||||
int id2 = fs.roboterAnlegen("Test2", 2);
|
||||
|
||||
int[] zahlen = { 5, 9, 1, 6 };
|
||||
Throwable exception = assertThrows(RobotIllegalStateException.class, () -> fs.sprechenAufruf(id, zahlen));
|
||||
assertEquals("Roboter ausgeschaltet! Bitte einschalten.", exception.getMessage());
|
||||
fs.schalterBetätigen(id);
|
||||
fs.schalterBetätigen(id2);
|
||||
int[] zahlen = { 5, 9, 1, 6 };
|
||||
|
||||
assertEquals("1, 5, 6, 9, ", fs.sprechenAufruf(id, zahlen));
|
||||
assertEquals("9; 6; 5; 1; ", fs.sprechenAufruf(id2, zahlen));
|
||||
|
|
|
@ -6,8 +6,14 @@ public class RobotException extends Exception {
|
|||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
String name;
|
||||
|
||||
public RobotException(String message) {
|
||||
public RobotException(String message, String name) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getRobotName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,8 @@ public class RobotIllegalStateException extends RobotException {
|
|||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
String name;
|
||||
|
||||
public RobotIllegalStateException(String message, String name) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getRobotName() {
|
||||
return this.name;
|
||||
super(message, name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,9 @@ public class RobotMagicValueException extends RobotException {
|
|||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
String name;
|
||||
|
||||
public RobotMagicValueException(String message, String name) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
super(message, name);
|
||||
}
|
||||
|
||||
public String getRobotName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,7 +258,8 @@ public class Factory {
|
|||
* @param id vom Roboter
|
||||
*/
|
||||
private void letzteFehlermeldung(int id) {
|
||||
System.out.println(factorysystem.fehlerAuslesen(id));
|
||||
RobotException fehler = factorysystem.fehlerAuslesen(id);
|
||||
System.out.println(fehler.getRobotName() + ": " + fehler.getMessage());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue