From 76872e8807b4207d29036af2eeef615fbb2b336e Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 15:02:03 +0200 Subject: [PATCH 1/7] Make `same` return non-null type --- .../com/nhaarman/mockito_kotlin/Mockito.kt | 2 +- .../src/test/kotlin/test/MockitoTest.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt index 6d62267c..e53e9939 100644 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt @@ -236,7 +236,7 @@ fun refEq(value: T, vararg excludeFields: String): T? = Mockito.refEq(value, fun reset(vararg mocks: T) = Mockito.reset(*mocks) -fun same(value: T): T? = Mockito.same(value) ?: value +fun same(value: T): T = Mockito.same(value) ?: value inline fun spy(): T = Mockito.spy(T::class.java)!! fun spy(value: T): T = Mockito.spy(value)!! diff --git a/mockito-kotlin/src/test/kotlin/test/MockitoTest.kt b/mockito-kotlin/src/test/kotlin/test/MockitoTest.kt index d5055a74..c897c93f 100644 --- a/mockito-kotlin/src/test/kotlin/test/MockitoTest.kt +++ b/mockito-kotlin/src/test/kotlin/test/MockitoTest.kt @@ -983,4 +983,28 @@ class MockitoTest : TestBase() { verify(this).nullableString(isA()) } } + + @Test + fun same_withNonNullArgument() { + mock().apply { + string("") + verify(this).string(same("")) + } + } + + @Test + fun same_withNullableNonNullArgument() { + mock().apply { + nullableString("") + verify(this).nullableString(same("")) + } + } + + @Test + fun same_withNullArgument() { + mock().apply { + nullableString(null) + verify(this).nullableString(same(null)) + } + } } \ No newline at end of file From 6c29db1e6b35708648482ec727a40504e1879657 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 15:34:29 +0200 Subject: [PATCH 2/7] Update Kotlin test version to 1.1.2-4 --- .travis.yml | 4 ++-- mockito-kotlin/build.gradle | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b42990a1..1b5ebbcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,11 @@ matrix: - jdk: oraclejdk7 env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.7 - jdk: oraclejdk7 - env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.1 + env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.2-4 - jdk: oraclejdk8 env: TERM=dumb KOTLIN_VERSION=1.0.7 - jdk: oraclejdk8 - env: TERM=dumb KOTLIN_VERSION=1.1.1 + env: TERM=dumb KOTLIN_VERSION=1.1.2-4 env: diff --git a/mockito-kotlin/build.gradle b/mockito-kotlin/build.gradle index a9e473da..c0dc9c3f 100644 --- a/mockito-kotlin/build.gradle +++ b/mockito-kotlin/build.gradle @@ -8,7 +8,6 @@ buildscript { repositories { mavenCentral() jcenter() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' } } dependencies { @@ -22,7 +21,6 @@ buildscript { repositories { mavenCentral() jcenter() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' } } dependencies { From 1251c2d0d1e98b9560e6c505ac2ce570bae11b2e Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 15:35:21 +0200 Subject: [PATCH 3/7] Update Mockito to 2.8.9 --- mockito-kotlin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockito-kotlin/build.gradle b/mockito-kotlin/build.gradle index c0dc9c3f..f404a435 100644 --- a/mockito-kotlin/build.gradle +++ b/mockito-kotlin/build.gradle @@ -26,7 +26,7 @@ repositories { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - compile "org.mockito:mockito-core:2.7.21" + compile "org.mockito:mockito-core:2.8.9" /* Tests */ testCompile "junit:junit:4.12" From d9aca8c3d29e0a839ed6d5057e8f7b3410370981 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 15:35:42 +0200 Subject: [PATCH 4/7] Update Dokka gradle plugin to 0.9.14 --- mockito-kotlin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockito-kotlin/build.gradle b/mockito-kotlin/build.gradle index f404a435..0ddd6e2c 100644 --- a/mockito-kotlin/build.gradle +++ b/mockito-kotlin/build.gradle @@ -12,7 +12,7 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.13" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.14" classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3" classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" } From 0824392614eacc71942b8156038a1a5c2999285d Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 15:36:02 +0200 Subject: [PATCH 5/7] Update Gradle versions plugin to 0.15.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f4da8369..92ed15c3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.ben-manes.versions' version '0.14.0' + id 'com.github.ben-manes.versions' version '0.15.0' } apply from: 'gradle/scripts/tagging.gradle' From 5246ea78037a025f5ea35d574811def0d14f02a1 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 16:04:09 +0200 Subject: [PATCH 6/7] Update Travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1b5ebbcd..d590b983 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ language: java matrix: include: - - jdk: oraclejdk7 + - jdk: oraclejdk8 env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.7 - - jdk: oraclejdk7 + - jdk: oraclejdk8 env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.2-4 - jdk: oraclejdk8 env: TERM=dumb KOTLIN_VERSION=1.0.7 From c34b487609d62b243ae26c1682302b0ff22c83f9 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sat, 3 Jun 2017 16:25:02 +0200 Subject: [PATCH 7/7] Create module to release a kt1.1 artifact --- README.md | 6 +++ mockito-kotlin-kt1.1/build.gradle | 42 +++++++++++++++++++ mockito-kotlin/build.gradle | 2 +- .../publishing.gradle => publishing.gradle | 0 settings.gradle | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 mockito-kotlin-kt1.1/build.gradle rename mockito-kotlin/publishing.gradle => publishing.gradle (100%) diff --git a/README.md b/README.md index 5a424b45..4d4096a3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ For Gradle users, add the following to your `build.gradle`, replacing `x.x.x` wi testCompile "com.nhaarman:mockito-kotlin:x.x.x" ``` +If you use Kotlin 1.1, you can instead depend on the `mockito-kotlin-kt1.1` artifact. + +```groovy +testCompile "com.nhaarman:mockito-kotlin-kt1.1:x.x.x" +``` + ## Example A test using Mockito-Kotlin typically looks like the following: diff --git a/mockito-kotlin-kt1.1/build.gradle b/mockito-kotlin-kt1.1/build.gradle new file mode 100644 index 00000000..e3851d88 --- /dev/null +++ b/mockito-kotlin-kt1.1/build.gradle @@ -0,0 +1,42 @@ +apply plugin: 'kotlin' +apply from: '../publishing.gradle' +apply plugin: 'org.jetbrains.dokka' + +buildscript { + ext.kotlin_version = '1.1.2-4' + + repositories { + mavenCentral() + jcenter() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.14" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3" + classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" + } +} + +repositories { + mavenCentral() + jcenter() +} + +dependencies { + compile project(':mockito-kotlin') + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" +} + +dokka { + outputFormat = 'html' + outputDirectory = "$buildDir/javadoc" + + linkMapping { + dir = "src/main/kotlin" + url = "https://github.com/nhaarman/mockito-kotlin/tree/master/mockito-kotlin/src/main/kotlin" + suffix = "#L" + } +} +javadoc.dependsOn dokka \ No newline at end of file diff --git a/mockito-kotlin/build.gradle b/mockito-kotlin/build.gradle index 0ddd6e2c..d9da782e 100644 --- a/mockito-kotlin/build.gradle +++ b/mockito-kotlin/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'kotlin' -apply from: './publishing.gradle' +apply from: '../publishing.gradle' apply plugin: 'org.jetbrains.dokka' buildscript { diff --git a/mockito-kotlin/publishing.gradle b/publishing.gradle similarity index 100% rename from mockito-kotlin/publishing.gradle rename to publishing.gradle diff --git a/settings.gradle b/settings.gradle index 3e1090c6..23d28d1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ include 'mockito-kotlin' - +include 'mockito-kotlin-kt1.1'