@Test public void getDirectionNull() { assertThatThrownBy(() -> grid.get(1,0).get(null)) .isInstanceOf(IllegalArgumentException.class); }
public Tile get(Direction direction) { Grid grid = getGrid(); int x = getX(); int y = getY(); if (direction == null) { throw new IllegalArgumentException(); } Tile result = null; switch (direction) { case TOP: result = grid.get(x, y + 1); break; case RIGHT: result = grid.get(x + 1, y); break; case BOTTOM: result = grid.get(x, y - 1); break; case LEFT: result = grid.get(x - 1, y); break; default: } return result; }
Tile implements Entity { public Tile get(Direction direction) { Grid grid = getGrid(); int x = getX(); int y = getY(); if (direction == null) { throw new IllegalArgumentException(); } Tile result = null; switch (direction) { case TOP: result = grid.get(x, y + 1); break; case RIGHT: result = grid.get(x + 1, y); break; case BOTTOM: result = grid.get(x, y - 1); break; case LEFT: result = grid.get(x - 1, y); break; default: } return result; } }
Tile implements Entity { public Tile get(Direction direction) { Grid grid = getGrid(); int x = getX(); int y = getY(); if (direction == null) { throw new IllegalArgumentException(); } Tile result = null; switch (direction) { case TOP: result = grid.get(x, y + 1); break; case RIGHT: result = grid.get(x + 1, y); break; case BOTTOM: result = grid.get(x, y - 1); break; case LEFT: result = grid.get(x - 1, y); break; default: } return result; } Tile(); }
Tile implements Entity { public Tile get(Direction direction) { Grid grid = getGrid(); int x = getX(); int y = getY(); if (direction == null) { throw new IllegalArgumentException(); } Tile result = null; switch (direction) { case TOP: result = grid.get(x, y + 1); break; case RIGHT: result = grid.get(x + 1, y); break; case BOTTOM: result = grid.get(x, y - 1); break; case LEFT: result = grid.get(x - 1, y); break; default: } return result; } Tile(); Tileable getTileable(); boolean isOccupied(); Tile get(Direction direction); abstract int getX(); abstract int getY(); abstract Grid getGrid(); }
Tile implements Entity { public Tile get(Direction direction) { Grid grid = getGrid(); int x = getX(); int y = getY(); if (direction == null) { throw new IllegalArgumentException(); } Tile result = null; switch (direction) { case TOP: result = grid.get(x, y + 1); break; case RIGHT: result = grid.get(x + 1, y); break; case BOTTOM: result = grid.get(x, y - 1); break; case LEFT: result = grid.get(x - 1, y); break; default: } return result; } Tile(); Tileable getTileable(); boolean isOccupied(); Tile get(Direction direction); abstract int getX(); abstract int getY(); abstract Grid getGrid();  }