I'm trying to stub an instance method of a particular class, so that when any instance of this Foo class calls this instance method doSomething, the same object is returned (see code below). However, mockito doesn't allow any matchers outside of verification or stubbing.
Bar object = new Bar();
given(any(Foo.class).doSomething(Arg.class)).willReturn(object);
And in Foo.class:
Bar doSomething(Arg param) {
Bar bar = new Bar();
// Do something with bar
return bar;
}
Any way I can achieve this goal with Mockito? Thanks!