Mocked Object with Mockito Kotlin Not Stubbing Method

Viewed 2735

I have the following code:

@RunWith(MockitoJUnitRunner::class)
class OnboardingViewModelTest {

    @Mock lateinit var authService : AuthService
    lateinit var internetProvider: InternetStatusProvider
    private lateinit var viewModel: OnboardingViewModel

    @Before
    fun setup() {
        internetProvider = mock()
        whenever(internetProvider.hasInternet()).thenReturn(true)
    }

The constructor of InternetStatusProvider looks like so:

InternetStatusProvider(context:Context)

I am getting a NullPointerException when stubbing the internetProvider.hasInternet() method because that method's implementation uses the context passed in the constructor and the real method is being called?

What am I missing here? the whole point is to stub the real implementation of this method?

1 Answers
Related