C3PO JUnit Test hinzugefügt
parent
d4d52f5ad2
commit
50324c8592
|
@ -0,0 +1,62 @@
|
|||
package domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import exceptions.RobotException;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
class C3POTest {
|
||||
|
||||
@Test
|
||||
void testSetNameGetName() {
|
||||
C3PO c = new C3PO("Test");
|
||||
assertEquals("Test", c.getName());
|
||||
c.setName("TestNeu");
|
||||
assertEquals("TestNeu", c.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetiDGetiD() {
|
||||
C3PO c = new C3PO("Test");
|
||||
assertEquals(10000, c.getId());
|
||||
C3PO c2 = new C3PO("Test2");
|
||||
assertNotEquals(10001, c2.getId());
|
||||
c2.setiD(10002);
|
||||
assertEquals(10002, c2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTriggerPowerSwitchIsPowerOn() {
|
||||
C3PO c = new C3PO("Test");
|
||||
assertEquals(true, c.isPowerOn());
|
||||
c.triggerPowerSwitch();
|
||||
assertEquals(false, c.isPowerOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThinkSpeak() throws RobotException {
|
||||
C3PO c = new C3PO("Test");
|
||||
int[] zahlen = {2,4,3,1,6,5};
|
||||
assertEquals("2; 4; 3; 1; 6; 5", c.speak(zahlen));
|
||||
int[] zahlenNeu = {6,5,4,3,2,1};
|
||||
Assert.assertArrayEquals(zahlenNeu, c.think(zahlen));
|
||||
assertEquals("6; 5; 4; 3; 2; 1", c.speak(c.think(zahlen)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetLastException() throws RobotException {
|
||||
C3PO c = new C3PO("Test");
|
||||
int[] zahlen = {42,4,3,1,6,5};
|
||||
c.think(zahlen);
|
||||
assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", c.getLastException().toString());
|
||||
c.speak(zahlen);
|
||||
assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", c.getLastException().toString());
|
||||
c.triggerPowerSwitch();
|
||||
c.think(zahlen);
|
||||
assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", c.getLastException().toString());
|
||||
c.speak(zahlen);
|
||||
assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", c.getLastException().toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue