Let's say I have a constructor:
public Something(A a) {
this.a = a;
this.b = a.someLogicMethod();
this.c = b.someLogicMethod();
}
@Autowired
private Class d;
Is this code testable? If not, What should I change to make it testable and keep the initialization of b to be through method of object a, which i get as an argument to the constructor of my class.
I want to pass my object (that I created in the test class) of classB to the Something class, The problem is that Something should be mocked and the object a is mocked, so I can't change the behaviour of a with when&thenReturn so when a.someLogicMethod is called, it will return my object of classB that I created in the test class, because when Something is mocked, the when&thenReturn logic will be called after a.someLogicMethod() has already been called and b is set. I also can't have a setter for the b object because it should be initialized with a.someLogicMethod(). The reason i need Something to be mocked is because I want that the object d will be mocked.
Thanks.