Overload resolution ambiguity while using Robolectric


#1

I’m experimenting with Robolectric + Kotlin project. I managed to run thing quite smoothly, but i stombled on using shadowOf function. My code:

import com.pawegio.kandroid.IntentFor
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.*
import org.mockito.runners.MockitoJUnitRunner
import org.robolectric.Robolectric
import pl.ownvision.dogsociety.*
import pl.ownvision.dogsociety.authorization.Authorization
import org.hamcrest.MatcherAssert.assertThat
import org.robolectric.Shadows.*

@RunWith(MockitoJUnitRunner::class)
class SplashActivityTest : BaseRobolectricTest() {

    lateinit var activity: SplashActivity

    @Mock
    lateinit var authProvider: Authorization

    @Before
    fun setup() {
        val module = AndroidModule(activity.application as MainApplication)
        Mockito.spy(module)
        Mockito.doReturn(authProvider).`when`(module).provideAuthorization()

        MainApplication.graph = DaggerApplicationComponent.builder().androidModule(module).build()

        activity = Robolectric.setupActivity(SplashActivity::class.java)
    }

    @Test
    fun userNotLoggedIn() {
        `when`(authProvider.isLoggedIn()).thenReturn(true)

        val expectedIntent = IntentFor<LoginActivity>(activity)
        assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent)
    }
}

results with an compile error on line assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent)

Error is like that:

Error:(41, 20) Overload resolution ambiguity:
public open fun shadowOf(actual: [ERROR : Unresolved java classifier: AndroidHttpClient]!): org.robolectric.shadows.ShadowAndroidHttpClient! defined in org.robolectric.Shadows
public open fun shadowOf(actual: android.app.Activity!): org.robolectric.shadows.ShadowActivity! defined in org.robolectric.Shadows
public open fun shadowOf(actual: android.content.Context!): org.robolectric.shadows.ShadowContext! defined in org.robolectric.Shadows
public open fun shadowOf(actual: android.content.ContextWrapper!): org.robolectric.shadows.ShadowContextWrapper! defined in org.robolectric.Shadows
public open fun shadowOf(actual: android.view.ContextThemeWrapper!): org.robolectric.shadows.ShadowContextThemeWrapper! defined in org.robolectric.Shadows

Any ideas why is that happening?


#2

Ok, that seems to be Robolectric issue with sdk 23.

compileSdkVersion 23
buildToolsVersion "23.0.2"

useLibrary 'org.apache.http.legacy'

It helped!