I've seen that some developers are using some methods (namely getInternalState()
/setInternalState
) from the Whitebox
class.
My question is whether this is a good practice or not? I ask this because this class is in the package org.mockito.internal.util.reflection
and usually classes within an internal package are not meant to be used by the outside world.
If you take a look at the code, it is not a big deal at all. See here: https://code.google.com/p/mockito/source/browse/src/org/mockito/internal/util/reflection/Whitebox.java?r=9772247b067621ed5c3cefc356397b0bde5b89f6
If it is moved, you can do a full replace on the test code, which takes 2 minutes. If it will be deleted somehow from Mockito (which is not likely I think), then you can duplicate the class to your code (~50 lines). If there is any change, your tests will be broken, and you will see, that you need to change them. No real chance to get hidden problems.
So I would simply use it in test codes if neccessary.