Skip to content
This repository has been archived by the owner on Sep 13, 2018. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfebert committed Feb 28, 2010
1 parent e99b839 commit c3b4117
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
Expand All @@ -22,21 +23,14 @@

public class ImageAssert {

private final ICompareResultHandler compareHandler;

public ImageAssert(ICompareResultHandler compareHandler) {
this.compareHandler = compareHandler;
}

public ImageAssert() {
this.compareHandler = new JUnitCompareResultHandler();
}
private ICompareResultHandler compareResultHandler = new JUnitCompareResultHandler();
private int dpi = 300;

private void assertImageEquals(final File expectedFile, final File actualFile,
final BufferedImage expected, BufferedImage actual) {
boolean equal = Arrays.equals(extractPixels(expected), extractPixels(actual));
if (!equal) {
compareHandler.onImageNotEqual(expectedFile, actualFile, expected, actual);
compareResultHandler.onImageNotEqual(expectedFile, actualFile, expected, actual);
}
}

Expand Down Expand Up @@ -108,7 +102,7 @@ public void assertPdfEquals(URL expected, InputStream actual) {
}
}

private static File convertPdfToPng(File pdfFile) {
private File convertPdfToPng(File pdfFile) {
File destFile;
try {
String src = pdfFile.getAbsolutePath();
Expand All @@ -118,16 +112,24 @@ private static File convertPdfToPng(File pdfFile) {
// "png", src, "--out", dest).start().waitFor() != 0)
// TODO: support sips and imagemagick
// TODO: split might not be necessary when using imagemagick
if (new ProcessBuilder("convert", "-density", "300", src, "-resize", "800x", dest)
.start().waitFor() != 0)
if (new ProcessBuilder("convert", "-density", String.valueOf(dpi), src, "-resize",
"800x", dest).start().waitFor() != 0)
throw new RuntimeException("convert pdf2png returned error");
destFile = new File(dest);
if (!destFile.exists())
throw new RuntimeException(dest + " not found");
throw new FileNotFoundException(dest + " not found");
} catch (Exception e) {
throw new RuntimeException(e);
}
return destFile;
}

}
public void setDpi(int dpi) {
this.dpi = dpi;
}

public void setCompareResultHandler(ICompareResultHandler compareResultHandler) {
this.compareResultHandler = compareResultHandler;
}

}

0 comments on commit c3b4117

Please sign in to comment.