On Thu, 12 Jan 2006 09:36:33 -0500, "Rhino"
<no.offline.contact.please@nospam.com> wrote, quoted or indirectly
quoted someone who said :
>Is there a way to compare two files within JUnit? If not, is there some
>other way to test my file generating classes?
If the files are not too long, you read both in a byte array or string
and compare. If they are very long, compute an Adler checksum on
each. Compare the lengths first. If they differ, you don't even need
to compute the checksum. If the checksums differ, you have a problem.
see http://mindprod.com/jgloss/adler.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Luc The Perverse - 13 Jan 2006 00:47 GMT
> On Thu, 12 Jan 2006 09:36:33 -0500, "Rhino"
> <no.offline.contact.please@nospam.com> wrote, quoted or indirectly
[quoted text clipped - 9 lines]
>
> see http://mindprod.com/jgloss/adler.html
Whoa! I didn't know Java had native Adler support (in fact I was quite sure
it didn't)
I personally prefer SHA-256 for my checksumming needs. If you are only
doing one file you won't notice a speed difference, and Adler is known to be
weak for small file types. (I realize Roedy specific you should only do
this if you have a long file, but I wanted to make this warning.)
--
LTP
:)
Roedy Green - 13 Jan 2006 02:15 GMT
On Thu, 12 Jan 2006 17:47:27 -0700, "Luc The Perverse"
<sll_noSpamlicious_z_XXX_m@cc.usu.edu> wrote, quoted or indirectly
quoted someone who said :
>> see http://mindprod.com/jgloss/adler.html
>
>Whoa! I didn't know Java had native Adler support (in fact I was quite sure
>it didn't)
Yes it does. I use it in my "untouch" utility that puts files back to
what they used to be if they have not really changed.
It is very quick.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Andrew McDonagh - 13 Jan 2006 01:23 GMT
> On Thu, 12 Jan 2006 09:36:33 -0500, "Rhino"
> <no.offline.contact.please@nospam.com> wrote, quoted or indirectly
[quoted text clipped - 9 lines]
>
> see http://mindprod.com/jgloss/adler.html
finding out if the files is different is only the beginning. JUnit tests
tell you why they are different as well.
Rhino, there's actually a few add-ons available for JUnit that do
exactly this.
Most provide a new assertfile method.
Junit-addons is probably the dominant player in this field...
http://junit-addons.sourceforge.net/
For its File asserts see...
http://junit-addons.sourceforge.net/junitx/framework/FileAssert.html
assertBinaryEquals(java.io.File expected, java.io.File actual)
//Asserts that two binary files are equal.
assertBinaryEquals(java.lang.String message, java.io.File expected,
java.io.File actual)
// Asserts that two binary files are equal.
assertEquals(java.io.File expected, java.io.File actual)
// Asserts that two files are equal.
assertEquals(java.lang.String message, java.io.File expected,
java.io.File actual)
//Asserts that two files are equal.
assertEquals(java.lang.String message, java.io.Reader expected,
java.io.Reader actual)
//Testing only Asserts that two readers are equal.