nomemory/mockneat

Issue with mocking a class with a final static long field

leo4ever opened this issue · 3 comments

Hello,
I have a class which implements the Serializable interface and has the default declaration "serialVersionUID"
When I tried to mock the class, I get the error 'Cannot set field long.serialVersionUID to null

Stack trace below:
java.lang.IllegalArgumentException: Cannot set field long.serialVersionUID with value 'null'. Is the supplied value correct ? at net.andreinc.mockneat.unit.objects.Reflect.lambda$setValues$2(Reflect.java:176) at java.util.ArrayList.forEach(ArrayList.java:1257) at net.andreinc.mockneat.unit.objects.Reflect.setValues(Reflect.java:150) at net.andreinc.mockneat.unit.objects.Reflect.lambda$supplier$0(Reflect.java:87) at net.andreinc.mockneat.abstraction.MockUnit.val(MockUnit.java:68)

@leo4ever

I will investigate this issue next week. Until then can you use the filler() method instead of reflect()?

The reflect() needs to be fixed anyways and judging now I think it was a bad idea to have this method anyways.

@leo4ever

https://github.com/nomemory/mockneat/wiki/MockNeat#filler

Basically the filler() doesn't rely on invasive reflection tricks and allows you to use the normal method for creating objects, and fill them with data through setters.

@leo4ever

I don't seem to reproduce this issue.
Can you please add more details, eg.: the failing code ?