ImageScaler { public static BufferedImage scale(BufferedImage image, ImageSize size) { if (size == null) { log.error("The supplied image size is null."); throw new NullPointerException("The supplied image size is null."); } return scale(image, size.getWidth(), size.getHeight()); } private  ImageScaler(); static BufferedImage scale(BufferedImage image, ImageSize size); static BufferedImage scale(BufferedImage image, double scalingFactor); static BufferedImage scale(BufferedImage image, double widthScaling,
      double heightScaling); static BufferedImage scale(BufferedImage image, int size); static BufferedImage scale(BufferedImage image, int width, int height);  }
@Test(expected = IllegalArgumentException.class) public void testScalePixelTwoZero() { ImageScaler.scale(img, 0, 0); }
@Test(expected = IllegalArgumentException.class) public void testScalePixelTwoSIngleBelowZero() { ImageScaler.scale(img, 5, -6); }
@Test(expected = IllegalArgumentException.class) public void testScalePixelTwoBelowOne() { ImageScaler.scale(img, -4, -6); }
@Test(expected = NullPointerException.class) public void testScaleImageNull() { ImageScaler.scale(null, 50); }
@Test public void testScale() { BufferedImage uut = ImageScaler.scale(img, ImageSizePreset.FULL.getSize()); assertEquals(ImageSizePreset.FULL.getSize().getWidth(), uut.getWidth()); assertEquals(ImageSizePreset.FULL.getSize().getHeight(), uut.getHeight()); uut = ImageScaler.scale(img, ImageSizePreset.ICON.getSize()); assertEquals(ImageSizePreset.ICON.getSize().getWidth(), uut.getWidth()); assertEquals(ImageSizePreset.ICON.getSize().getHeight(), uut.getHeight()); uut = ImageScaler.scale(img, 2.2); assertEquals((int) (widthBefore * 2.2), uut.getWidth()); assertEquals((int) (heightBefore * 2.2), uut.getHeight()); uut = ImageScaler.scale(img, 0.33); assertEquals((int) (widthBefore * 0.33), uut.getWidth()); assertEquals((int) (heightBefore * 0.33), uut.getHeight()); uut = ImageScaler.scale(img, 1.0); assertEquals(widthBefore, uut.getWidth()); assertEquals(heightBefore, uut.getHeight()); uut = ImageScaler.scale(img, 0.001); assertEquals(1, uut.getWidth()); assertEquals(1, uut.getHeight()); uut = ImageScaler.scale(img, 1.0, 2.5); assertEquals(widthBefore, uut.getWidth()); assertEquals((int) (heightBefore * 2.5), uut.getHeight()); uut = ImageScaler.scale(img, 2.5, 1.0); assertEquals((int) (widthBefore * 2.5), uut.getWidth()); assertEquals(heightBefore, uut.getHeight()); uut = ImageScaler.scale(img, 0.5, 4.0); assertEquals((int) (widthBefore * 0.5), uut.getWidth()); assertEquals((int) (heightBefore * 4.0), uut.getHeight()); uut = ImageScaler.scale(img, 4.0, 0.5); assertEquals((int) (widthBefore * 4.0), uut.getWidth()); assertEquals((int) (heightBefore * 0.5), uut.getHeight()); uut = ImageScaler.scale(img, 807); assertEquals(807, uut.getWidth()); assertEquals(807, uut.getHeight()); uut = ImageScaler.scale(img, 122); assertEquals(122, uut.getWidth()); assertEquals(122, uut.getHeight()); uut = ImageScaler.scale(img, widthBefore); assertEquals(widthBefore, uut.getWidth()); assertEquals(widthBefore, uut.getHeight()); uut = ImageScaler.scale(img, widthBefore, 654); assertEquals(widthBefore, uut.getWidth()); assertEquals(654, uut.getHeight()); uut = ImageScaler.scale(img, 654, heightBefore); assertEquals(654, uut.getWidth()); assertEquals(heightBefore, uut.getHeight()); uut = ImageScaler.scale(img, 111, 555); assertEquals(111, uut.getWidth()); assertEquals(555, uut.getHeight()); uut = ImageScaler.scale(img, 555, 111); assertEquals(555, uut.getWidth()); assertEquals(111, uut.getHeight()); uut = ImageScaler.scale(img, 1, 1); assertEquals(1, uut.getWidth()); assertEquals(1, uut.getHeight()); }
@Test(expected = NullPointerException.class) public void testScaleImageSizeNull() { ImageScaler.scale(img, (ImageSize) null); }
@Test(expected = IllegalArgumentException.class) public void testScaleFactorZero() { ImageScaler.scale(img, 0.0); }
@Test(expected = IllegalArgumentException.class) public void testScaleFactorBelowZero() { ImageScaler.scale(img, -1.34); }
@Test(expected = IllegalArgumentException.class) public void testScaleFactorTwoZero() { ImageScaler.scale(img, 0.0, 0.0); }
@Test(expected = IllegalArgumentException.class) public void testScaleFactorTwoSingleBelowZero() { ImageScaler.scale(img, 1.5, -2.0); }
@Test(expected = IllegalArgumentException.class) public void testScaleFactorTwoBelowZero() { ImageScaler.scale(img, -1.22, -2.22); }
@Test(expected = IllegalArgumentException.class) public void testScalePixelZero() { ImageScaler.scale(img, 0); }
@Test(expected = IllegalArgumentException.class) public void testScalePixelBelowOne() { ImageScaler.scale(img, -4); }