nomemory/mockneat

tutorial for shuffling a subset of properties, given an instance of object

fredfr94 opened this issue · 1 comments

Bonjour,

I had working with MockNeat to implement a groovy interface.
Given an instance of an object, the interface can shuffle all the fields of the object.

interface Shuffle {
    void shuffleObject()
    void shufflePartly(Class[] classesThatChange)
}

It can also shuffle some fields of the instance without touching the others, for instance : all the String type.
This interface can deal with inheritance with respect on protected field.

It was not easy for me to design the script. I tried insistantly to find a elegant way with filler(), constructor() and factory(), reading the website tutorials but none of these calls can shuffle an existing instance partially.

So my script is using only reflect(). :-)
Maybe there is a better alternative solution. In case not, I suggest to underline the power of reflect() in your tutorial. Hope the script can help.

Thank you for the lib.

tuto-shuffle-interface.groovy.txt

@fredfr94

Thank you for the contribution.
Once i will have more time, I will link ur example.

Andrei