Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you capture and inspect arguments supplied to a method under test with ScalaMock?

The Java Mocking framework Mockito has a utility class called ArgumentCaptor that accumulates a list of values as a method under verification is invoked multiple times.

Does ScalaMock have a similar mechanism?

like image 954
fatuhoku Avatar asked Oct 22 '22 10:10

fatuhoku


2 Answers

There's an under the hood mechanism that does this in the preview release of ScalaMock3, but it's not currently exposed to client code.

What's your use case for this?

You might be able to achieve what you need by using where or onCall documented here (under the "Predicate matching" and "Return Value" headings respectively).

like image 70
Paul Butcher Avatar answered Nov 13 '22 01:11

Paul Butcher


In Specs2 you can use the following:

myMock.myFunction(argument) answers(
    passedArgument => "something with"+passedArgument
)

This maps to Mockito's ArgumentCaptor under the hood.

like image 33
iwein Avatar answered Nov 13 '22 00:11

iwein