I am trying to verify a method call made by an indirect private field object. For example
Code to Test:
class A
{
final private B b;
public A(C c, D d)
{
this.b = new B(c,d);
}
public void methodToTest()
{
b.wantToVerifyThisIsCalled();
}
}
class B
{
private C c;
private D d;
public B(C c, D d)
{
this.c = c;
this.d = d;
}
...
public void wantToVerifyThisIsCalled()
{
//do stuff
return;
}
}
I want to verify that b.wantToVerifyThisIsCalled() method was called when I run A.methodToTest();
I tried something like this but this doesn't work:
C c = mock(C.class);
D d = mock(D.class);
A a = new A(C,D);
B b = moc(B.class);
a.methodToTest();
verify(b).wantToVerifyThisIsCalled(); \\<-- This gives me error, wanted but not invoked
How should I verify that this b field object of class A is indeed making that method call ?
There is sadly no setter method and the field object is also marked as final :(
Thank you