Gonen I
Gonen I

Reputation: 6117

How does the Mockito-Kotlin mock function work without a class parameter?

Mockito is a mocking framework ( that tastes really good )

mockito-kotlin is a small library that provides helper functions to work with Mockito in Kotlin.

Normally from Kotlin to mock an interface with mockito I would write something like

val mockBookService = Mockito.mock(BookService::class.java)

But when using mockito-kotlin I can change this to

val mockBookService : BookService = mock()

so my question is how does the mock function know which interface to mock without the supplied class parameter?

Upvotes: 0

Views: 871

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198113

There is one most general type that could be used in mock() to make that declaration pass a type-check: val mockBookService: BookService = mock<BookService>().

So the type system figures that out, and uses it.

Upvotes: 1

Related Questions