I’m using Mockito for my unit testing, and I’ve run across an issue where I have a collection of hashes, and I want to verify that the parameters were equivalent.
i.e. I have something like
Collection< byte[] > blobs = new ArrayList< byte[] >();
// Do some stuff, omitted for brevity
verify( mockStore ).setWhatever( eq( blobs ) );
This fails, since ‘equals()’ on byte[]’s does a reference compare (and it’s not the same reference).
Is there something simple I’m missing to compare two collections of byte[]’s? Is there a special matcher that I need to use for the comparison? Normally I’d use Arrays.equal(), but I don’t know how to tell Mockito to use that for comparing the elements. Suggestions?
There’s no deepEquals mockito matcher. However you could code one in some test helper, for example :
Which should give soemthing like :