Skip to content

Commit 1d81c42

Browse files
committed
Add corner case of mockito
1 parent 22e518e commit 1d81c42

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/org/openrewrite/java/spring/util/concurrent/SuccessFailureCallbackToBiConsumerVisitor.java

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
4444
if (ADD_CALLBACK_SUCCESS_FAILURE_MATCHER.matches(mi)) {
4545
mi = (J.MethodInvocation) new MemberReferenceToMethodInvocation().visitNonNull(mi, ctx, getCursor().getParent());
4646

47+
/* If the first argument is a method invocation, very probably it's a mockito.when(), we should not do anything here
48+
* For example:
49+
* ListenableFuture<SendResult> future = mock(ListenableFuture.class);
50+
* doAnswer(i -> {
51+
* return null;
52+
* }).when(future).whenComplete(any(), any());
53+
*/
54+
if (mi.getArguments().get(0) instanceof J.MethodInvocation) {
55+
return mi;
56+
}
57+
4758
J.Lambda successCallback = (J.Lambda) mi.getArguments().get(0);
4859

4960
boolean isKafkaFailureCallback = false;

0 commit comments

Comments
 (0)