Some times I found myself in situations in which unit tests would be easier if I change the visibility of some methods from private to package private in order to either facilitate unit test mocking, assertions...
One example would be this
Say I have an object A that contains 4 attributes X, Y, Z and R where X, Y and Z are sets and R are relations among different elements of each set, for example a relation will be composed of an element of X , an element of Y and an element of Z. The object A does not allow direct access to X, Y, Z or R, instead it provides a rich API which allows you to create new elements on X, Y and Z, also allows you to mix those elements into new R elements. For a unit testing it would be highly convenient to have a public getX(), public getY(), public getZ() and public getR() methods, so I can make exact assertions about the internals of the object each time I call the object API. However, exposing X, Y and Z is something I want to prevent, which is why from the very beggining the object make those elements private and only provided indirect access to them by using its API. Would it however make sense to provide package private methods getX(), getY(), getZ() and getR() so that at least form the unit test I can easily check if the internal state of the object is the expected one?
The drawback is of course that the visibility of the method is increased and given that such method was private for a good reason, It feels a little bit weird.
Of course I could use reflection to achieve the same, but that feels even dirtier.
So the question is, is this a good or a bad practice? is it a code smell? does it happen to someone else? is there a better technique for this?