qertcounter.blogg.se

Mockito captor
Mockito captor









mockito captor

mockito captor

I know, it’s not the end of the world, and it already looks better than the Java equivalent, but we can do even better Let’s start with the nicer API, if you have used argument captors in the past you probably noticed that they are quite verbose, requiring us to call different methods like capture() and getValue depending onwhat stage of the test we where, let’s see an example of this val aMock = mock val captor = argumentCaptor aMock.stringArgument("it worked!") verify(aMock).stringArgument(captor.capture()) captor.getValue shouldBe "it worked!"Īs you can see we have to call capture() when we pass the captor the the verify method and then getValue to check the value the captor got. Provide a nicer API leveraging in the Scala power.Now it’s time to move into some other features mockito-scala provides! ArgCaptor We’ve already seen how the original Mockito Java API was improved in Part 1 and also how the matchers are easier to use and more powerful in Part 2

mockito captor

It’s also worth to check said README to discover the new features introduced in 1.x.x

#Mockito captor series

This article series was written for the version 0.x.x of mockito-scala, and while the technical details and reasoning behind the new features still holds true, some parts of the API were changed from 1.x.x, so I strongly recomend to have a read to the README where the changes are explained.











Mockito captor