lupuuss / Mokkery

The mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
https://mokkery.dev
Apache License 2.0
202 stars 8 forks source link

Not able to verify objects by their content #22

Closed mikolajefento closed 4 months ago

mikolajefento commented 4 months ago

Hello! I've found an issue with verifying the objects when the contents are the same but instances are not. Here is the error message:

Calls to the same method with failing matchers:
  ByteArrayParser(1).doNothing(id = UUID@fcb4004, value = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33])
    [-] id:
       expect: UUID@8c11eee
       actual: UUID@fcb4004
    [-] value:
       expect: [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
       actual: [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]

As one can see the contents of byte array are the same. Also I am using the any() matcher so it should not matter if the contents are the same at the first place.

The minimal reproducible example is attached. multiplatform-library-template.zip Tested on Mac with apple chip and on windows

lupuuss commented 4 months ago

It's expected behavior. All literal arguments are checked by equals. It seems that both ByteArray and UUID have default equals (by reference). For arrays it's a known behavior and mokkery provides a matcher contentEq. For UUID, override equals or use custom matcher e.g. matching.

mikolajefento commented 4 months ago

Ok, makes sense. I've tried verifying with custom matcher and it works fine now. Thank you for quick response!