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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -