mcharmas / Android-ReactiveLocation

Small library that wraps Google Play Service API in brilliant RxJava Observables reducing boilerplate to minimum.
2.11k stars 312 forks source link

Mockito cannot mock this class: class pl.charmas.android.reactivelocation.ReactiveLocationProvider #195

Open ArtemNurtdinov opened 5 years ago

ArtemNurtdinov commented 5 years ago
@Mock lateinit var reactiveLocationProvider: ReactiveLocationProvider
@Mock lateinit var prefs: Preferences
@Mock private lateinit var location: Location

@Before
fun setUp() {
    initMocks(this)
    locationProvider = LocationProviderImpl(reactiveLocationProvider, prefs)

    given(location.latitude).willReturn(FAKE_LATITUDE)
    given(location.longitude).willReturn(FAKE_LONGITUDE)
}

Getting this error

org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class 
pl.charmas.android.reactivelocation2.ReactiveLocationProvider.

Using Mockito 2.23.0 Any solutions?

saadfarooq commented 3 years ago

A workaround is to add the following dependency to the testImplementation configuration.

// hacks to get ReactiveLocationProvider to mock
testImplementation "com.google.android.gms:play-services-places:17.0.0"

It provides the missing class references from ReactiveLocationProvider.