Hi All,
I have a scenario where I need to override the behavior of a class, but that class has a private default constructor (no argument constructor) and provide my own implemenation of a static method.
Assume that I have three classes A,B,C
class B and C has private no argument constructors. A invokes the static method of B, and in turn B invokes the static method of C. A has no direct visibility of C.
Now, I'm writing some
unit tests for A and want to mock up the behavior of C. i.e ,I want to create a mock class for C, with my own implementation of the static method. For that I thought, I can over ride C and hide the implementation of a static method of the parent class, with my own. Similarly mock the behavior of B, hiding the implementation of the entire static method or part of it that, calling C. But my problem is I can not extend B or C to have my own implementation, due to private constructors. I could have implemented the interfaces which B and C are implementing, but I have to duplicate lot of code which is not needed for me and that would be a overkill.
Considering this scenario, is it possible to apply any design
pattern to accomplish this, with out refactoring B or C. Any advice.
Thanks