R2D2 Test und Roboter Test erweitert
parent
11fd265348
commit
9ee42e098f
|
@ -0,0 +1,57 @@
|
|||
package Domäne;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
class R2D2Test {
|
||||
|
||||
@Test
|
||||
void getIdTest() {
|
||||
R2D2 junit = new R2D2("junit", 1);
|
||||
assertEquals(1, junit.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRobotTypeTest() {
|
||||
R2D2 junit = new R2D2("junit", 1);
|
||||
assertEquals(RobotType.R2D2, junit.getRobotType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void powerTest() {
|
||||
R2D2 junit = new R2D2("junit", 1);
|
||||
int[] arr = { 1, 3, 5 };
|
||||
assertThrows(RobotIllegalStateException.class, () -> junit.think(arr));
|
||||
}
|
||||
|
||||
@Test
|
||||
void magicValueTest() {
|
||||
R2D2 junit = new R2D2("junit", 1);
|
||||
junit.triggerPowerSwitch();
|
||||
int[] arr = { 1, 5, 42, 7, 15 };
|
||||
Throwable exception = assertThrows(RobotMagicValueException.class, () -> junit.think(arr));
|
||||
assertEquals("Fehler! Zahl 42 im Array!", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void thinkTest() {
|
||||
R2D2 junit = new R2D2("junit", 1);
|
||||
junit.triggerPowerSwitch();
|
||||
int[] arr = { 1, 5, 43, 7, 15 };
|
||||
int[] ziel = { 1, 5, 7, 15, 43 };
|
||||
try {
|
||||
assertArrayEquals(ziel, junit.think(arr));
|
||||
} catch (RobotException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Zahlen im Array sind ungültig!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,17 @@
|
|||
package Domäne;
|
||||
|
||||
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.Test;
|
||||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
class RoboterTest {
|
||||
|
||||
|
@ -56,4 +63,28 @@ class RoboterTest {
|
|||
assertFalse(pris.isPowerOn());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void prepareAndSpeakTest() {
|
||||
Roboter test1 = new R2D2("Test", 123);
|
||||
Roboter test2 = new C3PO("Test2", 321);
|
||||
int[] arr = { 1, 2, 3 };
|
||||
int[] douglas = { 1, 2, 42 };
|
||||
assertThrows(RobotIllegalStateException.class, () -> test1.speak(arr));
|
||||
test1.triggerPowerSwitch();
|
||||
test2.triggerPowerSwitch();
|
||||
Throwable exception = assertThrows(RobotMagicValueException.class, () -> test1.think(douglas));
|
||||
assertEquals("Fehler! Zahl 42 im Array!", exception.getMessage());
|
||||
|
||||
try {
|
||||
assertEquals("1, 2, 3, ", test1.speak(arr));
|
||||
test2.think(arr);
|
||||
assertEquals("3; 2; 1; ", test2.speak(arr));
|
||||
} catch (RobotException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.out.println("Zahlen im Array sind ungültig!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue