Skip to content

Commit

Permalink
Merge pull request #121 from nhaarman/release-0.12.0
Browse files Browse the repository at this point in the history
Release 0.12.0
  • Loading branch information
nhaarman committed Nov 12, 2016
2 parents 27c6bf6 + 66d8249 commit ebc6147
Show file tree
Hide file tree
Showing 25 changed files with 638 additions and 353 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ sudo: false

language: java

jdk:
- oraclejdk7
matrix:
include:
- jdk: oraclejdk7
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5
- jdk: oraclejdk7
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M02
- jdk: oraclejdk8
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5
- jdk: oraclejdk8
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M02


env:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ plugins {
}

apply from: 'gradle/scripts/tagging.gradle'

println ext.versionName
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
#

isRelease = false
publishToLocal = false
50 changes: 27 additions & 23 deletions mockito-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ apply from: './publishing.gradle'
apply plugin: 'org.jetbrains.dokka'

buildscript {
ext.kotlin_version = '1.0.4'
ext.kotlin_version = System.getenv("KOTLIN_VERSION") ?: '1.0.5'

repositories {
mavenCentral()
jcenter()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' }
}

dependencies {
Expand All @@ -19,33 +20,13 @@ buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' }
}

sourceSets {
testInlineMockito {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}

configurations {
testInlineMockitoCompile.extendsFrom testCompile
testInlineMockitoRuntime.extendsFrom testRuntime
}

// define custom test task for running integration tests
task testInlineMockito(type: Test) {
testClassesDir = sourceSets.testInlineMockito.output.classesDir
classpath = sourceSets.testInlineMockito.runtimeClasspath
}

test.dependsOn testInlineMockito


dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.mockito:mockito-core:2.2.9"
compile "org.mockito:mockito-core:2.2.15"

/* Tests */
testCompile "junit:junit:4.12"
Expand All @@ -63,3 +44,26 @@ dokka {
}
}
javadoc.dependsOn dokka

//Switch inline
task createTestResources << {
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
if (System.env.MOCK_MAKER != null) {
logger.warn("! Using MockMaker ${System.env.MOCK_MAKER}")
mockMakerFile.parentFile.mkdirs()
mockMakerFile.createNewFile()
mockMakerFile.write(System.env.MOCK_MAKER)
} else {
logger.warn("! Using default MockMaker")
}
}

task removeTestResources << {
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
if (mockMakerFile.exists()) {
mockMakerFile.delete()
}
}

test.dependsOn createTestResources
test.finalizedBy removeTestResources
2 changes: 2 additions & 0 deletions mockito-kotlin/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ uploadArchives {
)
}

if (publishToLocal) repository(url: mavenLocal().url)

pom.project {
name 'Mockito-Kotlin'
packaging 'jar'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.nhaarman.mockito_kotlin

import com.nhaarman.mockito_kotlin.createinstance.createInstance
import org.mockito.ArgumentCaptor
import kotlin.reflect.KClass

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

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

@Deprecated("Use captor.capture() instead.", ReplaceWith("captor.capture()"), DeprecationLevel.ERROR)
inline fun <reified T : Any> capture(captor: KArgumentCaptor<T>): T = captor.capture()

class KArgumentCaptor<out T : Any?>(private val captor: ArgumentCaptor<T>, private val tClass: KClass<*>) {

@Deprecated("Use lastValue", ReplaceWith("lastValue"))
val value: T
get() = captor.value

/**
* The first captured value of the argument.
* @throws IndexOutOfBoundsException if the value is not available.
*/
val firstValue: T
get() = captor.firstValue

/**
* The second captured value of the argument.
* @throws IndexOutOfBoundsException if the value is not available.
*/
val secondValue: T
get() = captor.secondValue

/**
* The third captured value of the argument.
* @throws IndexOutOfBoundsException if the value is not available.
*/
val thirdValue: T
get() = captor.thirdValue

/**
* The last captured value of the argument.
* @throws IndexOutOfBoundsException if the value is not available.
*/
val lastValue: T
get() = captor.lastValue

val allValues: List<T>
get() = captor.allValues

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

val <T> ArgumentCaptor<T>.firstValue: T
get() = allValues[0]

val <T> ArgumentCaptor<T>.secondValue: T
get() = allValues[1]

val <T> ArgumentCaptor<T>.thirdValue: T
get() = allValues[2]

val <T> ArgumentCaptor<T>.lastValue: T
get() = allValues.last()

/**
* This method is deprecated because its behavior differs from the Java behavior.
* Instead, use [argumentCaptor] in the traditional way, or use one of
Expand All @@ -58,3 +97,7 @@ inline fun <reified T : Any> capture(noinline consumer: (T) -> Unit): T {
var times = 0
return argThat { if (++times == 1) consumer.invoke(this); true }
}

@Deprecated("Use captor.capture() instead.", ReplaceWith("captor.capture()"), DeprecationLevel.ERROR)
inline fun <reified T : Any> capture(captor: KArgumentCaptor<T>): T = captor.capture()

Loading

0 comments on commit ebc6147

Please sign in to comment.