Skip to content

Commit 3dbe0d0

Browse files
authored
Merge pull request #144 from nhaarman/release-1.1.0
Release 1.1.0
2 parents 327d431 + 9f827eb commit 3dbe0d0

File tree

9 files changed

+328
-15
lines changed

9 files changed

+328
-15
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ language: java
55
matrix:
66
include:
77
- jdk: oraclejdk7
8-
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.5-2
8+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.6
99
- jdk: oraclejdk7
10-
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M03
10+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1-M04
1111
- jdk: oraclejdk8
12-
env: TERM=dumb KOTLIN_VERSION=1.0.5-2
12+
env: TERM=dumb KOTLIN_VERSION=1.0.6
1313
- jdk: oraclejdk8
14-
env: TERM=dumb KOTLIN_VERSION=1.1-M03
14+
env: TERM=dumb KOTLIN_VERSION=1.1-M04
1515

1616

1717
env:

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip

mockito-kotlin/build.gradle

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

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

88
repositories {
99
mavenCentral()
@@ -13,7 +13,7 @@ buildscript {
1313

1414
dependencies {
1515
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16-
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.10"
16+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.11"
1717
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
1818
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
1919
}
@@ -28,7 +28,7 @@ repositories {
2828
dependencies {
2929
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3030
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
31-
compile "org.mockito:mockito-core:2.2.28"
31+
compile "org.mockito:mockito-core:2.4.5"
3232

3333
/* Tests */
3434
testCompile "junit:junit:4.12"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.nhaarman.mockito_kotlin
2+
3+
import org.mockito.BDDMockito
4+
5+
fun <T> given(methodCall: T): BDDMockito.BDDMyOngoingStubbing<T> = BDDMockito.given(methodCall)
6+
fun <T> given(methodCall: () -> T) = given(methodCall())
7+
8+
fun <T> then(mock: T): BDDMockito.Then<T> = BDDMockito.then(mock)
9+
10+
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willAnswer { value() }
11+
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willReturn(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willReturn(value())
12+
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(value: () -> Throwable): BDDMockito.BDDMyOngoingStubbing<T> = willThrow(value())
13+

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

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mock
6868
*/
6969
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)
7070

71+
/**
72+
* Creates a custom argument matcher.
73+
* `null` values will never evaluate to `true`.
74+
*
75+
* @param predicate A function that returns `true` when given [T] matches the predicate.
76+
*/
77+
inline fun <reified T: Any> argWhere(noinline predicate: (T) -> Boolean) = argThat(predicate)
78+
7179
/**
7280
* For usage with verification only.
7381
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package test
2+
3+
import com.nhaarman.expect.expect
4+
import com.nhaarman.mockito_kotlin.*
5+
import org.junit.Test
6+
7+
class BDDMockitoTest {
8+
9+
@Test
10+
fun given_willReturn_properlyStubs() {
11+
/* Given */
12+
val mock = mock<Methods>()
13+
14+
/* When */
15+
given(mock.stringResult()).willReturn("Test")
16+
17+
/* Then */
18+
expect(mock.stringResult()).toBe("Test")
19+
}
20+
21+
@Test
22+
fun givenLambda_willReturn_properlyStubs() {
23+
/* Given */
24+
val mock = mock<Methods>()
25+
26+
/* When */
27+
given { mock.stringResult() }.willReturn("Test")
28+
29+
/* Then */
30+
expect(mock.stringResult()).toBe("Test")
31+
}
32+
33+
@Test
34+
fun given_willReturnLambda_properlyStubs() {
35+
/* Given */
36+
val mock = mock<Methods>()
37+
38+
/* When */
39+
given(mock.stringResult()).willReturn { "Test" }
40+
41+
/* Then */
42+
expect(mock.stringResult()).toBe("Test")
43+
}
44+
45+
@Test
46+
fun givenLambda_willReturnLambda_properlyStubs() {
47+
/* Given */
48+
val mock = mock<Methods>()
49+
50+
/* When */
51+
given { mock.stringResult() } willReturn { "Test" }
52+
53+
/* Then */
54+
expect(mock.stringResult()).toBe("Test")
55+
}
56+
57+
@Test
58+
fun given_willAnswer_properlyStubs() {
59+
/* Given */
60+
val mock = mock<Methods>()
61+
62+
/* When */
63+
given(mock.stringResult()).willAnswer { "Test" }
64+
65+
/* Then */
66+
expect(mock.stringResult()).toBe("Test")
67+
}
68+
69+
@Test
70+
fun given_willAnswerInfix_properlyStubs() {
71+
/* Given */
72+
val mock = mock<Methods>()
73+
74+
/* When */
75+
given(mock.stringResult()) willAnswer { "Test" }
76+
77+
/* Then */
78+
expect(mock.stringResult()).toBe("Test")
79+
}
80+
81+
@Test(expected = IllegalStateException::class)
82+
fun given_willThrowInfix_properlyStubs() {
83+
/* Given */
84+
val mock = mock<Methods>()
85+
86+
/* When */
87+
given(mock.stringResult()) willThrow { IllegalStateException() }
88+
mock.stringResult()
89+
}
90+
91+
@Test
92+
fun then() {
93+
/* Given */
94+
val mock = mock<Methods>()
95+
whenever(mock.stringResult()).thenReturn("Test")
96+
97+
/* When */
98+
mock.stringResult()
99+
100+
/* Then */
101+
then(mock).should().stringResult()
102+
}
103+
}

mockito-kotlin/src/test/kotlin/test/MockitoTest.kt

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ class MockitoTest : TestBase() {
128128
}
129129
}
130130

131+
@Test
132+
fun listArgWhere() {
133+
mock<Methods>().apply {
134+
closedList(listOf(Closed(), Closed()))
135+
verify(this).closedList(argWhere {
136+
it.size == 2
137+
})
138+
}
139+
}
140+
131141
@Test
132142
fun listArgCheck() {
133143
mock<Methods>().apply {

mockito-kotlin/src/test/kotlin/test/inline/UsingMockMakerInlineTest.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
import com.nhaarman.expect.expect
26-
import com.nhaarman.expect.expectErrorWithMessage
2726
import com.nhaarman.mockito_kotlin.*
2827
import com.nhaarman.mockito_kotlin.createinstance.InstanceCreator
2928
import com.nhaarman.mockito_kotlin.createinstance.mockMakerInlineEnabled
@@ -129,13 +128,12 @@ class UsingMockMakerInlineTest {
129128
}
130129

131130
@Test
132-
fun sealedClass_fails() {
133-
/* Expect */
134-
expectErrorWithMessage("Could not create") on {
131+
fun sealedMemberClass() {
132+
/* When */
133+
val result = createInstance<MySealedClass>()
135134

136-
/* When */
137-
createInstance<MySealedClass>()
138-
}
135+
/* Then */
136+
expect(result).toNotBeNull()
139137
}
140138

141139
@Test

0 commit comments

Comments
 (0)