In a package are two classes A and B. Each A object has a reference to a B object. The state of a B instance should only be visible by A, meaning all the B attributes have a package visibility. This is due to the A class being too complex - I had split it in two (and it was semantically correct to do so).
The B class has a public method duplicate() performing a kind-of-deep-copy (meaning some attributes are deeply copied recursively, and for some only the reference is copied).
Problem is I need to make test the duplicate method:
- I can call the duplicate method
- I cannot check the state of the newly created object against the state of the original object due to the package visibility
- I would like to avoid creating getters as the state of a B object is not supposed to be visible outside of the package
Is there a way to make the attributes in B visible for testing only?