public static ImageOption backgroundColorOf(int color) {
  if (color < 0 || color > 0xFFFFFF) {
    throw new IllegalArgumentException("Color must be in rgb hex range of 0x0 to 0xFFFFFF.");
  }
  return new ImageOption("bg", "rgb:" + format(Locale.getDefault(), "%06X", color));
} public static ImageOption blackBackgroundColor() {
  return backgroundColorOf(0);
} public static ImageOption fitOf(Resize resize) {
  return new ImageOption("fit", resize.name());
} public static ImageOption focusOn(Focus focus) {
  return new ImageOption("f", focus.name());
} public static ImageOption formatOf(Format format) {
  return new ImageOption("fm", format.toUrlParameter());
} public static ImageOption heightOf(int height) {
  if (height <= 0) {
    throw new IllegalArgumentException("Height has to be positive.");
  }
  return new ImageOption("h", Integer.toString(height));
} public static ImageOption http() {
  return new ImageOption("http", "") {
    @Override public String apply(String url) {
      if (url.startsWith("//")) {
        return "http:" + url;
      } else {
        return url;
      }
    }
  };
} public static ImageOption https() {
  return new ImageOption("https", "") {
    @Override public String apply(String url) {
      if (url.startsWith("//")) {
        return "https:" + url;
      } else {
        return url;
      }
    }
  };
} public static ImageOption jpegQualityOf(int quality) {
  if (quality < 1 || quality > 100) {
    throw new IllegalArgumentException("Quality has to be in the range from 1 to 100.");
  }

  return new ImageOption("q", Integer.toString(quality));
} public static ImageOption roundedCornerRadiusOf(float radius) {
  if (radius < 0) {
    throw new IllegalArgumentException("Radius is negative.");
  }

  return new ImageOption("r", Float.toString(radius));
} public static ImageOption widthOf(int width) {
  if (width <= 0) {
    throw new IllegalArgumentException("Width has to be positive.");
  }
  return new ImageOption("w", Integer.toString(width));
}
import com.contentful.java.cda.lib.Enqueue;
import org.junit.Test;
import static com.contentful.java.cda.image.ImageOption.Focus.top;
import static com.contentful.java.cda.image.ImageOption.Format.jpg;
import static com.contentful.java.cda.image.ImageOption.Format.png8;
import static com.contentful.java.cda.image.ImageOption.Resize.crop;
import static com.contentful.java.cda.image.ImageOption.backgroundColorOf;
import static com.contentful.java.cda.image.ImageOption.blackBackgroundColor;
import static com.contentful.java.cda.image.ImageOption.fitOf;
import static com.contentful.java.cda.image.ImageOption.focusOn;
import static com.contentful.java.cda.image.ImageOption.formatOf;
import static com.contentful.java.cda.image.ImageOption.heightOf;
import static com.contentful.java.cda.image.ImageOption.http;
import static com.contentful.java.cda.image.ImageOption.https;
import static com.contentful.java.cda.image.ImageOption.jpegQualityOf;
import static com.contentful.java.cda.image.ImageOption.roundedCornerRadiusOf;
import static com.contentful.java.cda.image.ImageOption.widthOf;
import static com.google.common.truth.Truth.assertThat;
package com.contentful.java.cda;




public class AssetTest extends BaseTest {
  @Test
  @Enqueue("demo/assets_jake.json")
  public void fetchAsset() {
    final CDAAsset asset = client.fetch(CDAAsset.class).one("jake");

    assertThat(asset.id()).isEqualTo("jake");
    assertThat(asset.title()).isEqualTo("Jake");
    assertThat(asset.mimeType()).isEqualTo("image/png");
    assertThat(asset.url()).isEqualTo("//images.contentful.com"
        + "/cfexampleapi"
        + "/4hlteQAXS8iS0YCMU6QMWg"
        + "/2a4d826144f014109364ccf5c891d2dd"
        + "/jake.png");
  }

  @Test
  @Enqueue("demo/assets_jake.json")
  public void augmentUrlSimple() {
    final CDAAsset asset = client.fetch(CDAAsset.class).one("jake");

    assertThat(asset.urlForImageWith(http(), widthOf(10)))
        .isEqualTo("http://images.contentful.com"
            + "/cfexampleapi"
            + "/4hlteQAXS8iS0YCMU6QMWg"
            + "/2a4d826144f014109364ccf5c891d2dd"
            + "/jake.png?w=10");
  }

  @Test
  @Enqueue("demo/assets_jake.json")
  public void augmentUrlWithSameOperationUsesLastOption() {
    final CDAAsset asset = client.fetch(CDAAsset.class).one("jake");

    assertThat(
        asset.urlForImageWith(widthOf(12), widthOf(34)))
        .isEqualTo("//images.contentful.com"
            + "/cfexampleapi"
            + "/4hlteQAXS8iS0YCMU6QMWg"
            + "/2a4d826144f014109364ccf5c891d2dd"
            + "/jake.png"
            + "?w=34"
        );
  }

  @Test
  @Enqueue("demo/assets_jake.json")
  public void augmentUrlComplete() {
    final CDAAsset asset = client.fetch(CDAAsset.class).one("jake");

    assertThat(
        asset.urlForImageWith(
            formatOf(jpg),
            jpegQualityOf(89),
            widthOf(100),
            heightOf(100),