CropAdapter { public int[] scaleChip( BufferedImage original, BufferedImage overview, Map<String, Serializable> args) { if (args == null) { throw new IllegalArgumentException("method argument 'args' may not be null."); } int x = getArg(args, "x"); int y = getArg(args, "y"); int w = getArg(args, "w"); int h = getArg(args, "h"); double scaleFactor = 1.0; if (original != null && overview != null) { scaleFactor = original.getWidth() / ((double) overview.getWidth()); } int scaledX = multiply(scaleFactor, x); int scaledY = multiply(scaleFactor, y); int scaledW = multiply(scaleFactor, w); int scaledH = multiply(scaleFactor, h); return new int[] {scaledX, scaledY, scaledW, scaledH}; }  int[] scaleChip(
      BufferedImage original, BufferedImage overview, Map<String, Serializable> args);  }
@Test(expected = IllegalArgumentException.class) public void testNullArguments() { cropAdapter.scaleChip(originalImage, overviewImage, null); }
@Test(expected = IllegalArgumentException.class) public void testScaleChipNullHValue() { args.put("x", 10); args.put("y", 20); args.put("w", 30); cropAdapter.scaleChip(originalImage, overviewImage, args); }
@Test(expected = IllegalArgumentException.class) public void testScaleChipNullWValue() { args.put("x", 10); args.put("y", 20); args.put("h", 30); cropAdapter.scaleChip(originalImage, overviewImage, args); }
@Test(expected = IllegalArgumentException.class) public void testScaleChipNullXValue() { args.put("y", 10); args.put("w", 20); args.put("h", 30); cropAdapter.scaleChip(originalImage, overviewImage, args); }
@Test(expected = IllegalArgumentException.class) public void testScaleChipNullYValue() { args.put("x", 10); args.put("w", 20); args.put("h", 30); cropAdapter.scaleChip(originalImage, overviewImage, args); }
@Test public void testScaleChipNullOriginal() { when(overviewImage.getWidth()).thenReturn(1024); when(overviewImage.getHeight()).thenReturn(1024); int[] values = new int[] {100, 100, 512, 512}; args.put("x", values[0]); args.put("y", values[1]); args.put("w", values[2]); args.put("h", values[3]); int[] scaledValues = cropAdapter.scaleChip(null, overviewImage, args); for (int i = 0; i < values.length; i++) { assertThat(scaledValues[i], is(values[i])); } }
@Test public void testScaleChipNullOverview() { when(originalImage.getWidth()).thenReturn(1024); when(originalImage.getHeight()).thenReturn(1024); int[] values = new int[] {100, 100, 512, 512}; args.put("x", values[0]); args.put("y", values[1]); args.put("w", values[2]); args.put("h", values[3]); int[] scaledValues = cropAdapter.scaleChip(originalImage, null, args); for (int i = 0; i < values.length; i++) { assertThat(scaledValues[i], is(values[i])); } }
@Test public void testScaleChip() { when(overviewImage.getWidth()).thenReturn(1024); when(overviewImage.getHeight()).thenReturn(1024); when(originalImage.getWidth()).thenReturn(2048); when(originalImage.getHeight()).thenReturn(2048); int[] values = new int[] {100, 100, 400, 400}; args.put("x", values[0]); args.put("y", values[1]); args.put("w", values[2]); args.put("h", values[3]); int[] scaledValues = cropAdapter.scaleChip(originalImage, overviewImage, args); for (int i = 0; i < values.length; i++) { assertThat(scaledValues[i], is(values[i] * 2)); } }