File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ language: java
5
5
matrix :
6
6
include :
7
7
- jdk : oraclejdk7
8
- env : TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.6
8
+ env : TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.0.7
9
9
- jdk : oraclejdk7
10
- env : TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.0-beta-38
10
+ env : TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.1
11
11
- jdk : oraclejdk8
12
- env : TERM=dumb KOTLIN_VERSION=1.0.6
12
+ env : TERM=dumb KOTLIN_VERSION=1.0.7
13
13
- jdk : oraclejdk8
14
- env : TERM=dumb KOTLIN_VERSION=1.1.0-beta-38
14
+ env : TERM=dumb KOTLIN_VERSION=1.1.1
15
15
16
16
17
17
env :
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ apply from: './publishing.gradle'
3
3
apply plugin : ' org.jetbrains.dokka'
4
4
5
5
buildscript {
6
- ext. kotlin_version = System . getenv(" KOTLIN_VERSION" ) ?: ' 1.0.6 '
6
+ ext. kotlin_version = System . getenv(" KOTLIN_VERSION" ) ?: ' 1.0.7 '
7
7
8
8
repositories {
9
9
mavenCentral()
@@ -28,7 +28,7 @@ repositories {
28
28
dependencies {
29
29
compile " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
30
30
compile " org.jetbrains.kotlin:kotlin-reflect:$kotlin_version "
31
- compile " org.mockito:mockito-core:2.7.5 "
31
+ compile " org.mockito:mockito-core:2.7.21 "
32
32
33
33
/* Tests */
34
34
testCompile " junit:junit:4.12"
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ inline fun <reified T : Any> mock(
175
175
KStubbing (this ).stubbing(this )
176
176
}!!
177
177
178
+ inline fun <T : Any > T.stub (stubbing : KStubbing <T >.(T ) -> Unit ) = this .apply { KStubbing (this ).stubbing(this ) }
179
+
178
180
@Deprecated(" Use mock() with optional arguments instead." , ReplaceWith (" mock<T>(defaultAnswer = a)" ), level = WARNING )
179
181
inline fun <reified T : Any > mock (a : Answer <Any >): T = mock(defaultAnswer = a)
180
182
Original file line number Diff line number Diff line change @@ -516,6 +516,41 @@ class MockitoTest : TestBase() {
516
516
expect(result).toBe(" argument-result" )
517
517
}
518
518
519
+ @Test
520
+ fun testMockStubbingAfterCreatingMock () {
521
+ val mock = mock<Methods >()
522
+
523
+ // create stub after creation of mock
524
+ mock.stub {
525
+ on { stringResult() } doReturn " result"
526
+ }
527
+
528
+ /* When */
529
+ val result = mock.stringResult()
530
+
531
+ /* Then */
532
+ expect(result).toBe(" result" )
533
+ }
534
+
535
+ @Test
536
+ fun testOverrideDefaultStub () {
537
+ /* Given mock with stub */
538
+ val mock = mock<Methods > {
539
+ on { stringResult() } doReturn " result1"
540
+ }
541
+
542
+ /* override stub */
543
+ mock.stub {
544
+ on { stringResult() } doReturn " result2"
545
+ }
546
+
547
+ /* When */
548
+ val result = mock.stringResult()
549
+
550
+ /* Then */
551
+ expect(result).toBe(" result2" )
552
+ }
553
+
519
554
@Test
520
555
fun mock_withCustomName () {
521
556
/* Given */
You can’t perform that action at this time.
0 commit comments