Legger til manglende sjekking av retning for en vegg som instansieres

Legger til en test som sjekker at en exception blir kastet når en ugyldig vegg blir forsøkt instansiert
Legger til en test som sjekker at en exception blir kastet når en ugyldig tile blir forsøkt instansiert
This commit is contained in:
Kristian Knarvik 2020-03-02 13:26:42 +01:00
parent d7186d38c3
commit c6083c2a70
3 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,9 @@ public class Wall {
* @param direction The direction of the wall
*/
public Wall (WallType wallType, Direction direction) {
if (direction.getDirectionID() % 2 == 0 && wallType != WallType.WALL_CORNER) {
throw new IllegalArgumentException("Invalid direction for wall type submitted");
}
this.wallType = wallType;
this.direction = direction;
}

View File

@ -1,5 +1,6 @@
package inf112.fiasko.roborally.element_properties;
import inf112.fiasko.roborally.objects.Tile;
import org.junit.Test;
import java.util.ArrayList;
@ -44,6 +45,11 @@ public class TileTypeTest {
assertNull(TileType.getTileTypeFromID(-1));
}
@Test (expected = IllegalArgumentException.class)
public void invalidTileDirectionThrowsError() {
new Tile(TileType.TILE, Direction.NORTH_EAST);
}
@Test
public void allTilesHaveUniqueId() {
/* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail

View File

@ -1,5 +1,6 @@
package inf112.fiasko.roborally.element_properties;
import inf112.fiasko.roborally.objects.Wall;
import org.junit.Test;
import java.util.ArrayList;
@ -44,6 +45,11 @@ public class WallTypeTest {
assertNull(TileType.getTileTypeFromID(-1));
}
@Test (expected = IllegalArgumentException.class)
public void invalidWallDirectionThrowsError() {
new Wall(WallType.WALL_NORMAL, Direction.NORTH_EAST);
}
@Test
public void allWallsHaveUniqueId() {
/* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail