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!"); } } }