Viewport { public boolean isOnScreen(Drawable item) { return item.getWorldX() >= getX() && item.getWorldX() < getX() + getWidthTiles() && item.getWorldY() >= getY() && item.getWorldY() < getY() + getHeightTiles(); } Viewport(double width, double height, World world); boolean isOnScreen(Drawable item); int getX(); int getY(); Point getPosition(); void setPosition(int newX, int newY); void move(int offsetX, int offsetY); int getWidthTiles(); int getMaxWidthTiles(); int getWidthPixels(); int getHeightTiles(); int getMaxHeightTiles(); int getHeightPixels(); void setWidthTiles(int newWidth); void setMaxWidthTiles(int newMaxWidth); void setHeightTiles(int newHeight); void setMaxHeightTiles(int newMaxHeight); void setSizeTiles(int width, int height); void setWidthPixels(double newWidth); void setHeightPixels(double newHeight); void setMaxWidthPixels(double newMaxWidth); void setMaxHeightPixels(double newMaxHeight);  }
@Test public void testIsVisible() { Viewport viewport = new Viewport( TileRegister.TILE_SIZE, TileRegister.TILE_SIZE, world); Drawable notVisible = mock(Drawable.class); when(notVisible.getWorldX()).thenReturn(20.0); when(notVisible.getWorldY()).thenReturn(20.0); assertFalse( "Drawable should not be visible", viewport.isOnScreen(notVisible) ); Drawable visible = mock(Drawable.class); when(notVisible.getWorldX()).thenReturn(0.0); when(notVisible.getWorldY()).thenReturn(0.0); assertTrue( "Drawable should be visible", viewport.isOnScreen(visible) ); }