Skip to content

Commit

Permalink
Merge pull request #144 from nhaarman/release-1.1.0
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
nhaarman committed Dec 27, 2016
2 parents 327d431 + 9f827eb commit 3dbe0d0
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ language: java
matrix:
include:
- jdk: oraclejdk7
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5-2
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.6
- jdk: oraclejdk7
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M03
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M04
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.0.5-2
env: TERM=dumb KOTLIN_VERSION=1.0.6
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.1-M03
env: TERM=dumb KOTLIN_VERSION=1.1-M04


env:
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
6 changes: 3 additions & 3 deletions mockito-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: './publishing.gradle'
apply plugin: 'org.jetbrains.dokka'

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

repositories {
mavenCentral()
Expand All @@ -13,7 +13,7 @@ buildscript {

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.10"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.11"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
}
Expand All @@ -28,7 +28,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.2.28"
compile "org.mockito:mockito-core:2.4.5"

/* Tests */
testCompile "junit:junit:4.12"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nhaarman.mockito_kotlin

import org.mockito.BDDMockito

fun <T> given(methodCall: T): BDDMockito.BDDMyOngoingStubbing<T> = BDDMockito.given(methodCall)
fun <T> given(methodCall: () -> T) = given(methodCall())

fun <T> then(mock: T): BDDMockito.Then<T> = BDDMockito.then(mock)

infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willAnswer { value() }
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willReturn(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willReturn(value())
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(value: () -> Throwable): BDDMockito.BDDMyOngoingStubbing<T> = willThrow(value())

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mock
*/
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)

/**
* Creates a custom argument matcher.
* `null` values will never evaluate to `true`.
*
* @param predicate A function that returns `true` when given [T] matches the predicate.
*/
inline fun <reified T: Any> argWhere(noinline predicate: (T) -> Boolean) = argThat(predicate)

/**
* For usage with verification only.
*
Expand Down
103 changes: 103 additions & 0 deletions mockito-kotlin/src/test/kotlin/test/BDDMockitoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package test

import com.nhaarman.expect.expect
import com.nhaarman.mockito_kotlin.*
import org.junit.Test

class BDDMockitoTest {

@Test
fun given_willReturn_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult()).willReturn("Test")

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test
fun givenLambda_willReturn_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given { mock.stringResult() }.willReturn("Test")

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test
fun given_willReturnLambda_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult()).willReturn { "Test" }

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test
fun givenLambda_willReturnLambda_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given { mock.stringResult() } willReturn { "Test" }

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test
fun given_willAnswer_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult()).willAnswer { "Test" }

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test
fun given_willAnswerInfix_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult()) willAnswer { "Test" }

/* Then */
expect(mock.stringResult()).toBe("Test")
}

@Test(expected = IllegalStateException::class)
fun given_willThrowInfix_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult()) willThrow { IllegalStateException() }
mock.stringResult()
}

@Test
fun then() {
/* Given */
val mock = mock<Methods>()
whenever(mock.stringResult()).thenReturn("Test")

/* When */
mock.stringResult()

/* Then */
then(mock).should().stringResult()
}
}
10 changes: 10 additions & 0 deletions mockito-kotlin/src/test/kotlin/test/MockitoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ class MockitoTest : TestBase() {
}
}

@Test
fun listArgWhere() {
mock<Methods>().apply {
closedList(listOf(Closed(), Closed()))
verify(this).closedList(argWhere {
it.size == 2
})
}
}

@Test
fun listArgCheck() {
mock<Methods>().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import com.nhaarman.expect.expect
import com.nhaarman.expect.expectErrorWithMessage
import com.nhaarman.mockito_kotlin.*
import com.nhaarman.mockito_kotlin.createinstance.InstanceCreator
import com.nhaarman.mockito_kotlin.createinstance.mockMakerInlineEnabled
Expand Down Expand Up @@ -129,13 +128,12 @@ class UsingMockMakerInlineTest {
}

@Test
fun sealedClass_fails() {
/* Expect */
expectErrorWithMessage("Could not create") on {
fun sealedMemberClass() {
/* When */
val result = createInstance<MySealedClass>()

/* When */
createInstance<MySealedClass>()
}
/* Then */
expect(result).toNotBeNull()
}

@Test
Expand Down
Loading

0 comments on commit 3dbe0d0

Please sign in to comment.