Skip to content

Commit

Permalink
add tests for issue#199
Browse files Browse the repository at this point in the history
  • Loading branch information
scp-WFZ committed May 24, 2022
1 parent 9990b67 commit e701ad1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/java/com/github/romankh3/image/comparison/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static void main(String[] args) throws Exception {
String actual = cli.getOptionValue("a");
if(cli.hasOption('o')){
String result = cli.getOptionValue("o");
ImageComparison(expected, actual, result);
ImageComparisonResult imageComparisonResult = wholeImageComparison(expected, actual, result);
}else {
simpleImageComparison(expected, actual);
ImageComparisonResult imageComparisonResult = defaultImageComparison(expected, actual);
}
}else {
System.out.println("Invalid or Wrong Arguments, Please try -h to get help");
Expand All @@ -46,7 +46,14 @@ public static void main(String[] args) throws Exception {
}
}

public static void simpleImageComparison(String expected, String actual){
/**
* Compare images without output
*
* @param expected Path of the expected image
* @param actual Path of the actual image
* @return the result of image comparison
*/
public static ImageComparisonResult defaultImageComparison(String expected, String actual){
//load images to be compared:
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(expected);
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(actual);
Expand All @@ -56,9 +63,19 @@ public static void simpleImageComparison(String expected, String actual){

//Check the result
System.out.println(imageComparisonResult.getImageComparisonState().toString());

return imageComparisonResult;
}

public static void ImageComparison(String expected, String actual, String result){
/**
* Compare images without output
*
* @param expected Path of the expected image
* @param actual Path of the actual image
* @param result Path of the result of image comparison
* @return the result of image comparison
*/
public static ImageComparisonResult wholeImageComparison(String expected, String actual, String result){
//load images to be compared:
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(expected);
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(actual);
Expand All @@ -68,5 +85,7 @@ public static void ImageComparison(String expected, String actual, String result

//Create ImageComparison object with result destination and compare the images.
ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage, resultDestination).compareImages();

return imageComparisonResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@
@DisplayName("Unit-level testing for {@link ImageComparison} object.")
public class ImageComparisonUnitTest {

@DisplayName("For issue#199, test the '-e' and '-a' arguments")
@Test
public void testCLI1() throws Exception {
//given
String expected = "expected.png";
String actual = "actual.png";

//when
ImageComparisonResult imageComparisonResult = client.defaultImageComparison(expected, actual);

//then
assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
}

@DisplayName("For issue#199, test the '-o' argument")
@Test
public void tesCLI2() {
//given
String expected = "expected.png";
String actual = "actual.png";
String result = "build/test-images/result.png";
BufferedImage expectedResultImage = readImageFromResources("result.png");

//when
ImageComparisonResult imageComparisonResult = client.wholeImageComparison(expected, actual, result);

//then
assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
assertImagesEqual(expectedResultImage, imageComparisonResult.getResult());
}

@DisplayName("The most important test. Shown, that the changes in algorithm, "
+ "don't break the main behaviour and result as expected")
@Test
Expand Down

0 comments on commit e701ad1

Please sign in to comment.