@Test
public void testCropRegion() throws TransformException{

    // Setup an envelope in WGS84
    GeneralEnvelope envelope = new GeneralEnvelope(DefaultGeographicCRS.WGS84);
    envelope.setEnvelope(0, 0, 10, 10);
    
    // Setup a rectangle
    Rectangle rect = new Rectangle(0, 0, 20, 20);
    GridEnvelope2D env = new GridEnvelope2D(rect);
    
    // GridGeometry
    GridGeometry2D gg2D = new GridGeometry2D(env, envelope);
    
    // Getting the crop region
    Rectangle cropRegion = Utilities.getCropRegion(envelope, gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT));
    
    // Ensure the crop region is contains the input one
    assertTrue(cropRegion.contains(rect));
    
    
    // Check that an exception is thrown when one of the two parameters is null
    boolean notThrown = false;
    try {
        Utilities.getCropRegion(envelope, null);
        notThrown = true;
    } catch (IllegalArgumentException e) {
    }
    assertFalse(notThrown);
    // Reset the boolean
    notThrown = false;
    try {
        Utilities.getCropRegion(null, gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT));
        notThrown = true;
    } catch (IllegalArgumentException e) {
    }
    assertFalse(notThrown);
}