diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index aa2fea9db..b94dcd8f2 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -19,8 +19,7 @@ jobs: java-version: [ 11, 17, 18 ] # test LTS versions, and the newest kotlin-version: [ 1.5.31, 1.6.21, 1.7.10 ] kotlin-ir-enabled: [ true, false ] - # in case one JDK fails, we still want to see results from others - fail-fast: false + fail-fast: false # in case one JDK fails, we still want to see results from others timeout-minutes: 30 steps: - uses: actions/checkout@v2 @@ -52,7 +51,8 @@ jobs: runs-on: macos-latest strategy: matrix: - api-level: [ 28, 29 ] + api-level: [ 26, 28, 29 ] + fail-fast: false # in case one API-level fails, we still want to see results from others timeout-minutes: 30 steps: - uses: actions/setup-java@v2 @@ -73,6 +73,25 @@ jobs: path: ~/.gradle/wrapper key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} + - name: AVD cache + uses: actions/cache@v3 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: ${{ runner.os }}-avd-${{ matrix.api-level }} + + - name: create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: false + script: echo "Generated AVD snapshot for caching." + - name: run tests uses: reactivecircus/android-emulator-runner@v2 with: diff --git a/.travis.yml b/.travis.yml index 08045d51c..58ca80a7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ android: - tools - platform-tools - build-tools-27.0.3 - - android-28 + - android-30 jdk: - - oraclejdk8 + - openjdk17 install: - yes | sdkmanager "ndk;20.0.5594570" diff --git a/README.md b/README.md index e9887768f..e8ed61d3c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Check the series of articles "Mocking is not rocket science" at [Kt. Academy](ht ### Kotlin version support -From version 1.10.0 MockK does not support Kotlin 1.2.* +From version 1.13.0 MockK supports Kotlin 1.4 and higher ### Known issues diff --git a/agent/android/build.gradle b/agent/android/build.gradle index 8e54f7b84..fefb70697 100644 --- a/agent/android/build.gradle +++ b/agent/android/build.gradle @@ -40,7 +40,7 @@ task packageDispatcherJar(type: Jar) { preBuild.dependsOn(packageDispatcherJar) android { - compileSdkVersion 'android-31' + compileSdkVersion 'android-32' lintOptions { abortOnError false @@ -59,8 +59,8 @@ android { } defaultConfig { - minSdkVersion 21 - targetSdkVersion 31 + minSdkVersion 26 + targetSdkVersion 32 versionName project['version'] testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArgument "notAnnotation", "io.mockk.test.SkipInstrumentedAndroidTest" @@ -83,7 +83,7 @@ dependencies { api project(':mockk-agent-common') implementation "com.linkedin.dexmaker:dexmaker:$dexmaker_version" implementation "org.objenesis:objenesis:$objenesis_android_version" - androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', { + androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', { exclude group: 'com.android.support', module: 'support-annotations' }) androidTestImplementation 'junit:junit:4.13.1' diff --git a/agent/android/dispatcher/build.gradle.kts b/agent/android/dispatcher/build.gradle.kts index 34949f98d..b723604fb 100644 --- a/agent/android/dispatcher/build.gradle.kts +++ b/agent/android/dispatcher/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } android { - compileSdkVersion = "android-31" + compileSdkVersion = "android-32" android { lintOptions { @@ -19,8 +19,8 @@ android { } defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 applicationId = "com.android.dexmaker.mockito.inline.dispatcher" } diff --git a/build.gradle b/build.gradle index 8c0d28a46..463fc85ca 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,23 @@ import java.time.Duration buildscript { - ext.kotlin_gradle_version = findProperty('kotlin.version')?.toString() ?: '1.6.0' - ext.android_gradle_version = '7.0.0' - ext.byte_buddy_version = '1.12.6' - ext.coroutines_version = '1.3.3' + ext.kotlin_gradle_version = findProperty('kotlin.version')?.toString() ?: '1.7.10' + ext.android_gradle_version = '7.2.1' + ext.byte_buddy_version = '1.12.10' + ext.coroutines_version = '1.6.4' ext.dexmaker_version = '2.28.1' ext.objenesis_version = '3.2' ext.objenesis_android_version = '3.2' - ext.junit_jupiter_version = '5.6.2' - ext.junit_vintage_version = '5.6.2' - ext.dokka_version = '1.6.0' + ext.junit_jupiter_version = '5.8.2' + ext.junit_vintage_version = '5.8.2' + ext.dokka_version = '1.7.10' ext.gradles = project.projectDir.toString() + "/gradle" repositories { mavenCentral() google() } + dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_gradle_version" classpath "com.android.tools.build:gradle:$android_gradle_version" @@ -25,7 +26,7 @@ buildscript { } plugins { - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.9.0" + id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.11.0" } subprojects { subProject -> diff --git a/circle.yml b/circle.yml index d280cad38..2c93a6fcc 100644 --- a/circle.yml +++ b/circle.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: ~/code docker: - - image: circleci/android:api-26-alpha + - image: circleci/android:api-30 resource_class: xlarge environment: JVM_OPTS: -Xmx4096m @@ -21,18 +21,18 @@ jobs: name: Download Dependencies command: | sdkmanager --install 'ndk-bundle' - sdkmanager --install 'platforms;android-25' - sdkmanager --install 'system-images;android-25;google_apis;armeabi-v7a' + sdkmanager --install 'platforms;android-30' + sdkmanager --install 'system-images;android-30;google_apis;armeabi-v7a' - save_cache: paths: - ~/.gradle - ~/.m2 - - /opt/android/sdk/platforms/android-25 + - /opt/android/sdk/platforms/android-30 key: cache-{{ checksum ".cache-hash" }} - run: name: Starting Android emulator command: | - echo no | avdmanager create avd --package "system-images;android-25;google_apis;armeabi-v7a" --name "test" + echo no | avdmanager create avd --package "system-images;android-30;google_apis;armeabi-v7a" --name "test" emulator -avd test -no-skin -no-audio -no-window & android-wait-for-emulator adb shell input keyevent 82 & diff --git a/client-tests/jvm/build.gradle.kts b/client-tests/jvm/build.gradle.kts index 62ae32200..edbb9d5fe 100644 --- a/client-tests/jvm/build.gradle.kts +++ b/client-tests/jvm/build.gradle.kts @@ -1,6 +1,6 @@ buildscript { ext { - kotlin_version = "1.3.72" + kotlin_version = "1.7.10" } repositories { mavenCentral() @@ -12,7 +12,7 @@ buildscript { } plugins { - kotlin("jvm") version "1.3.72" + kotlin("jvm") version "1.7.10" } java { @@ -32,29 +32,17 @@ repositories { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib") { - version { - strictly("$kotlin_version") - } - } - implementation("org.jetbrains.kotlin:kotlin-stdlib-common") { - version { - strictly("$kotlin_version") - } - } - implementation("org.jetbrains.kotlin:kotlin-reflect") { - version { - strictly("$kotlin_version") - } - } + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") + implementation("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version") testImplementation(project(":mockk-jvm")) testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") { exclude(group = "junit", module = "junit") } - testImplementation("org.slf4j:slf4j-api:1.7.32") - testImplementation("ch.qos.logback:logback-classic:1.2.9") + testImplementation("org.slf4j:slf4j-api:1.7.36") + testImplementation("ch.qos.logback:logback-classic:1.2.11") compileOnly("org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version") testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version") diff --git a/dsl/common/src/main/kotlin/io/mockk/InternalPlatformDsl.kt b/dsl/common/src/main/kotlin/io/mockk/InternalPlatformDsl.kt index c280a87cc..e55b0d14d 100644 --- a/dsl/common/src/main/kotlin/io/mockk/InternalPlatformDsl.kt +++ b/dsl/common/src/main/kotlin/io/mockk/InternalPlatformDsl.kt @@ -66,7 +66,6 @@ interface InternalRef { val value: T } - interface InternalCounter { val value: Long diff --git a/dsl/jvm/build.gradle.kts b/dsl/jvm/build.gradle.kts index e2496b9c1..f1a63b8e6 100644 --- a/dsl/jvm/build.gradle.kts +++ b/dsl/jvm/build.gradle.kts @@ -34,5 +34,3 @@ tasks { add("archives", sourcesJar) } } - - diff --git a/gradle.properties b/gradle.properties index f417ea718..cc19a5769 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,3 +9,4 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=768m # localrepo=build/mockk-repo localrepo=/Users/raibaz/.m2/repository kotlin.version=1.7.10 +android.useAndroidX=true diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle index bc38d4d7e..550eeb19b 100644 --- a/gradle/jacoco.gradle +++ b/gradle/jacoco.gradle @@ -1,7 +1,7 @@ apply plugin: 'jacoco' jacoco { - toolVersion = "0.8.7" + toolVersion = "0.8.8" } afterEvaluate { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a4..249e5832f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fcea..8049c684f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c78733..a69d9cb6c 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..53a6b238d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/mockk/android/build.gradle.kts b/mockk/android/build.gradle.kts index d5ade77fa..ea3b74985 100644 --- a/mockk/android/build.gradle.kts +++ b/mockk/android/build.gradle.kts @@ -27,9 +27,8 @@ android { } defaultConfig { - minSdk = 21 - targetSdk = 31 - versionName = "${project.version}" + minSdk = 26 + targetSdk = 32 testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments testInstrumentationRunnerArguments["notAnnotation"] = "io.mockk.test.SkipInstrumentedAndroidTest" @@ -57,7 +56,7 @@ dependencies { implementation(project(":mockk-agent-api")) testImplementation("junit:junit:4.13.1") - androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2") { + androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0") { exclude(group = "com.android.support", module = "support-annotations") } androidTestImplementation(Deps.Libs.kotlinReflect(kotlinVersion())) @@ -65,10 +64,9 @@ dependencies { androidTestImplementation(Deps.Libs.kotlinTestJunit()) { exclude(group = "junit", module = "junit") } - androidTestImplementation("com.android.support.test:rules:1.0.2") + androidTestImplementation("androidx.test:rules:1.4.0") androidTestImplementation(Deps.Libs.junitJupiterApi) androidTestImplementation(Deps.Libs.junitJupiterEngine) androidTestImplementation(Deps.Libs.junitVintageEngine) } - diff --git a/mockk/android/src/androidTest/java/io/mockk/proxy/android/AndroidMockKAgentFactoryTest.kt b/mockk/android/src/androidTest/java/io/mockk/proxy/android/AndroidMockKAgentFactoryTest.kt index 4030c7a7b..14ebcb9ef 100644 --- a/mockk/android/src/androidTest/java/io/mockk/proxy/android/AndroidMockKAgentFactoryTest.kt +++ b/mockk/android/src/androidTest/java/io/mockk/proxy/android/AndroidMockKAgentFactoryTest.kt @@ -1,7 +1,7 @@ package io.mockk.proxy.android -import android.support.test.rule.ActivityTestRule import android.widget.FrameLayout +import androidx.test.rule.ActivityTestRule import io.mockk.debug.TestActivity import io.mockk.mockk import org.junit.Rule diff --git a/mockk/common/src/main/kotlin/io/mockk/impl/recording/PermanentMocker.kt b/mockk/common/src/main/kotlin/io/mockk/impl/recording/PermanentMocker.kt index 0601f94d0..0203747cb 100644 --- a/mockk/common/src/main/kotlin/io/mockk/impl/recording/PermanentMocker.kt +++ b/mockk/common/src/main/kotlin/io/mockk/impl/recording/PermanentMocker.kt @@ -138,7 +138,7 @@ class PermanentMocker( args.isEmpty() ) { return prefix + - methodName[3].lowercase() + + methodName[3].lowercaseChar() + methodName.substring(4) } diff --git a/mockk/common/src/test/kotlin/io/mockk/impl/recording/states/VerifyingStateTest.kt b/mockk/common/src/test/kotlin/io/mockk/impl/recording/states/VerifyingStateTest.kt index 82beaf160..b730ee66e 100644 --- a/mockk/common/src/test/kotlin/io/mockk/impl/recording/states/VerifyingStateTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/impl/recording/states/VerifyingStateTest.kt @@ -5,6 +5,7 @@ import io.mockk.MockKGateway.* import io.mockk.impl.recording.CommonCallRecorder import io.mockk.impl.recording.VerificationCallSorter import kotlin.test.BeforeTest +import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertFailsWith @@ -60,7 +61,6 @@ class VerifyingStateTest { } } - @Test fun givenOneCalledMocksWhenRecordingDoneThrowsException() { setupCalls(VerificationResult.OK(listOf())) @@ -117,4 +117,4 @@ class VerifyingStateTest { } private fun allRecordedCalls(mock: Any) = recorder.stubRepo.stubFor(mock).allRecordedCalls() -} \ No newline at end of file +} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/PartialArgumentMatchingTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/PartialArgumentMatchingTest.kt index 77db3c47f..9788bc303 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/PartialArgumentMatchingTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/PartialArgumentMatchingTest.kt @@ -20,7 +20,7 @@ class PartialArgumentMatchingTest { s: IntWrapper = IntWrapper(16), t: IntWrapper = IntWrapper(17) ): Double { - return a.toInt() * -1 + b.toInt() * -2 + c + d + e + f + g.toByte() + h.toByte() + + return a.toInt() * -1 + b.toInt() * -2 + c + d + e + f + g.code.toByte() + h.code.toByte() + i + j + k + l + m + n + o + p + q.toInt() + r.toInt() + s.data + t.data } diff --git a/mockk/common/src/test/kotlin/io/mockk/it/ValueClassTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/ValueClassTest.kt index 826a0e7b1..b95d04231 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/ValueClassTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/ValueClassTest.kt @@ -1,9 +1,6 @@ package io.mockk.it -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import io.mockk.verify +import io.mockk.* import kotlin.jvm.JvmInline import kotlin.test.Ignore import kotlin.test.Test diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VarargsTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VarargsTest.kt index 43b7bba03..29679c7d3 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VarargsTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VarargsTest.kt @@ -901,7 +901,7 @@ class VarargsTest { fun intWrapperOp(a: Int, vararg b: IntWrapper, c: Int, d: Int = 6) = b.map { it.value }.sum() + a fun booleanOp(a: Int, vararg b: Boolean, c: Int, d: Int = 6) = b.map { if (it) 1 else 0 }.sum() + a fun byteOp(a: Int, vararg b: Byte, c: Int, d: Int = 6) = b.sum() + a - fun charOp(a: Int, vararg b: Char, c: Int, d: Int = 6) = b.map { it.toInt() }.sum() + a + fun charOp(a: Int, vararg b: Char, c: Int, d: Int = 6) = b.map { it.code }.sum() + a fun shortOp(a: Int, vararg b: Short, c: Int, d: Int = 6) = b.sum() + a fun intOp(a: Int, vararg b: Int, c: Int, d: Int = 6) = b.sum() + a fun longOp(a: Int, vararg b: Long, c: Int, d: Int = 6) = b.sum() + a diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VerificationErrorsTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VerificationErrorsTest.kt index 948e295d4..00af909e9 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VerificationErrorsTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VerificationErrorsTest.kt @@ -182,7 +182,7 @@ class VerificationErrorsTest { s: IntWrapper = IntWrapper(16), t: IntWrapper = IntWrapper(17) ): Double { - return (if (a) 0 else -1) + (if (b) 0 else -2) + c + d + e + f + g.toByte() + h.toByte() + + return (if (a) 0 else -1) + (if (b) 0 else -2) + c + d + e + f + g.code.toByte() + h.code.toByte() + i + j + k + l + m + n + o + p + q.toInt() + r.toInt() + s.data + t.data } } diff --git a/mockk/jvm/build.gradle.kts b/mockk/jvm/build.gradle.kts index cf0dc779a..672d6ef63 100644 --- a/mockk/jvm/build.gradle.kts +++ b/mockk/jvm/build.gradle.kts @@ -19,8 +19,8 @@ dependencies { implementation(Deps.Libs.kotlinReflect(kotlinVersion())) compileOnly(Deps.Libs.kotlinCoroutinesCore()) - compileOnly("org.slf4j:slf4j-api:1.7.26") - compileOnly("junit:junit:4.13.1") + compileOnly("org.slf4j:slf4j-api:1.7.36") + compileOnly("junit:junit:4.13.2") testImplementation(Deps.Libs.kotlinCoroutinesCore()) } @@ -40,4 +40,4 @@ tasks { base { archivesBaseName = "mockk" -} \ No newline at end of file +} diff --git a/mockk/jvm/src/test/kotlin/io/mockk/jvm/HashMapMockTest.kt b/mockk/jvm/src/test/kotlin/io/mockk/jvm/HashMapMockTest.kt index 041fa521a..e9fbd44b9 100644 --- a/mockk/jvm/src/test/kotlin/io/mockk/jvm/HashMapMockTest.kt +++ b/mockk/jvm/src/test/kotlin/io/mockk/jvm/HashMapMockTest.kt @@ -9,6 +9,8 @@ import kotlin.test.assertEquals import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.condition.DisabledForJreRange +import org.junit.jupiter.api.condition.JRE class HashMapMockTest { @@ -26,28 +28,29 @@ class HashMapMockTest { } @Test + @DisabledForJreRange(min = JRE.JAVA_17, disabledReason = "https://github.com/mockk/mockk/issues/864") fun canSpyAHashMap() { val map = spyk>() - assertDoesNotThrow { map["key"] = "value" } + assertDoesNotThrow { map["key"] = "value" } verify(exactly = 1) { map["key"] = "value" } } @Test - @Disabled("Does not work anymore with jdk 16+") + @DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "https://github.com/mockk/mockk/issues/864") fun concurrentHashMap_shouldBeSpied_Successfully() { val map = spyk(ConcurrentHashMap()) - assertDoesNotThrow { map.put("key", "value") } + assertDoesNotThrow { map.put("key", "value") } - verify(exactly = 1) { map.put("key", "value") } + verify(exactly = 1) { map["key"] = "value" } } @Test - @Disabled(value = "mocking of abstractMap don't work") + @Disabled(value = "mocking AbstractMap doesn't work https://github.com/mockk/mockk/issues/864") fun abstractMap_shouldBeMocked_SuccessFully() { val map = mockk>() - assertDoesNotThrow { map.get("key") } + assertDoesNotThrow { map["key"] } - verify(exactly = 1) { map.get("key") } + verify(exactly = 1) { map["key"] } } } diff --git a/plugins/configuration/build.gradle.kts b/plugins/configuration/build.gradle.kts index 7aab64880..1c46531c6 100644 --- a/plugins/configuration/build.gradle.kts +++ b/plugins/configuration/build.gradle.kts @@ -1,5 +1,6 @@ import io.mockk.dependencies.Deps import io.mockk.dependencies.kotlinVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `kotlin-dsl` @@ -44,3 +45,9 @@ gradlePlugin { } } } + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + } +} diff --git a/plugins/configuration/src/main/kotlin/io/mockk/configuration/CommonConfigurationPlugin.kt b/plugins/configuration/src/main/kotlin/io/mockk/configuration/CommonConfigurationPlugin.kt index 3eee0b873..9e00cbb86 100644 --- a/plugins/configuration/src/main/kotlin/io/mockk/configuration/CommonConfigurationPlugin.kt +++ b/plugins/configuration/src/main/kotlin/io/mockk/configuration/CommonConfigurationPlugin.kt @@ -17,6 +17,7 @@ class CommonConfigurationPlugin : Plugin { extensions.configure(KotlinCommonProjectExtension::class) { sourceSets["main"].dependencies { implementation(Deps.Libs.kotlinStdLib(kotlinVersion())) + implementation(Deps.Libs.kotlinReflect(kotlinVersion())) } sourceSets["test"].dependencies { implementation(Deps.Libs.kotlinTestCommon(kotlinVersion())) diff --git a/plugins/configuration/src/main/kotlin/io/mockk/configuration/JvmConfigurationPlugin.kt b/plugins/configuration/src/main/kotlin/io/mockk/configuration/JvmConfigurationPlugin.kt index 4bdf6b2c9..efe064fb5 100644 --- a/plugins/configuration/src/main/kotlin/io/mockk/configuration/JvmConfigurationPlugin.kt +++ b/plugins/configuration/src/main/kotlin/io/mockk/configuration/JvmConfigurationPlugin.kt @@ -35,6 +35,7 @@ class JvmConfigurationPlugin : Plugin { extensions.configure(KotlinJvmProjectExtension::class) { sourceSets["main"].dependencies { implementation(Deps.Libs.kotlinStdLib(kotlinVersion())) + implementation(Deps.Libs.kotlinReflect(kotlinVersion())) compileOnly(Deps.Libs.junitJupiterApi) } sourceSets["test"].dependencies { diff --git a/plugins/dependencies/build.gradle.kts b/plugins/dependencies/build.gradle.kts index bc96f092b..6c55d9606 100644 --- a/plugins/dependencies/build.gradle.kts +++ b/plugins/dependencies/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { `kotlin-dsl` `java-gradle-plugin` @@ -18,3 +20,9 @@ gradlePlugin { implementationClass = "io.mockk.dependencies.DependenciesPlugin" } } + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + } +} diff --git a/plugins/dependencies/src/main/kotlin/io/mockk/dependencies/Deps.kt b/plugins/dependencies/src/main/kotlin/io/mockk/dependencies/Deps.kt index 49f06d83d..bc78710ea 100644 --- a/plugins/dependencies/src/main/kotlin/io/mockk/dependencies/Deps.kt +++ b/plugins/dependencies/src/main/kotlin/io/mockk/dependencies/Deps.kt @@ -6,12 +6,12 @@ fun Project.kotlinVersion() = findProperty("kotlin.version")?.toString() ?: Deps object Deps { object Versions { - const val androidTools = "4.1.1" - const val dokka = "1.6.0" + const val androidTools = "7.2.1" + const val dokka = "1.7.10" const val kotlinDefault = "1.7.10" - const val coroutines = "1.3.3" + const val coroutines = "1.6.4" const val slfj = "1.7.32" - const val logback = "1.2.10" + const val logback = "1.2.11" const val junitJupiter = "5.8.2" const val junitVintage = "5.8.2" } @@ -26,8 +26,7 @@ object Deps { fun kotlinStdLib(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-stdlib:$version" fun kotlinStdLibJs(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-stdlib-js:$version" fun kotlinTestCommon(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-test-common:$version" - fun kotlinTestCommonAnnotations(version: String = Versions.kotlinDefault) = - "org.jetbrains.kotlin:kotlin-test-annotations-common:$version" + fun kotlinTestCommonAnnotations(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-test-annotations-common:$version" fun kotlinTestJunit(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-test-junit:$version" fun kotlinTestJs(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-test-js:$version" fun kotlinReflect(version: String = Versions.kotlinDefault) = "org.jetbrains.kotlin:kotlin-reflect:$version"