Skip to content

Commit ebc6147

Browse files
authored
Merge pull request #121 from nhaarman/release-0.12.0
Release 0.12.0
2 parents 27c6bf6 + 66d8249 commit ebc6147

25 files changed

+638
-353
lines changed

.travis.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ sudo: false
22

33
language: java
44

5-
jdk:
6-
- oraclejdk7
5+
matrix:
6+
include:
7+
- jdk: oraclejdk7
8+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5
9+
- jdk: oraclejdk7
10+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M02
11+
- jdk: oraclejdk8
12+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5
13+
- jdk: oraclejdk8
14+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M02
15+
716

817
env:
918
matrix:

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ plugins {
33
}
44

55
apply from: 'gradle/scripts/tagging.gradle'
6+
7+
println ext.versionName

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
#
2525

2626
isRelease = false
27+
publishToLocal = false

mockito-kotlin/build.gradle

+27-23
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ apply from: './publishing.gradle'
33
apply plugin: 'org.jetbrains.dokka'
44

55
buildscript {
6-
ext.kotlin_version = '1.0.4'
6+
ext.kotlin_version = System.getenv("KOTLIN_VERSION") ?: '1.0.5'
77

88
repositories {
99
mavenCentral()
1010
jcenter()
11+
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' }
1112
}
1213

1314
dependencies {
@@ -19,33 +20,13 @@ buildscript {
1920
repositories {
2021
mavenCentral()
2122
jcenter()
23+
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' }
2224
}
2325

24-
sourceSets {
25-
testInlineMockito {
26-
compileClasspath += main.output + test.output
27-
runtimeClasspath += main.output + test.output
28-
}
29-
}
30-
31-
configurations {
32-
testInlineMockitoCompile.extendsFrom testCompile
33-
testInlineMockitoRuntime.extendsFrom testRuntime
34-
}
35-
36-
// define custom test task for running integration tests
37-
task testInlineMockito(type: Test) {
38-
testClassesDir = sourceSets.testInlineMockito.output.classesDir
39-
classpath = sourceSets.testInlineMockito.runtimeClasspath
40-
}
41-
42-
test.dependsOn testInlineMockito
43-
44-
4526
dependencies {
4627
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4728
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
48-
compile "org.mockito:mockito-core:2.2.9"
29+
compile "org.mockito:mockito-core:2.2.15"
4930

5031
/* Tests */
5132
testCompile "junit:junit:4.12"
@@ -63,3 +44,26 @@ dokka {
6344
}
6445
}
6546
javadoc.dependsOn dokka
47+
48+
//Switch inline
49+
task createTestResources << {
50+
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
51+
if (System.env.MOCK_MAKER != null) {
52+
logger.warn("! Using MockMaker ${System.env.MOCK_MAKER}")
53+
mockMakerFile.parentFile.mkdirs()
54+
mockMakerFile.createNewFile()
55+
mockMakerFile.write(System.env.MOCK_MAKER)
56+
} else {
57+
logger.warn("! Using default MockMaker")
58+
}
59+
}
60+
61+
task removeTestResources << {
62+
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
63+
if (mockMakerFile.exists()) {
64+
mockMakerFile.delete()
65+
}
66+
}
67+
68+
test.dependsOn createTestResources
69+
test.finalizedBy removeTestResources

mockito-kotlin/publishing.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ uploadArchives {
4040
)
4141
}
4242

43+
if (publishToLocal) repository(url: mavenLocal().url)
44+
4345
pom.project {
4446
name 'Mockito-Kotlin'
4547
packaging 'jar'

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/ArgumentCaptor.kt

+46-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package com.nhaarman.mockito_kotlin
2727

28+
import com.nhaarman.mockito_kotlin.createinstance.createInstance
2829
import org.mockito.ArgumentCaptor
2930
import kotlin.reflect.KClass
3031

@@ -33,21 +34,59 @@ inline fun <reified T : Any> nullableArgumentCaptor(): KArgumentCaptor<T?> = KAr
3334

3435
inline fun <reified T : Any> capture(captor: ArgumentCaptor<T>): T = captor.capture() ?: createInstance<T>()
3536

36-
@Deprecated("Use captor.capture() instead.", ReplaceWith("captor.capture()"), DeprecationLevel.ERROR)
37-
inline fun <reified T : Any> capture(captor: KArgumentCaptor<T>): T = captor.capture()
38-
3937
class KArgumentCaptor<out T : Any?>(private val captor: ArgumentCaptor<T>, private val tClass: KClass<*>) {
4038

39+
@Deprecated("Use lastValue", ReplaceWith("lastValue"))
4140
val value: T
4241
get() = captor.value
4342

43+
/**
44+
* The first captured value of the argument.
45+
* @throws IndexOutOfBoundsException if the value is not available.
46+
*/
47+
val firstValue: T
48+
get() = captor.firstValue
49+
50+
/**
51+
* The second captured value of the argument.
52+
* @throws IndexOutOfBoundsException if the value is not available.
53+
*/
54+
val secondValue: T
55+
get() = captor.secondValue
56+
57+
/**
58+
* The third captured value of the argument.
59+
* @throws IndexOutOfBoundsException if the value is not available.
60+
*/
61+
val thirdValue: T
62+
get() = captor.thirdValue
63+
64+
/**
65+
* The last captured value of the argument.
66+
* @throws IndexOutOfBoundsException if the value is not available.
67+
*/
68+
val lastValue: T
69+
get() = captor.lastValue
70+
4471
val allValues: List<T>
4572
get() = captor.allValues
4673

4774
@Suppress("UNCHECKED_CAST")
4875
fun capture(): T = captor.capture() ?: createInstance(tClass) as T
4976
}
5077

78+
val <T> ArgumentCaptor<T>.firstValue: T
79+
get() = allValues[0]
80+
81+
val <T> ArgumentCaptor<T>.secondValue: T
82+
get() = allValues[1]
83+
84+
val <T> ArgumentCaptor<T>.thirdValue: T
85+
get() = allValues[2]
86+
87+
val <T> ArgumentCaptor<T>.lastValue: T
88+
get() = allValues.last()
89+
5190
/**
5291
* This method is deprecated because its behavior differs from the Java behavior.
5392
* Instead, use [argumentCaptor] in the traditional way, or use one of
@@ -58,3 +97,7 @@ inline fun <reified T : Any> capture(noinline consumer: (T) -> Unit): T {
5897
var times = 0
5998
return argThat { if (++times == 1) consumer.invoke(this); true }
6099
}
100+
101+
@Deprecated("Use captor.capture() instead.", ReplaceWith("captor.capture()"), DeprecationLevel.ERROR)
102+
inline fun <reified T : Any> capture(captor: KArgumentCaptor<T>): T = captor.capture()
103+

0 commit comments

Comments
 (0)