R2D2 JUnit Test hinzugefügt
parent
50324c8592
commit
a0f16fc808
|
@ -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 R2D2Test {
|
||||
|
||||
@Test
|
||||
void testSetNameGetName() {
|
||||
R2D2 r = new R2D2("Test");
|
||||
assertEquals("Test", r.getName());
|
||||
r.setName("TestNeu");
|
||||
assertEquals("TestNeu", r.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetiDGetiD() {
|
||||
R2D2 r = new R2D2("Test");
|
||||
assertEquals(0, r.getId());
|
||||
R2D2 r2 = new R2D2("Test2");
|
||||
assertNotEquals(1, r2.getId());
|
||||
r2.setiD(2);
|
||||
assertEquals(2, r2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTriggerPowerSwitchIsPowerOn() {
|
||||
R2D2 r = new R2D2("Test");
|
||||
assertEquals(true, r.isPowerOn());
|
||||
r.triggerPowerSwitch();
|
||||
assertEquals(false, r.isPowerOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThinkSpeak() throws RobotException {
|
||||
R2D2 r = new R2D2("Test");
|
||||
int[] zahlen = {2,4,3,1,6,5};
|
||||
assertEquals("2, 4, 3, 1, 6, 5", r.speak(zahlen));
|
||||
int[] zahlenNeu = {1,2,3,4,5,6};
|
||||
Assert.assertArrayEquals(zahlenNeu, r.think(zahlen));
|
||||
assertEquals("1, 2, 3, 4, 5, 6", r.speak(r.think(zahlen)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetLastException() throws RobotException {
|
||||
R2D2 r = new R2D2("Test");
|
||||
int[] zahlen = {42,4,3,1,6,5};
|
||||
r.think(zahlen);
|
||||
assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", r.getLastException().toString());
|
||||
r.speak(zahlen);
|
||||
assertEquals("exceptions.RobotMagicValueException: Zahl 42 kommt vor - Roboter: \"Ihhhhh\"!", r.getLastException().toString());
|
||||
r.triggerPowerSwitch();
|
||||
r.think(zahlen);
|
||||
assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", r.getLastException().toString());
|
||||
r.speak(zahlen);
|
||||
assertEquals("exceptions.RobotIllegalStateException: Leider ist der Roboter aus und kann nichts machen!", r.getLastException().toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue