https://kotlinlang.org logo
#testing
Title
# testing
a

Andrew Ebling

02/15/2021, 10:21 AM
I want to test that calling a given method on my subject/unit under test calls a given method on a mock, with any lambda as an argument. However if I do this:
Copy code
subject.openThePodBayDoors()

verify(mockDoorManager).completion(Mockito.any())
...then I get an error:
Copy code
java.lang.IllegalStateException: Mockito.any() must not be null
...even though I have written the production code which should make this test pass. I’ve been googling “kotlin mockito match any lambda” etc. and can find complex tests with
LambdaMatcher
but all I want to do is check that the method was called with some lamba - I don’t even care what it does for this test. There must be a simple solution for this I’m missing, surely?
I’ve also tried:
Copy code
verify(mockDoorManager).completion(argThat(ArgumentMatcher { true } ))
...but get exactly the same runtime error
9 Views