mardi 12 février 2019

Is it possible to mock System.idenitiyHashCode?

Good day.

I have a tool which instruments objects in project by adding certain bytecode-generated toString implementation to each. The logic of generated toString is irrelevant but what important is that the returned string depends on System.idenitityHashCode invocations, made inside.

Now I want to cover the generated logic with automated tests. I created class for testing, generated toString for it and want to assert over its toString output. It's obvious that such assertion won't be stable, since System.identityHashCode gives different results between test runs.

Is it possible somehow to mock System.identityHashCode or stabilize the result it is given?

Aucun commentaire:

Enregistrer un commentaire