Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fredfr94 opened this issue Nov 10, 2022 · 1 comment

Comments

@fredfr94
Copy link

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

@nomemory
Copy link
Owner

@fredfr94

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

Andrei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants