generated from hummel/Bank-System
62 lines
2.5 KiB
Java
62 lines
2.5 KiB
Java
package tpe.exceptions.roboter;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
import tpe.exceptions.RobotException;
|
|
import tpe.exceptions.RobotIllegalStateException;
|
|
import tpe.exceptions.RobotMagicValueException;
|
|
|
|
public class RobotsTest {
|
|
RobotException robotException;
|
|
Robots robots;
|
|
Robots R2rob= new R2D2("Testname1", 1);
|
|
Robots C3rob=new C3PO("Testname2",10000);
|
|
Robots Nerob=Nexus6.getInstance();
|
|
int[] testZahlen1= {1,4,3,42,78,20};
|
|
int[] testZahlen2= {1,4,3,41,78,20};
|
|
|
|
@Test
|
|
void basicRobotsTest() throws RobotException
|
|
{
|
|
assertEquals(R2rob.getName(),"Testname1");
|
|
assertEquals(R2rob.getId(),1);
|
|
assertFalse(R2rob.powerStatus);
|
|
R2rob.triggerPowerSwitch();
|
|
assertTrue(R2rob.powerStatus);
|
|
|
|
assertEquals(C3rob.getName(),"Testname2");
|
|
assertEquals(C3rob.getId(),10000);
|
|
assertFalse(C3rob.powerStatus);
|
|
C3rob.triggerPowerSwitch();
|
|
assertTrue(C3rob.powerStatus);
|
|
|
|
assertEquals(Nerob.getName(),"Pris");
|
|
assertEquals(Nerob.getId(),19281982);
|
|
assertFalse(Nerob.powerStatus);
|
|
}
|
|
|
|
@Test
|
|
void speakAndThinkTest() throws RobotException{
|
|
RobotIllegalStateException thrownState=Assertions.assertThrows(RobotIllegalStateException.class,() -> R2rob.speak(testZahlen2));
|
|
assertEquals(thrownState.getMessage(),"Robotname-Testname1: Der Roboter ist ausgeschaltet!");
|
|
R2rob.triggerPowerSwitch();
|
|
assertEquals("1, 3, 4, 20, 41, 78", R2rob.speak(R2rob.think(testZahlen2)));
|
|
RobotMagicValueException thrownValue=Assertions.assertThrows(RobotMagicValueException.class,() -> R2rob.speak(testZahlen1));
|
|
assertEquals(thrownValue.getMessage(),"Robotname-Testname1: Zahl 42 kann nicht verarbeitet werden!");
|
|
|
|
RobotIllegalStateException thrownState2=Assertions.assertThrows(RobotIllegalStateException.class,() -> C3rob.speak(testZahlen2));
|
|
assertEquals(thrownState2.getMessage(),"Robotname-Testname2: Der Roboter ist ausgeschaltet!");
|
|
C3rob.triggerPowerSwitch();
|
|
assertEquals("78; 41; 20; 4; 3; 1", C3rob.speak(C3rob.think(testZahlen2)));
|
|
RobotMagicValueException thrownValue2=Assertions.assertThrows(RobotMagicValueException.class,() -> C3rob.speak(testZahlen1));
|
|
assertEquals(thrownValue2.getMessage(),"Robotname-Testname2: Zahl 42 kann nicht verarbeitet werden!");
|
|
|
|
RobotIllegalStateException thrownState3=Assertions.assertThrows(RobotIllegalStateException.class,() -> Nerob.speak(testZahlen2));
|
|
assertEquals(thrownState3.getMessage(),"Robotname-Pris: Der Nexus6-Roboter ist ausgeschaltet!");
|
|
}
|
|
|
|
}
|