I'm trying to write an integration test to see if a file is downloaded correctly from a url. I'm not sure how to test this because I expect to get the file in byte[] but I not really sure about the image that I'm comparing it to. I thought about downloading the file manually and then convert it to bytes and take the result and paste it in the code as the expected value and than compare it to the result i get. If you have a better idea I would be glad to hear it.
Thanks:)
Since you are using and
There's an input stream decorator,
java.security.DigestInputStream
orjava.security.MessageDigest
, so that you can compute the digest while using the input stream.Here you can find other also good code snippets.
Comparing the images' hash value will be helpful.
You can use hash algorithms like MD5 or SHA-1. If the files are smaller MD5 is good. For large number of file comparison SHA-1 will be useful since there will be less collisions.