1

With

  • Kotlin 1.0.6
  • Mockito 2.6.3

If I have a class like:

class UserRepository {
   var loggedInUser: User?
       get() = //...
}

How can I mock the get of loggedInUser with mockito?

Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
  • The question duplicate covers mocking of `final` elements, while this question is about mocking a property. Thus, it shouldn't be closed for that reason. For that matter, if you apply `open` to the class so Mockito allows you to mock it, you can do `when(mockUserRepository.loggedInUser).thenReturn(someValue)`. – nhaarman Jan 25 '17 at 06:56
  • 1
    I marked as duplicate since the other question is related and the answer fix this too. – Daniel Gomez Rico Jan 25 '17 at 16:31
  • @caipivaira Fair enough. – nhaarman Jan 25 '17 at 16:43

0 Answers0