package foo; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; class Test { public void setup(OngoingStubbing>> stubbing) throws ReflectiveOperationException { stubbing.thenAnswer(inv -> toMap((Collection) inv.getArguments()[0], periodic((String) null))); } private Map toMap(Collection keys, V v) { return Collections.emptyMap(); } private List periodic(T t) throws ReflectiveOperationException { return null; } } abstract class OngoingStubbing { abstract OngoingStubbing thenAnswer(Answer answer); } interface Answer { T answer(InvocationOnMock invocation) throws Throwable; } interface InvocationOnMock { Object[] getArguments(); }