AbstractBuilding implements Clickable, Drawable,
        Tickable { public List<Tile> getTiles() { List<Tile> tiles = new ArrayList<>(); int buildingX = (int) location.getX(); int buildingY = (int) location.getY(); for (int y = buildingY; y < buildingY + height; y++) { for (int x = buildingX; x < buildingX + width; x++) { if (x < 0 || x >= world.getWidth() || y < 0 || y >= world.getHeight()) { tiles.add(null); } else { tiles.add(world.getTile(x, y)); } } } return tiles; } AbstractBuilding(World world, int width, int height,
            String imageName); World getWorld(); Point getLocation(); void setLocation(Point location); boolean isLocationValid(); boolean addToWorld(); void removeFromWorld(); List<Tile> getTiles(); int getWidth(); int getHeight(); Image getSprite(); int getSpriteOffset(); void setSprite(String imageName); long getCurrentHealth(); void setHealth(long health); long getMaxHealth(); void setMaxHealth(long maxHealth); long damageHealth(long damage); long healHealth(long heal); void fullyRestoreHealth(); boolean onChangeHealth(long newHealth); void setPollutionSource(double rate); void removePollutionSource(); double getPollutionRate(); boolean isBuilt(); void completeBuilding(); void setBuildTime(int buildTime); int getBuildTime(); @Override void draw(Viewport viewport, GraphicsContext ctx); @Override double getWorldX(); @Override double getWorldY(); void onPlace(); void onBuild(); void onRemove(); @Override boolean containsPoint(Point point); @Override void click(Point location); void onClick(Point location); void onDoubleClick(Point location); @Override void tick(); @Override String toString(); static final int DOUBLE_CLICK_TIME; static final int DEFAULT_MAX_HEALTH; static final int DEFAULT_BUILD_TIME; }
@Test public void testGetTiles() { Tile tile = mock(Tile.class); when(world.getTile(anyInt(), anyInt())).thenReturn(tile); building.setLocation(new Point(1, 1)); List<Tile> tiles = building.getTiles(); assertEquals("incorrect number of tiles were returned", 4 * 3, tiles.size()); assertFalse("Building is within the world but contains null.", tiles.contains(null)); assertTrue("Building does not contain the tile.", tiles.contains(tile)); setBuilding(new Point(-1, -3), 3, 4, 1000); tiles = building.getTiles(); assertEquals("incorrect number of tiles were returned", 3 * 4, tiles.size()); assertTrue("Building is outside the world but tiles do not contain" + "null.", tiles.contains(null)); assertTrue("Building does not contain the tile.", tiles.contains(tile)); setBuilding(new Point(2, 2), 5, 3, 1000); tiles = building.getTiles(); assertEquals("incorrect number of tiles were returned", 5 * 3, tiles.size()); assertTrue("Building is outside the world but tiles do not contain" + "null.", tiles.contains(null)); assertTrue("Building does not contain the tile.", tiles.contains(tile)); when(world.getWidth()).thenReturn(2); when(world.getHeight()).thenReturn(2); tiles = building.getTiles(); assertEquals("incorrect number of tiles were returned", 5 * 3, tiles.size()); assertTrue("Building is outside the world but tiles do not contain" + "null.", tiles.contains(null)); assertFalse("Building should not contain the tile.", tiles.contains(tile)); setBuilding(new Point(0, 0), 0, 0, 1000); tiles = building.getTiles(); assertEquals("No tiles should be returned", 0, tiles.size()); }