Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
You mean, aside from giving the team that made B a stern talking to? ;-) You could introduce another layer of indirection, and mock that. For instance like this: interface MockFriendlyB { pu...
Answer
#1: Initial revision
You mean, aside from giving the team that made `B` a stern talking to? ;-) You could introduce another layer of indirection, and mock that. For instance like this: interface MockFriendlyB { public void add(T arg); } class UnmockedB implements MockFriendlyB { B b = ...; public void add(T arg) { b.add(arg); } } class MockedB implements MockFriendlyB { public void add(T arg) { // do whatever you like } } and then change `A` to use a `MockFriendlyB` rather than `B`, and give `A` an `UnmockedB` in normal usage, but a `MockedB` when testing.