ImageStyleUtils { public static int getCropY(int imageWidth, int imageHeight, ImageStyle style) { int cropY = 0; int styledHeight = getStyledHeight(imageWidth, imageHeight, style); float scale = getScale(imageWidth, imageHeight, style); switch (style.getScalingMode()) { case Fill: case Box: case Cover: case Height: case Width: if (styledHeight > -1 && styledHeight < scale * imageHeight) cropY = Math.round(scale * imageHeight) - styledHeight; break; case None: break; default: throw new IllegalStateException("Image style " + style + " contains an unknown scaling mode '" + style.getScalingMode() + "'"); } return cropY; } private  ImageStyleUtils(); static int getStyledWidth(ImageContent image, ImageStyle style); static int getStyledHeight(ImageContent image, ImageStyle style); static float getScale(float imageWidth, float imageHeight,
      ImageStyle style); static int getCropX(int imageWidth, int imageHeight, ImageStyle style); static int getCropY(int imageWidth, int imageHeight, ImageStyle style); static int getStyledWidth(int imageWidth, int imageHeight,
      ImageStyle style); static int getStyledHeight(int imageWidth, int imageHeight,
      ImageStyle style); static ImageStyle findStyle(String styleId, Site site); static ImageStyle[] findStyles(String regex, boolean composeableOnly,
      Site site); static File createScaledFile(Resource<?> resource, Language language,
      ImageStyle style); static File createScaledFile(Resource<?> resource, String filename,
      Language language, ImageStyle style); static File getScaledFile(Resource<?> resource, Language language,
      ImageStyle style); static File getUnscaledFile(Resource<?> resource, Language language); static File getScaledFile(Resource<?> resource, String filename,
      Language language, ImageStyle style); static File getUnscaledFile(Resource<?> resource, String filename,
      Language language); static File getDirectory(Site site); static File getDirectory(Site site, ImageStyle style); static final String DEFAULT_PREVIEW_FORMAT; }
@Test public void testGetCropY() { for (ImageStyle style : styles) { switch (style.getScalingMode()) { case Box: int[] expectedBoxValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; testGetCropY(style, expectedBoxValues); break; case Fill: int[] expectedFillValues = { 0, 0, 0, 100, 0, 0, 300, 150, 0 }; testGetCropY(style, expectedFillValues); break; case Cover: int[] expectedCoverValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; testGetCropY(style, expectedCoverValues); break; case Width: int[] expectedWidthValues = { 0, 0, 0, 100, 0, 0, 300, 150, 0 }; testGetCropY(style, expectedWidthValues); break; case Height: int[] expectedHeightValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; testGetCropY(style, expectedHeightValues); break; case None: int[] expectedNoneValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; testGetCropY(style, expectedNoneValues); break; default: fail("Unknown scaling mode " + style.getScalingMode()); } } }