Null pointer exception when stubbing

  android, kotlin, mockito

Good afternoon, I have a nullpointer exception when stubbing


import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.micheladrien.fresquerappel.R
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock    
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.junit.MockitoJUnitRunner

class MainViewModelTest {

  var instantTaskExecutorRule = InstantTaskExecutorRule()    

  val applicationMock: Application = mock(
  fun setUpTaskDetailViewModel() {

I need to stub this function because my viewmodel gets strings from context.

According to this blog post :
I should replace when thenreturn by when then (answer) which if it’s true, why ?

I have already Tested : Changing value to a brut number. => Same error
Mocking the file inside the before and using lateinit for the declaration at @Mock => same error

Unlike previous question thread Mockito – NullpointerException when stubbing Method
I am directly stubbing the method. Not stubbing the method of the object of another method.

Any help would be greatly appreciated.

Source: Android Questions