ChipServiceImpl implements ChipService { @Override public BufferedImage chip( BufferedImage inputImage, Polygon inputImagePolygon, Polygon chipPolygon) throws ChipOutOfBoundsException { validateNotNull(inputImage, "inputImage"); validateNotNull(inputImagePolygon, "inputImagePolygon"); validateNotNull(chipPolygon, "chipPolygon"); List<Vector> imageVectors = createVectorListFromPolygon(inputImagePolygon); List<Vector> chipVectors = createVectorListFromPolygon(chipPolygon); CoordinateConverter converter = new CoordinateConverter(inputImage, imageVectors); List<Vector> pixels = converter.toPixels(chipVectors); int maxX = findMax(pixels, v -> v.get(0)); int maxY = findMax(pixels, v -> v.get(1)); int minX = findMin(pixels, v -> v.get(0)); int minY = findMin(pixels, v -> v.get(1)); return crop(inputImage, minX, minY, maxX - minX, maxY - minY); } ChipServiceImpl();  ChipServiceImpl(Semaphore lock); @Override BufferedImage chip(
      BufferedImage inputImage, Polygon inputImagePolygon, Polygon chipPolygon); BufferedImage crop(BufferedImage inputImage, int x, int y, int w, int h);  }
@Test public void testChip() throws ChipOutOfBoundsException, ParseException, InterruptedException { Boundary mainImage = new Boundary(52.0, 15.0, 100, Math.toRadians(30)); Boundary chip = new Boundary(52.0, 15.0, 10, Math.toRadians(30)); Polygon mainPolygon = createPolygon(mainImage.getBoundary()); Polygon chipPolygon = createPolygon(chip.getBoundary()); BufferedImage result = chipService.chip(inputImage, mainPolygon, chipPolygon); assertThat(result.getWidth(), is(102)); assertThat(result.getHeight(), is(102)); verify(lock).acquire(); verify(lock).release(); }