Skip to content

Commit

Permalink
4.2.1 (#183)
Browse files Browse the repository at this point in the history
4.2.1:
*   Fixed bug #180 - problem with ImageComparisonUtil.readFromResources method.
  • Loading branch information
romankh3 authored Apr 17, 2020
1 parent 6b52abe commit 16ea3bc
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
<dependency>
<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
</dependency>
```
#### Gradle
```groovy
compile 'com.github.romankh3:image-comparison:4.2.0'
compile 'com.github.romankh3:image-comparison:4.2.1'
```

#### To compare two images programmatically
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## 4.2.1
* Fixed bug #180 - problem with ImageComparisonUtil.readFromResources method.

## 4.2.0
* added the ability to ignore some percent of differences for comparison.

Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ plugins {
}

group 'com.github.romankh3'
version '4.2.0'
description 'A library and utility to compare different images.'
version '4.2.1'
description 'Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. ' +
'Some parts of the image can be excluded from the comparison. Can be used for automation qa tests.'
sourceCompatibility = 1.8

mainClassName = "com.github.romankh3.image.comparison.ImageComparison"
Expand Down Expand Up @@ -66,7 +67,7 @@ artifacts {
// add all the info required by Maven Central to the pom
configure(install.repositories.mavenInstaller) {
pom.project {
inceptionYear '2019'
inceptionYear '2020'
name project.name
packaging 'jar'
description project.description
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<packaging>jar</packaging>

<name>Image Comparison</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ static BufferedImage deepCopy(BufferedImage image) {
* @throws ImageComparisonException due to read the image from resources.
*/
public static BufferedImage readImageFromResources(String path) throws ImageComparisonException {
InputStream inputStream = ImageComparisonUtil.class.getClassLoader().getResourceAsStream(path);
if (inputStream != null) {
File imageFile = new File(path);
if (imageFile.exists()) {
try {
return ImageIO.read(inputStream);
return ImageIO.read(imageFile);
} catch (IOException e) {
throw new ImageComparisonException(String.format("Cannot read image from the file, path=%s", path), e);
}
} else {
throw new ImageNotFoundException(String.format("Image with path = %s not found", path));
InputStream inputStream = ImageComparisonUtil.class.getClassLoader().getResourceAsStream(path);
if (inputStream != null) {
try {
return ImageIO.read(inputStream);
} catch (IOException e) {
throw new ImageComparisonException(String.format("Cannot read image from the file, path=%s", path), e);
}
} else {
throw new ImageNotFoundException(String.format("Image with path = %s not found", path));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.github.romankh3.image.comparison;

import static com.github.romankh3.image.comparison.ImageComparisonUtil.readImageFromResources;
import static com.github.romankh3.image.comparison.model.ImageComparisonState.MATCH;
import static com.github.romankh3.image.comparison.model.ImageComparisonState.MISMATCH;
import static com.github.romankh3.image.comparison.model.ImageComparisonState.SIZE_MISMATCH;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.romankh3.image.comparison.model.ImageComparisonResult;
import com.github.romankh3.image.comparison.model.Rectangle;
import org.junit.jupiter.api.Test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static com.github.romankh3.image.comparison.ImageComparisonUtil.readImageFromResources;
import static com.github.romankh3.image.comparison.model.ImageComparisonState.*;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

/**
* Unit-level testing for {@link ImageComparison} object.
Expand Down Expand Up @@ -140,7 +143,8 @@ public void testMinimalRectangleSize() {
@Test
public void testIssue17() {
//when
ImageComparisonResult imageComparisonResult = new ImageComparison("expected#17.png", "actual#17.png").compareImages();
ImageComparisonResult imageComparisonResult = new ImageComparison("expected#17.png", "actual#17.png")
.compareImages();

//then
assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
Expand All @@ -156,7 +160,8 @@ public void testIssue21() {
BufferedImage expectedResultImage = readImageFromResources("result#21.png");

//when
ImageComparisonResult imageComparisonResult = new ImageComparison("expected#21.png", "actual#21.png").compareImages();
ImageComparisonResult imageComparisonResult =
new ImageComparison("expected#21.png", "actual#21.png").compareImages();

//then
assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
Expand Down Expand Up @@ -416,7 +421,8 @@ public void testIssue134() {
@Test
public void testMatchSize() {
//when
ImageComparisonResult imageComparisonResult = new ImageComparison("expected.png", "expected.png").compareImages();
ImageComparisonResult imageComparisonResult = new ImageComparison("expected.png", "expected.png")
.compareImages();

//then
assertEquals(MATCH, imageComparisonResult.getImageComparisonState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

import com.github.romankh3.image.comparison.exception.ImageComparisonException;
import com.github.romankh3.image.comparison.exception.ImageNotFoundException;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -130,4 +128,36 @@ public void testIssue136() {
//when
assertDoesNotThrow(() -> ImageComparisonUtil.deepCopy(subimage));
}

/**
* Test issue #180. It was a problem with {@link ImageComparisonUtil#readImageFromResources(String)}
* from non test/resources.
*/
@Test
public void shouldProperlyHandleBug180FromRoot() {
//given
String imagePath = "build/resources/test/result.png";

//when
BufferedImage result = ImageComparisonUtil.readImageFromResources(imagePath);

//then
assertNotNull(result);
}

/**
* Test issue #180. It was a problem with {@link ImageComparisonUtil#readImageFromResources(String)}
* from non test/resources.
*/
@Test
public void shouldProperlyHandleBug180FromTestResources() {
//given
String imagePath = "actual.png";

//when
BufferedImage result = ImageComparisonUtil.readImageFromResources(imagePath);

//then
assertNotNull(result);
}
}

0 comments on commit 16ea3bc

Please sign in to comment.