mercredi 26 août 2015

Can you mock a chain of method calls with Mocktio? [duplicate]

This question already has an answer here:

Imagine I have the following line in a piece of code I am unit testing:

SomeClass.method1().method2();

Where SomeClass is a class, method1() is a static method inside SomeClass that returns some instance of, say, 'aClass', and method2() is a method that can be called from an instance of 'aClass'.

Is it possible to mock out this entire chain so that I can return a result that I want? At the moment I know I could 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 this possible?

Aucun commentaire:

Enregistrer un commentaire