java - Mocking anonymous function -
i'm writing junits , got stuck lambda expressions.
is there way mock anonymous function?
return retrytemplate.execute(retrycontext -> { return mockedresponse; });
in above code, i'm trying mock retrytemplate
. retrytemplate
of type - org.springframework.retry.support.retrytemplate
assuming retrytemplate dependency in bean "mybean", use dependency injection mock retrytemplate.execute method using mockito , configure accept parameter:
retrytemplate mockretrytemplate = mockito.mock(retrytemplate.class); mockito.when(mockretrytemplate.execute(matchers.any(retrycallback.class))).thenreturn(mockedresponse); mybean.setretrytemplate(mockretrytemplate);
if trying mock parameter method parameter happens lambda, create new lambda expression stub rather try mock it.
Comments
Post a Comment