I came across a scenario where I am not able to mock/stub a method.
Class A{
B b = new B();
method aa(){
... call to method bb in class B
}
}
Class B{
method bb(){
......
}
}
I want to mock method bb for class B. Since method aa of class A doesn't have constructor where b is being passed I am not sure how I can mock it behavior.
I tried mocking B
A a = new A();
B b_mock = Mockito.mock(B.class);
when(b_mock.bb).thenReturn(..something);
a.aa();
But when testing method aa it still goes in method bb, which make sense as there is no relation between A and b_mock. I am not sure how to establish a connection between A and B.
I tried @InjectMock which also doesn't work and I am trying to avoid powerMock. I am not sure if this is achievable.
Thanks in advance!