private static void assertThemeUsed(ActionBarIconGenerator.Theme theme, @Nullable Color color)
      throws Exception {
    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument =
        ArgumentCaptor.forClass(ActionBarIconGenerator.ActionBarOptions.class);

    ActionBarIconGenerator generator = mock(ActionBarIconGenerator.class);

    TemplateWizardState state = new TemplateWizardState();
    AssetStudioAssetGenerator studioGenerator =
        new AssetStudioAssetGenerator(
            new TemplateWizardContextAdapter(state), generator, null, null);
    pickImage(state);
    state.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name());
    state.put(ATTR_ASSET_THEME, theme.name());
    state.put(ATTR_FOREGROUND_COLOR, color);
    studioGenerator.generateImages(true);

    verify(generator, times(1))
        .generate(
            isNull(String.class),
            any(Map.class),
            eq(studioGenerator),
            argument.capture(),
            anyString());

    assertEquals(theme, argument.getValue().theme);

    if (color != null && theme.equals(ActionBarIconGenerator.Theme.CUSTOM)) {
      assertEquals(color.getRGB(), argument.getValue().customThemeColor);
    }
  }
  public void testTrim() throws Exception {
    myState.put(ATTR_TRIM, true);
    myState.put(ATTR_SOURCE_TYPE, SourceType.IMAGE);

    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = runImageTest();

    BufferedImage expectedImage = crop(getImage(myState.getString(ATTR_IMAGE_PATH), false));

    assertImagesSimilar("TrimmedImage", expectedImage, argument.getValue().sourceImage, 5.0f);
  }
  public void testPadding() throws Exception {
    myState.put(ATTR_PADDING, 50);
    myState.put(ATTR_SOURCE_TYPE, SourceType.IMAGE);

    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = runImageTest();

    BufferedImage expectedImage =
        Util.paddedImage(getImage(myState.getString(ATTR_IMAGE_PATH), false), 50);

    assertImagesSimilar("PaddedImage", expectedImage, argument.getValue().sourceImage, 5.0f);
  }
  public void testActionBarIcons() throws Exception {
    myState.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name());
    myAssetGenerator.generateImages(true);

    verify(myNotificationIconGenerator, never())
        .generate(any(GraphicGeneratorContext.class), any(GraphicGenerator.Options.class));
    verify(myNotificationIconGenerator, never())
        .generate(
            anyString(),
            any(Map.class),
            any(GraphicGeneratorContext.class),
            any(GraphicGenerator.Options.class),
            anyString());

    verify(myActionBarIconGenerator, never())
        .generate(eq(myAssetGenerator), any(ActionBarIconGenerator.ActionBarOptions.class));
    verify(myActionBarIconGenerator, times(1))
        .generate(
            isNull(String.class),
            any(Map.class),
            eq(myAssetGenerator),
            any(ActionBarIconGenerator.ActionBarOptions.class),
            eq(ASSET_NAME));

    verify(myLauncherIconGenerator, never())
        .generate(any(GraphicGeneratorContext.class), any(GraphicGenerator.Options.class));
    verify(myLauncherIconGenerator, never())
        .generate(
            anyString(),
            any(Map.class),
            any(GraphicGeneratorContext.class),
            any(GraphicGenerator.Options.class),
            anyString());
  }
  public void testClipartSource() throws Exception {
    myState.put(ATTR_SOURCE_TYPE, SourceType.CLIPART);

    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = runImageTest();

    BufferedImage expectedImage =
        GraphicGenerator.getClipartImage(myState.getString(ATTR_CLIPART_NAME));
    assertImagesSimilar("ClipartImage", expectedImage, argument.getValue().sourceImage, 5.0f);
  }
  private ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> runImageTest() throws Exception {
    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument =
        ArgumentCaptor.forClass(ActionBarIconGenerator.ActionBarOptions.class);
    myState.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name());
    myState.put(ATTR_ASSET_THEME, ActionBarIconGenerator.Theme.HOLO_DARK.name());

    myAssetGenerator.generateImages(true);

    verify(myActionBarIconGenerator, times(1))
        .generate(
            isNull(String.class),
            any(Map.class),
            eq(myAssetGenerator),
            argument.capture(),
            anyString());

    return argument;
  }
  public void testTextSource() throws Exception {
    myState.put(ATTR_SOURCE_TYPE, SourceType.TEXT);

    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = runImageTest();

    TextRenderUtil.Options options = new TextRenderUtil.Options();
    options.font = Font.decode(myState.getString(ATTR_FONT) + " " + myState.getInt(ATTR_FONT_SIZE));
    options.foregroundColor = 0xFFFFFFFF;
    BufferedImage expectedImage =
        TextRenderUtil.renderTextImage(myState.getString(ATTR_TEXT), 1, options);

    assertImagesSimilar("TextImage", expectedImage, argument.getValue().sourceImage, 5.0f);
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   myNotificationIconGenerator = mock(NotificationIconGenerator.class);
   myActionBarIconGenerator = mock(ActionBarIconGenerator.class);
   myLauncherIconGenerator = mock(LauncherIconGenerator.class);
   myAssetGenerator =
       new AssetStudioAssetGenerator(
           new TemplateWizardContextAdapter(myState),
           myActionBarIconGenerator,
           myNotificationIconGenerator,
           myLauncherIconGenerator);
   pickImage(myState);
   myState.put(ATTR_ASSET_NAME, ASSET_NAME);
 }
 private static void pickImage(TemplateWizardState state) {
   // This is no longer done by the asset state by default, but by the
   // AssetSetStep#initialize method
   state.put(
       ATTR_IMAGE_PATH,
       new File(
               TemplateManager.getTemplateRootFolder(),
               FileUtil.join(
                   Template.CATEGORY_PROJECTS,
                   NewProjectWizardState.MODULE_TEMPLATE_NAME,
                   "root",
                   "res",
                   "drawable-xhdpi",
                   "ic_launcher.png"))
           .getAbsolutePath());
 }