CategoryImageComparator extends ImageComparator<CategoryComparisonParameters> { @Override protected List<Point> compare(BufferedImage image1, BufferedImage image2, int offsetX, int offsetY) { return null; } CategoryImageComparator();   CategoryImageComparator(CategoryComparisonParameters parameters); @Override ImageComparedResult compare(BufferedImage img1, Rectangle img1Area, BufferedImage img2, Rectangle img2Area);  }
@Test public void testCompareMissingSucceeded() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_missing_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_missing_actual.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.MISSING }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(true)); assertThat(result.getComparedRectangles().size(), is(1)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.MISSING)); }
@Test public void testCompareMissingFailed() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_missing_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_missing_actual_failed.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.MISSING }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(false)); assertThat(result.getComparedRectangles().size(), is(2)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.TEXT)); assertThat(result.getComparedRectangles().get(1).getCategory(), is(DiffCategory.MISSING)); }
@Test public void testCompareShiftSucceeded() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_shift_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_shift_actual.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SHIFT }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(true)); assertThat(result.getComparedRectangles().size(), is(1)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.SHIFT)); }
@Test public void testCompareShiftFailed() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_shift_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_shift_actual_failed.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SHIFT }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(false)); assertThat(result.getComparedRectangles().size(), is(2)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.TEXT)); assertThat(result.getComparedRectangles().get(1).getCategory(), is(DiffCategory.SHIFT)); }
@Test public void testCompareTextSucceeded() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_text_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO.read(getClass().getResource("CategoryImageComparatorTest_text_actual.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.TEXT }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(true)); assertThat(result.getComparedRectangles().size(), is(1)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.TEXT)); }
@Test public void testCompareTextFailed() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_text_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_text_actual_failed.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.TEXT }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(false)); assertThat(result.getComparedRectangles().size(), is(2)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.MISSING)); assertThat(result.getComparedRectangles().get(1).getCategory(), is(DiffCategory.TEXT)); }
@Test public void testCompareScalingSucceeded() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_scaling_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_scaling_actual.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SCALING }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(true)); assertThat(result.getComparedRectangles().size(), is(1)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.SCALING)); }
@Test public void testCompareScalingFailed() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_scaling_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_scaling_actual_failed.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SCALING }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(false)); assertThat(result.getComparedRectangles().size(), is(2)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.TEXT)); assertThat(result.getComparedRectangles().get(1).getCategory(), is(DiffCategory.SCALING)); }
@Test public void testCompareSimilarSucceeded() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_similar_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_similar_actual.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SIMILAR }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(true)); assertThat(result.getComparedRectangles().size(), is(1)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.SIMILAR)); }
@Test public void testCompareSimilarFailed() throws Exception { BufferedImage expectedImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_similar_expected.png")); Rectangle expectedRectangle = new Rectangle(0, 0, expectedImage.getWidth(), expectedImage.getHeight()); BufferedImage actualImage = ImageIO .read(getClass().getResource("CategoryImageComparatorTest_similar_actual_failed.png")); Rectangle actualRectangle = new Rectangle(0, 0, actualImage.getWidth(), actualImage.getHeight()); DiffCategory[] acceptCategories = new DiffCategory[] { DiffCategory.SIMILAR }; CategoryComparisonParameters parameters = new CategoryComparisonParameters(acceptCategories); CompareOption option = new CompareOption(CompareOptionType.CATEGORY, parameters); CategoryImageComparator categoryImageComparator = new CategoryImageComparator( (CategoryComparisonParameters) option.getParameters()); CategoryImageComparedResult result = (CategoryImageComparedResult) categoryImageComparator .compare(expectedImage, expectedRectangle, actualImage, actualRectangle); assertThat(result.isSucceeded(), is(false)); assertThat(result.getComparedRectangles().size(), is(2)); assertThat(result.getComparedRectangles().get(0).getCategory(), is(DiffCategory.TEXT)); assertThat(result.getComparedRectangles().get(1).getCategory(), is(DiffCategory.SIMILAR)); }