For testing purposes, I want to replace the implementation of a few methods of an object that implements some interface. One way of doing this would be to create a new object, passing the instance as a parameter to the constructor, and manually recreating all of the methods to use the instance’s methods for all but a couple of methods, which would be overridden for testing purposes. Unfortunately, the interface has a large number of methods, which makes this option tedious.
Is there some way to create an object that is a “subclass of an instance of an object” in the sense that it simply calls the instance’s method’s for all calls except when overridden?
Dynamic Proxy Classes may be a way to go. I have never used it before, however it is a viable mechanism to catch every method invocation and decide whether to invoke old method or do something else and/or extra.
The link I provided has even an example of
DebugProxywhich may be helpful for you.