From ef14673a32fec322da7669feb042f27f50f9fd81 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Tue, 4 Jan 2022 17:49:07 +0200 Subject: [PATCH] PR#32 Fix lint issues, remove Jake's IdlingResources, since it won't be updated anymore --- app/build.gradle | 19 +++++--- .../testutils/idling/OkHttp3IdlingResource.kt | 46 +++++++++++++++++++ .../idling/NetworkSynchronization.kt | 1 - .../idling/NetworkSynchronization.kt | 1 - build.gradle | 2 +- gradle.properties | 2 +- gradlescripts/versions.gradle | 1 - 7 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/OkHttp3IdlingResource.kt diff --git a/app/build.gradle b/app/build.gradle index d240085..25c7ae8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,13 +7,12 @@ plugins { } android { - compileSdkVersion 31 + compileSdk 31 defaultConfig { applicationId "org.fnives.test.showcase" - minSdkVersion 21 - //OldTargetApi - targetSdkVersion 31 + minSdk 21 + targetSdk 31 versionCode 1 versionName "1.0" buildConfigField "String", "BASE_URL", '"https://606844a10add49001733fe6b.mockapi.io/"' @@ -139,7 +138,6 @@ dependencies { testImplementation "androidx.test.espresso:espresso-core:$testing_espresso_version" testImplementation "androidx.test.espresso:espresso-intents:$testing_espresso_version" testImplementation project(':mockserver') - testImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$testing_okhttp3_idling_resource_version" testImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version" testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" testImplementation "com.google.dagger:hilt-android-testing:$hilt_version" @@ -154,7 +152,6 @@ dependencies { androidTestImplementation "androidx.test.espresso:espresso-core:$testing_espresso_version" androidTestImplementation "androidx.test.espresso:espresso-intents:$testing_espresso_version" androidTestImplementation project(':mockserver') - androidTestImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$testing_okhttp3_idling_resource_version" androidTestImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version" androidTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version" @@ -162,4 +159,12 @@ dependencies { androidTestImplementation project(":network") // hilt needs it implementation "io.reactivex.rxjava3:rxjava:3.1.2" -} \ No newline at end of file +} + + +///Users/gergelyhegedus/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.31/ff5d99aecd328872494e8921b72bf6e3af97af3e/kotlin-stdlib-jdk8-1.5.31.jar (version 1.5) +///Users/gergelyhegedus/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.5.31/77e0f2568912e45d26c31fd417a332458508acdf/kotlin-stdlib-jdk7-1.5.31.jar (version 1.5) +///Users/gergelyhegedus/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.6.0/a40b8b22529b733892edf4b73468ce598bb17f04/kotlin-stdlib-1.6.0.jar (version 1.6) +///Users/gergelyhegedus/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.6.0/7857e365f925cfa060f941c1357cda1f8790502c/kotlin-stdlib-common-1.6.0.jar (version 1.6) +//w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath +//dagger.lint.DaggerIssueRegistry in /Users/gergelyhegedus/.gradle/caches/transforms-3/7d8d9a87fed97b25e3e147795231ede4/transformed/jetified-dagger-lint-aar-2.40/jars/lint.jar does not specify a vendor; see IssueRegistry#vendor diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/OkHttp3IdlingResource.kt b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/OkHttp3IdlingResource.kt new file mode 100644 index 0000000..c22ad2f --- /dev/null +++ b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/OkHttp3IdlingResource.kt @@ -0,0 +1,46 @@ +package org.fnives.test.showcase.testutils.idling + +import androidx.annotation.CheckResult +import androidx.annotation.NonNull +import androidx.test.espresso.IdlingResource +import okhttp3.Dispatcher +import okhttp3.OkHttpClient + +/** + * AndroidX version of Jake Wharton's OkHttp3IdlingResource. + * + * Reference: https://github.com/JakeWharton/okhttp-idling-resource/blob/master/src/main/java/com/jakewharton/espresso/OkHttp3IdlingResource.java + */ +class OkHttp3IdlingResource private constructor( + private val name: String, + private val dispatcher: Dispatcher +) : IdlingResource { + @Volatile + var callback: IdlingResource.ResourceCallback? = null + + init { + dispatcher.idleCallback = Runnable { callback?.onTransitionToIdle() } + } + + override fun getName(): String = name + + override fun isIdleNow(): Boolean = dispatcher.runningCallsCount() == 0 + + override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) { + this.callback = callback + } + + companion object { + /** + * Create a new [IdlingResource] from `client` as `name`. You must register + * this instance using `Espresso.registerIdlingResources`. + */ + @CheckResult + @NonNull // Extra guards as a library. + fun create(@NonNull name: String?, @NonNull client: OkHttpClient?): OkHttp3IdlingResource { + if (name == null) throw NullPointerException("name == null") + if (client == null) throw NullPointerException("client == null") + return OkHttp3IdlingResource(name, client.dispatcher) + } + } +} diff --git a/app/src/sharedTestHilt/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt b/app/src/sharedTestHilt/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt index 5cef5c9..2a81671 100644 --- a/app/src/sharedTestHilt/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt +++ b/app/src/sharedTestHilt/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt @@ -2,7 +2,6 @@ package org.fnives.test.showcase.testutils.idling import androidx.annotation.CheckResult import androidx.test.espresso.IdlingResource -import com.jakewharton.espresso.OkHttp3IdlingResource import okhttp3.OkHttpClient import org.fnives.test.showcase.hilt.SessionLessQualifier import org.fnives.test.showcase.hilt.SessionQualifier diff --git a/app/src/sharedTestKoin/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt b/app/src/sharedTestKoin/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt index a6fca71..7bcb095 100644 --- a/app/src/sharedTestKoin/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt +++ b/app/src/sharedTestKoin/java/org/fnives/test/showcase/testutils/idling/NetworkSynchronization.kt @@ -2,7 +2,6 @@ package org.fnives.test.showcase.testutils.idling import androidx.annotation.CheckResult import androidx.test.espresso.IdlingResource -import com.jakewharton.espresso.OkHttp3IdlingResource import okhttp3.OkHttpClient import org.koin.core.qualifier.StringQualifier import org.koin.test.KoinTest diff --git a/build.gradle b/build.gradle index dad6a57..791926d 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } dependencies { classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.0.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.0" } diff --git a/gradle.properties b/gradle.properties index 349b5c9..3852b81 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true +android.enableJetifier=false android.jetifier.ignorelist=bcprov-jdk15on # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official \ No newline at end of file diff --git a/gradlescripts/versions.gradle b/gradlescripts/versions.gradle index 8c76f7c..2a3c544 100644 --- a/gradlescripts/versions.gradle +++ b/gradlescripts/versions.gradle @@ -26,5 +26,4 @@ project.ext { testing_junit4_version = "4.13.2" testing_robolectric_version = "4.6.1" testing_espresso_version = "3.4.0" - testing_okhttp3_idling_resource_version = "1.0.0" } \ No newline at end of file