title: kotlin.UninitializedPropertyAccessException: lateinit property mRepository has not been initialized
body: <p>I have a method in my SearchViewModel and I want to test this method by Mockito and JUnit4.(searchCity())
  but this error is shown after running the test:</p>
  
  <p>kotlin.UninitializedPropertyAccessException: 
  lateinit property mRepository has not been initialized</p>
  
  <p>SearchViewModel class :</p>
  
  <pre><code>class SearchViewModel @Inject constructor() : BaseViewModel() {
  
      @Inject
      lateinit var mRepository: DataRepository
      @Inject
      lateinit var sharedPfs: SharedPrefs
  
      private var disposable: Disposable? = null
      val search = MutableLiveData&lt;ResponseSearch&gt;()
      val searchOWM = MutableLiveData&lt;ResponseOWMCity&gt;()
      val searchCityName = MutableLiveData&lt;String&gt;()
      val serachClick = SingleLiveEvent&lt;Boolean&gt;()
      val progressBar = SingleLiveEvent&lt;Boolean&gt;()
      val searchOWMvisibility = SingleLiveEvent&lt;Boolean&gt;()
      val cityOWMclick = SingleLiveEvent&lt;ResponseOWMCity&gt;()
  
      override fun getSharedPrefs(): SharedPrefs? {
          return sharedPfs
      }
  
      fun stop() {
          disposable?.let { if (!it.isDisposed) it.dispose() }
      }
  
      fun fabSearchClick(){
          serachClick.call()
      }
  
      fun searchCity() {
          val cityName = searchCityName.value
          if (!Strings.isEmptyOrWhitespace(cityName)) {
              progressBar.postValue(true)
              disposable = mRepository.doSearchProcess(cityName)
                  ?.subscribe({
                      search.postValue(it)
                      progressBar.postValue(false)
                  }, {
                      showToast(it!!.message!!)
                      progressBar.postValue(false)
                  })
          } else{
              showToast("لطفا شهر دلخواه خود را وارد کنید.")
          }
      }
  
  
      fun searchCityOWM() {
          val cityName = searchCityName.value
          disposable = mRepository.doSearchProcessOWM(cityName)
              ?.subscribe({
                  if (it != null){
                      searchOWM.postValue(it)
                      searchOWMvisibility.postValue(true)
                  } else{
                      searchOWMvisibility.postValue(false)
                  }
  
              }, {
                  searchOWMvisibility.postValue(false)
              })
  
      }
  
      fun clickCityOWM(city: ResponseOWMCity){
          cityOWMclick.postValue(city)
      }
  }
  </code></pre>
  
  <p>DataRepository class :</p>
  
  <pre><code>class DataRepository @Inject
      constructor(private val endPointAPI: EndPointAPI, private val localRoomDatabse: LocalRoomDatabse) {
  
      fun getAllSavedResults(): LiveData&lt;List&lt;City?&gt;&gt;? {
          return localRoomDatabse.roomDao().getAllResults()
      }
  
      fun doSearchProcess(city: String?): Observable&lt;ResponseSearch&gt;? {
          return endPointAPI.searchCities(Config.BASE_URL2 + city)
              .subscribeOn(Schedulers.io())
              ?.observeOn(AndroidSchedulers.mainThread())
              ?.doOnError({ throwable -&gt; Log.i("1397", "remote: " + throwable.message) })
      }
  }
  </code></pre>
  
  <p>SearchViewModelTest :</p>
  
  <pre><code>class SearchViewModelTest {
  
      @get:Rule
      val mockitoRule: MockitoRule = MockitoJUnit.rule()
  
      @get:Rule
      val taskExecutorRule = InstantTaskExecutorRule()
  
      @Rule
      @JvmField
      var testSchedulerRule = RxImmediateSchedulerRule()
  
      @Mock
      lateinit var observer: Observer&lt;ResponseSearch&gt;
  
      @Mock
      lateinit var mRepository: DataRepository
  
      lateinit var searchViewModel: SearchViewModel
  
  
      @Before
      @Throws(Exception::class)
      fun setUp() {
          MockitoAnnotations.initMocks(this)
          searchViewModel = SearchViewModel()
      }
  
  
      @Test
      fun doSearchResultSuccessWithData() {
  
          // GIVEN
          val res = RESULT()
          res.name = "shiraz"
          val list = ArrayList&lt;RESULT&gt;()
          list.add(res)
          val search = ResponseSearch(list)
          val observable = Observable.just(search)
  
  
          // WHEN
          searchViewModel.searchCityName.value = "shiraz"
          searchViewModel.search.observeForever(observer)
          whenever(mRepository?.doSearchProcess("shiraz")).thenReturn(observable)
          searchViewModel.searchCity()
          // THEN
          assertNotNull(searchViewModel.search.value)
          assertThat(searchViewModel.search.value?.results?.size, CoreMatchers.`is`(1))
  
      }
  }
  </code></pre>
  
  <p>can anyone help me?</p>