DiffImageMaker { public BufferedImage execute() { BufferedImage expectedBaseImage = ImageUtils.getMarkedImage(leftImage, diffPoints); final int border = 1; int expectedImageWidth = expectedBaseImage.getWidth() + border * 2; BufferedImage actualBaseImage = ImageUtils.getMarkedImage(rightImage, diffPoints); int actualImageWidth = actualBaseImage.getWidth() + border * 2; int diffImageWidth = expectedImageWidth + actualImageWidth; int baseImageHeight = ((expectedBaseImage.getHeight() >= actualBaseImage.getHeight()) ? expectedBaseImage .getHeight() : actualBaseImage.getHeight()) + border * 2; final int statusHeight = 50; int diffImageHeight = baseImageHeight + statusHeight; BufferedImage diffImage = new BufferedImage(diffImageWidth, diffImageHeight, 1); Graphics2D g = (Graphics2D) diffImage.getGraphics(); g.drawImage(expectedBaseImage, 1, statusHeight + 1, null); g.drawImage(actualBaseImage, expectedImageWidth + border, statusHeight + 1, null); final float leftR = 0.2f; final float leftG = 0.5f; final float leftB = 1.0f; final float leftA = 1.0f; g.setColor(new Color(leftR, leftG, leftB, leftA)); g.fillRect(0, 0, expectedImageWidth + 1, statusHeight + 1); g.drawRect(0, statusHeight, expectedBaseImage.getWidth() + border, diffImageHeight + 1); final float rightR = 0.8f; final float rightG = 0.2f; final float rightB = 0.2f; final float rightA = 1.0f; g.setColor(new Color(rightR, rightG, rightB, rightA)); g.fillRect(expectedImageWidth, 0, actualImageWidth + 1, statusHeight + 1); g.drawRect(expectedImageWidth, statusHeight, actualBaseImage.getWidth() + 1, diffImageHeight + 1); final int fontSize = 25; final int centeringWidth = 80; final int centeringHeight = 35; g.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f)); g.setFont(new Font("Arial", Font.BOLD, fontSize)); g.drawString(leftImageLabel, expectedBaseImage.getWidth() / 2 - centeringWidth, centeringHeight); g.drawString(rightImageLabel, expectedImageWidth + actualImageWidth / 2 - centeringWidth, centeringHeight); return diffImage; } DiffImageMaker(BufferedImage leftImage, BufferedImage rightImage, DiffPoints diffPoints);  DiffImageMaker(BufferedImage leftImage, BufferedImage rightImage, DiffPoints diffPoints,
			String leftImageLabel, String rightImageLabel); BufferedImage getLeftImage(); BufferedImage getRightImage(); DiffPoints getDiffPoints(); String getLeftImageLabel(); void setLeftImageLabel(String leftImageLabel); String getRightImageLabel(); void setRightImageLabel(String rightImageLabel); BufferedImage execute();  }
@Test public void testExecute_default() throws Exception { BufferedImage image = ImageIO.read(getClass().getResource("web_page_screenshot.png")); List<Point> points = new ArrayList<Point>(); points.add(new Point(50, 50)); DiffPoints diffPoints = new DiffPoints(points, new ArrayList<Point>()); BufferedImage actual = new DiffImageMaker(image, image, diffPoints).execute(); BufferedImage expected = ImageIO.read(getClass().getResource("DiffImageMakerTest_defaultResult.png")); assertThat(ImageUtils.imageEquals(expected, actual), is(true)); }
@Test public void testExecute_setLabels() throws Exception { BufferedImage image = ImageIO.read(getClass().getResource("web_page_screenshot.png")); List<Point> points = new ArrayList<Point>(); points.add(new Point(50, 50)); DiffPoints diffPoints = new DiffPoints(points, new ArrayList<Point>()); BufferedImage actual = new DiffImageMaker(image, image, diffPoints, "left", "right").execute(); BufferedImage expected = ImageIO.read(getClass().getResource("DiffImageMakerTest_setLabelsResult.png")); assertThat(ImageUtils.imageEquals(expected, actual), is(true)); }