I am working on part of a Java application that takes an image as a byte array, reads it into a java.awt.image.BufferedImage
instance and passes it to a third-p
If you want to use Mockito, then you could write a Hamcrest Matcher
import org.mockito.ArgumentMatcher;
public class BufferedImageMatcher extends ArgumentMatcher {
private final BufferedImage expected;
public BufferedImageMatcher(BufferedImage expected) {
this.expected = expected;
}
@Override
public boolean matches(Object argument) {
BufferedImage actual = (BufferedImage) argument;
assertEquals(expected.getWidth(), actual.getWidth());
assertEquals(expected.getHeight(), actual.getHeight());
for (int x = 0; x < actual.getWidth(); x++) {
for (int y = 0; y < actual.getHeight(); y++) {
assertEquals(expected.getRGB(x, y), actual.getRGB(x, y));
}
}
return true;
}
}
and use it like this
assertThat(actual, new BufferedImageMatcher(expected));