ImageRect { public void validate() { Integer croph = getHeight(); Integer cropw = getWidth(); Integer startx = getStartX(); Integer starty = getStartY(); boolean hasOneCropParameter = croph != null || cropw != null || startx != null || starty != null; if (hasOneCropParameter) { if (croph != null && croph <= 0) { throw error(BAD_REQUEST, "image_error_parameter_positive", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, String.valueOf(croph)); } if (cropw != null && cropw <= 0) { throw error(BAD_REQUEST, "image_error_parameter_positive", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, String.valueOf(cropw)); } if (startx != null && startx <= -1) { throw error(BAD_REQUEST, "image_error_crop_start_not_negative", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, String.valueOf( startx)); } if (starty != null && starty <= -1) { throw error(BAD_REQUEST, "image_error_crop_start_not_negative", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, String.valueOf( starty)); } } } ImageRect(String dimensions);  ImageRect(int startX, int startY, int height, int width);  ImageRect(); int getStartX(); int getStartY(); int getWidth(); int getHeight(); @Override String toString(); void validateCropBounds(int imageWidth, int imageHeight); void validate(); @Override boolean equals(Object obj);  }
@Test(expected = GenericRestException.class) public void testIncompleteCropParameters() { ImageRect rect = new ImageRect("1"); rect.validate(); }
@Test public void testValidation() { try { ImageRect rect = new ImageRect("0,0,0,10"); rect.validate(); fail("The validation should fail but it did not."); } catch (GenericRestException e) { Assert.assertException(e, BAD_REQUEST, "image_error_parameter_positive", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, "0"); } try { ImageRect rect = new ImageRect("0,0,10,0"); rect.validate(); fail("The validation should fail but it did not."); } catch (GenericRestException e) { Assert.assertException(e, BAD_REQUEST, "image_error_parameter_positive", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, "0"); } try { ImageRect rect = new ImageRect("-1,0,10,10"); rect.validate(); fail("The validation should fail but it did not."); } catch (GenericRestException e) { Assert.assertException(e, BAD_REQUEST, "image_error_crop_start_not_negative", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, "-1"); } try { ImageRect rect = new ImageRect("0,-1,10,10"); rect.validate(); fail("The validation should fail but it did not."); } catch (GenericRestException e) { Assert.assertException(e, BAD_REQUEST, "image_error_crop_start_not_negative", ImageManipulationParameters.RECT_QUERY_PARAM_KEY, "-1"); } ImageRect rect = new ImageRect("0,0,1,1"); rect.validate(); }