AbstractBuilding implements Clickable, Drawable,
        Tickable { public boolean addToWorld() { if (isLocationValid() && !world.containsBuilding(this)) { this.handlePlace(); for (Tile tile : getTiles()) { Tile original = new Tile((int)tile.getWorldX(), (int)tile.getWorldY(), tile.getTileType()); original.setTileEntity(tile.getTileEntity()); originalTiles.add(original); BuildingTileEntity entity = new BuildingTileEntity(this, tile); tile.setProperty(TileProperty.IS_BUILDING, true); tile.setTileEntity(entity); } world.addBuilding(this); if (buildTime > 0) { buildTask = new BuildTask(this); TaskManager.getInstance().addTask(buildTask); } else { completeBuilding(); } return true; } return false; } 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 testAddToWorld() { Tile tile = mock(Tile.class); when(tile.getTileEntity()).thenReturn(null); when(world.getTile(anyInt(), anyInt())).thenReturn(tile); TileRegister tileRegister = new TileRegister(); TileRegister mockRegister = mock(TileRegister.class); when(mockRegister.getTileImage("")).thenReturn(null); tileRegister.setInstance(mockRegister); building.setLocation(new Point(1, 1)); assertTrue("Building should be able to be added to the world", building.addToWorld()); verify(tile, times(4 * 3)).setProperty(TileProperty.IS_BUILDING, true); verify(tile, times(4 * 3)).setTileEntity(any(BuildingTileEntity.class)); verify(world).addBuilding(building); when(world.containsBuilding(building)).thenReturn(true); assertFalse("Building already added to the world.", building.addToWorld()); when(world.containsBuilding(building)).thenReturn(false); TileEntity entity = mock(TileEntity.class); when(tile.getTileEntity()).thenReturn(entity); assertFalse("Building is being placed on a tile entity.", building.addToWorld()); }