### Question:
Watermask { public byte getWaterFraction(int x, int y, PixelLocator locator, int stepCountX, int stepCountY) { final Point2D g = new Point2D.Double(); final double startX = x + 0.0; final double startY = y + 0.0; final double deltaX = 1.0 / (stepCountX - 1); final double deltaY = 1.0 / (stepCountY - 1); int waterCount = 0; int invalidCount = 0; for (int i = 0; i < stepCountX; i++) { final double u = startX + i * deltaX; for (int j = 0; j < stepCountY; j++) { final double v = startY + j * deltaY; if (locator.getGeoLocation(u, v, g)) { if (isWater(g.getX(), g.getY())) { waterCount++; } } else { invalidCount++; } } } final int count = stepCountX * stepCountY; if (invalidCount == count) { return INVALID_WATER_FRACTION; } return (byte) ((100.0 * waterCount) / count); } Watermask(); boolean isWater(double lon, double lat); byte getWaterFraction(int x, int y, PixelLocator locator, int stepCountX, int stepCountY); static final byte INVALID_WATER_FRACTION; }### Answer:
@Test public void testGetWaterFraction() throws Exception { final Watermask watermask = new Watermask(); final PixelLocator geographic = new PixelLocator() { @Override public boolean getGeoLocation(double x, double y, Point2D g) { g.setLocation(x, y); return true; } @Override public boolean getPixelLocation(double lon, double lat, Point2D p) { return false; } }; assertEquals(100, watermask.getWaterFraction(0, 0, geographic, 11, 11)); assertEquals(0, watermask.getWaterFraction(20, 0, geographic, 11, 11)); }