Let\'s imagine I have a following method in some service class:
public SomeEntity makeSthWithEntity(someArgs){
SomeEntity entity = new SomeEntity();
/**
You can implement an Answer
and then use thenAnswer()
instead.
Something similar to:
when(mock.someMethod(anyString())).thenAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
return invocation.getArguments()[0];
}
});
Of course, once you have this you can refactor the answer into a reusable answer called ReturnFirstArgument
or similar.