mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.11k stars 202 forks source link

any<JSONObject> returns null #183

Closed MadeRelevant closed 7 years ago

MadeRelevant commented 7 years ago

Hi,

This results into null:

val mockedJSON = any<JSONObject>()!! // <-- added !! to check in runtime, IDE tells it is redundant which is correct IMO

Looking in your tests it should run via an instance creator so I tried that as well:

MockitoKotlin.registerInstanceCreator { JSONObject() }

Unfortunately this method is not triggered from what I have seen in the debugger so far.

My gradle dependencies (bit messy at the moment):

ext {
    supportLibVersion = "25.3.1"
    anko_version = "0.10.1"
    daggerVersion = "2.9"
    mockitoVersion = "2.8.52"
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    androidTestCompile "org.mockito:mockito-core:2.8.47"
    androidTestCompile "org.mockito:mockito-android:2.8.47"

    //androidTestCompile 'com.google.dexmaker:dexmaker:2.2.0'
    //androidTestCompile 'com.google.dexmaker:dexmaker-mockito:2.2.0'
    compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'

    testCompile "org.mockito:mockito-core:2.8.47"

    androidTestCompile "com.nhaarman:mockito-kotlin:1.5.0"

    // Dependency Injection
    androidTestCompile "com.google.dagger:dagger:$daggerVersion"
    kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"

    testCompile "com.google.dagger:dagger:$daggerVersion"
    kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"

    compile "com.google.dagger:dagger:$daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"

    provided 'javax.annotation:jsr250-api:1.0'

    // RxJava
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.0'

    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile 'com.github.k0shk0sh:PermissionHelper:1.1.0'

    compile 'com.squareup.okhttp3:okhttp:3.8.0'
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile('io.socket:socket.io-client:0.8.3') {
        exclude group: 'org.json', module: 'json'
    }

    compile 'com.github.douglasjunior:android-simple-tooltip:0.2.0'
    compile 'com.facebook.fresco:fresco:1.3.0'
    compile 'com.andkulikov:transitionseverywhere:1.7.1'
    compile 'com.miguelcatalan:materialsearchview:1.0.0'
    compile 'com.mikepenz:iconics-core:2.8.2@aar'
    compile 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'
    compile 'jp.wasabeef:recyclerview-animators:2.2.6'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.0.4'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.hbb20:ccp:1.7.2'
    compile 'com.google.firebase:firebase-messaging:10.2.6'
    testCompile 'junit:junit:4.12'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    // Anko Commons
    compile "org.jetbrains.anko:anko-commons:$anko_version"
    compile "org.jetbrains.anko:anko-design:$anko_version"
    compile "org.jetbrains.anko:anko-design-coroutines:$anko_version"
    compile "org.jetbrains.anko:anko-cardview-v7:$anko_version"

    // Anko Layouts
    compile "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
    compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
}
nhaarman commented 7 years ago

any() always returns null. The instance creator is included in the library as a fallback, but is not used and not reachable for now. The solution should be to not depend on any() to return a non-null value.

nhaarman commented 7 years ago

Closing due to inactivity.