I would like write something like this :
this.spyObject = Mockito.spy(myObject);
...
verify(this.spiedObject, atLastOnce()).getMember().doSomething(any(OneClass.class))
or
this.spyObject = Mockito.spy(myObject);
...
verify(this.spiedObject.getMember(), atLastOnce()).doSomething(any(OneClass.class))
in a Junit test, knowing that the constructor of myObject is
public MyObject() {
this.member = new Member()
}
Obviously, it doesn't works !
Finally, I would be able to verify doSomething was called on the member.
I'm pretty beginner with Mockito :)
Any help please ?
It sounds like you want
Memberto be a spy too. In this case, you could do something like this:Be warned, including
doReturn(...)with a spy is partial mocking if you intend to only mockgetMember()and not its other functions. In that case, consider using a full mock and deciding what the return values of its other functions should be.