Imagine that I have the following line in a piece of code. I am testing a module:
SomeClass.method1().method2();
If SomeClass is a class, method1 () is a static method inside SomeClass that returns some instance, for example, 'aClass', and method2 () is a method that can be called from an instance of "aClass".
Is it possible to mock the whole chain so that I can return the result that I need? At the moment, I know that I can do something similar to this:
BDDMockito.given(SomeClass.method1()).willReturn(mockedAClass); when(mockedAClass.method2()).thenReturn(true);
But I would rather do something like this:
when(SomeClass.method1().method2()).thenReturn(true);
Is it possible?
EDIT: This question has been marked as duplicate, but there is one big difference between my question and the “duplicate”. In my question, the first method is static, the second is not. I can't seem to get mockito to cling to this static method, which makes me think that this is not the same answer.
source share