0

I have the followign bit of code which is failing in the arguents mismatch error

       mockSpotAccessor.doWithRetry(eq({
            mockSpotAccessor.asyncNestedAggregation(any(), any(), any(), any(), any()) }), eq(5))

        verify(mockSpotAccessor, times(1)).doWithRetry(eq({
            mockSpotAccessor.asyncNestedAggregation(any(), any(), any(), any(), any()) }), eq(5))

Expected spotAccessor.doWithRetry( (callRetryForAsyncCalls$2) () -> java.util.concurrent.CompletableFuture<kotlin.collections.List<com.amazon.noblearsenallambda.AggregationResultObject>>, 5 );

Actual spotAccessor.doWithRetry( (callRetryForAsyncCalls$answer$1) () -> java.util.concurrent.CompletableFuture<kotlin.collections.List<com.amazon.noblearsenallambda.AggregationResultObject>>, 0 );

I am not sure, as working with mockito for the first time

1 Answers1

0
  1. The two lambdas cannot be expected to be eq (equals) to each other, even if the contents are identical, unless they refer to the exact same object reference.

  2. When using matchers, matchers should only be used directly within the invocation for when or verify for all arguments to the call to when or verify. Because you're describing a lambda, the calls to any() don't happen as part of the call to when or verify, and therefore you should not use matchers.

The best shot you have is to use any() in place of the entire Unit or callback lambda, or possibly use an ArgumentCaptor to capture the lambda, then invoke the lambda under controlled conditions and verify that it is invoked as you expect.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • My lambda function definition is `fun doWithRetry(action: () -> CompletableFuture, retryCount: Int): CompletableFuture {}` .I f I passed any I get the error `type inference failed: Not enough information to infer parameter T in fun doWithRetry ( action: () → CompletableFuture, retryCount: Int ) : CompletableFuture Please specify it explicitly.` – Sakshi Garg Dec 13 '21 at 21:44
  • @SakshiGarg That's a slightly different problem, but you can call `>doWithRetry(/*...*/)` [as described here](https://stackoverflow.com/q/57256572/1426891). – Jeff Bowman Dec 13 '21 at 21:52