fixed tests

main
zlohbierdcul 2023-01-09 22:30:15 +01:00
parent 3ca05973b8
commit 74c088e4fb
2 changed files with 38 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package de.hsmannheim.informatik.name.domain.starwars;
import de.hsmannheim.informatik.name.domain.exceptions.RobotException; import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -10,15 +11,29 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class SpeakTest { class SpeakTest {
final R2D2 r2d2 = new R2D2(9999, "test");
final C3PO c3po = new C3PO(19999, "test");
private R2D2 r2d2;
SpeakTest() throws RobotIllegalStateException { private C3PO c3po;
@BeforeEach
void setup() throws RobotIllegalStateException {
r2d2 = new R2D2(9999, "test");
c3po = new C3PO(19999, "test");
r2d2.triggerPowerSwitch(); r2d2.triggerPowerSwitch();
c3po.triggerPowerSwitch(); c3po.triggerPowerSwitch();
} }
SpeakTest() throws RobotIllegalStateException {
}
@Test
void RobotOffSpeakTest() {
r2d2.triggerPowerSwitch();
c3po.triggerPowerSwitch();
assertThrows(RobotIllegalStateException.class, () -> r2d2.speak(new int[1]));
assertThrows(RobotIllegalStateException.class, () -> c3po.speak(new int[1]));
}
@Test @Test
void R2D2SpeakTestStandard() throws RobotException { void R2D2SpeakTestStandard() throws RobotException {
assertEquals("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12", r2d2.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12})); assertEquals("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12", r2d2.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));

View File

@ -3,6 +3,7 @@ package de.hsmannheim.informatik.name.domain.starwars;
import de.hsmannheim.informatik.name.domain.exceptions.RobotException; import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@ -10,14 +11,28 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class ThinkTest { class ThinkTest {
private final R2D2 r2d2 = new R2D2(9999, "test"); private R2D2 r2d2;
private final C3PO c3po = new C3PO(19999, "test"); private C3PO c3po;
@BeforeEach
ThinkTest() throws RobotIllegalStateException { void setup() throws RobotIllegalStateException {
r2d2 = new R2D2(9999, "test");
c3po = new C3PO(19999, "test");
r2d2.triggerPowerSwitch(); r2d2.triggerPowerSwitch();
c3po.triggerPowerSwitch(); c3po.triggerPowerSwitch();
} }
@Test
void C3POTurnedOffThinkTest() {
r2d2.triggerPowerSwitch();
assertThrows(RobotIllegalStateException.class, () -> r2d2.think(new int[1]));
}
@Test
void R2D2TurnedOffThinkTest() {
c3po.triggerPowerSwitch();
assertThrows(RobotIllegalStateException.class, () -> c3po.think(new int[1]));
}
@Test @Test
void thinkTestStandard() throws RobotException { void thinkTestStandard() throws RobotException {
assertArrayEquals(new int[]{0, 1, 2, 3, 4, 5}, r2d2.think(new int[]{3, 0, 1, 5, 2, 4})); assertArrayEquals(new int[]{0, 1, 2, 3, 4, 5}, r2d2.think(new int[]{3, 0, 1, 5, 2, 4}));