### Question:
ImageOptimizationMojo extends AbstractWisdomWatcherMojo implements Constants { @Override public void execute() throws MojoExecutionException { if (imageMinification == null) { imageMinification = new ImageMinification(); } if (skipImageOptimization || ! imageMinification.isEnabled()) { getLog().info("Image minification skipped"); removeFromWatching(); return; } npm = npm(this, NPM_NAME, imageMinification.getVersion()); optimizeAllImagesFromDirectory(new File(buildDirectory, "classes")); optimizeAllImagesFromDirectory(new File(getWisdomRootDirectory(), ASSETS_DIR)); }  @Override void execute(); @Override boolean accept(File file); @Override boolean fileCreated(File file); @Override boolean fileUpdated(File file); @Override boolean fileDeleted(File file); static final String NPM_NAME; static final String COMMAND; static final List<String> EXTENSIONS; @Parameter(defaultValue = "${skipImageOptimization}", required = false)
    public boolean skipImageOptimization; }### Answer:
@Test public void testInstallationAndOptimization() throws MojoExecutionException { ImageOptimizationMojo mojo = new ImageOptimizationMojo(); mojo.basedir = basedir; mojo.buildDirectory = target; mojo.execute(); assertThat(new File(classes, jpg.getName()).length()).isLessThan(jpg.length()); assertThat(new File(classes, png.getName()).length()).isLessThan(png.length()); assertThat(new File(assets, jpg.getName()).length()).isLessThan(jpg.length()); assertThat(new File(assets, png.getName()).length()).isLessThan(png.length()); assertThat(new File(assets, gif.getName()).length()).isLessThan(gif.length()); assertThat(new File(internalNested, jpg.getName()).length()).isLessThan(jpg.length()); assertThat(new File(internalNested, png.getName()).length()).isLessThan(png.length()); assertThat(new File(internalNested, gif.getName()).length()).isLessThan(gif.length()); assertThat(new File(externalNested, jpg.getName()).length()).isLessThan(jpg.length()); assertThat(new File(externalNested, png.getName()).length()).isLessThan(png.length()); assertThat(new File(externalNested, gif.getName()).length()).isLessThan(gif.length()); }
@Test(expected = MojoExecutionException.class) public void testInstallationAndOptimizationWithInvalidImage() throws MojoExecutionException, IOException { ImageOptimizationMojo mojo = new ImageOptimizationMojo(); mojo.basedir = basedir; mojo.buildDirectory = target; mojo.failOnBrokenAsset = true; FileUtils.copyFile(invalid, invalidOutput); mojo.execute(); }
@Test public void testInstallationAndOptimizationWithInvalidImageButErrorIgnored() throws MojoExecutionException, IOException { ImageOptimizationMojo mojo = new ImageOptimizationMojo(); mojo.basedir = basedir; mojo.buildDirectory = target; mojo.failOnBrokenAsset = false; FileUtils.copyFile(invalid, invalidOutput); mojo.execute(); }
@Test public void testInstallationAndOptimizationWithParameters() throws MojoExecutionException, IOException { ImageOptimizationMojo mojo = new ImageOptimizationMojo(); mojo.basedir = basedir; mojo.buildDirectory = target; mojo.failOnBrokenAsset = true; mojo.imageMinification = new ImageMinification(); mojo.imageMinification.setInterlaced(true); mojo.imageMinification.setOptimizationLevel(5); mojo.imageMinification.setProgressive(true); mojo.execute(); }