Several times I found myself in situations where unit tests would be easier if I changed the visibility of some methods from a private to a private package to facilitate unit test mocking, assertions ...
One example would be this
Let's say I have an object A that contains 4 attributes X, Y, Z and R, where X, Y and Z are sets and R is the relationship between the different elements of each set, for example, the relationship will consist of the element X, the element Y and element Z. Object A does not allow direct access to X, Y, Z or R, instead it provides a rich API that allows you to create new elements on X, Y and Z, and also allows you to mix these elements with new elements of R. For unit testing it would be very convenient to have public methods getX (), public getY (), public getZ () and p ublic getR (), so I can make precise statements about the internal components of an object every time I call the API of the object. However, exposing X, Y, and Z is what I want to prevent, so from the very beginning the object makes these elements private and provides indirect access to them using its API. However, does it make sense to provide private methods getX (), getY (), getZ () and getR () so that at least to form a unit test, I can easily check if the internal state of the object is expected?
The disadvantage, of course, is that the visibility of the method increases, and given that such a method was closed for a good reason, it feels a little strange.
Of course, I could use reflection to achieve the same, but it feels even messier.
So the question is, is it good or bad practice? is it the smell of code? does this happen to someone else? is there a better technique for this?