0

I've got an interface:

interface DistanceChecker {
   fun checkDistance(locationData: LocationData, result: (Boolean) -> Unit)
}

I need to mock this method, but I don't call it explicitly, it's injected into logic. This construction does not work:

    doAnswer {
        it.getArgument<(Boolean) -> Unit>(1).invoke(true)

        null
    }.`when`(distanceChecker).checkDistance(
        same(
            LocationData(
                LatLng(.0, .0),
                LatLng(.0, .0),
                .0
            )
        ),
        any()
    )

By this I got a stubbing error:

- this invocation of 'checkDistance' method:
distanceChecker.checkDistance(
LocationData(point=0.0_0.0, location=0.0_0.0, zoneRadius=0.0),
(kotlin.Boolean) -> kotlin.Unit
);
- has following stubbing(s) with different arguments:
1. distanceChecker.checkDistance(
LocationData(point=0.0_0.0, location=0.0_0.0, zoneRadius=0.0),
null
);

Is there any way to mock lambda like that?

apleuxa12
  • 85
  • 5

0 Answers0