diff --git a/tests/build.gradle b/tests/build.gradle index 4137013..dd447d9 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -19,6 +19,7 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation "com.nhaarman:expect.kt:1.0.1" + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0-RC" } tasks.withType(KotlinCompile).configureEach { diff --git a/tests/src/test/kotlin/test/Classes.kt b/tests/src/test/kotlin/test/Classes.kt index 6d78a05..0c20200 100644 --- a/tests/src/test/kotlin/test/Classes.kt +++ b/tests/src/test/kotlin/test/Classes.kt @@ -45,6 +45,8 @@ class Closed interface Methods { fun closed(c: Closed) + fun classClosed(c: Class) + suspend fun coroutinesClosed(c: Closed) fun closedArray(a: Array) fun closedNullableArray(a: Array) fun closedCollection(c: Collection) @@ -77,6 +79,8 @@ interface Methods { fun nullableStringResult(): String? fun builderMethod(): Methods fun varargBooleanResult(vararg values: String): Boolean + suspend fun coroutinesClosedBooleanResult(c: Closed): Boolean + suspend fun coroutinesClassClosedBooleanResult(c: Class): Boolean fun stringArray(a: Array) fun argAndVararg(s: String, vararg a: String) diff --git a/tests/src/test/kotlin/test/MatchersTest.kt b/tests/src/test/kotlin/test/MatchersTest.kt index 10aeffc..f1c1382 100644 --- a/tests/src/test/kotlin/test/MatchersTest.kt +++ b/tests/src/test/kotlin/test/MatchersTest.kt @@ -2,6 +2,7 @@ package test import com.nhaarman.expect.expect import com.nhaarman.expect.expectErrorWithMessage +import kotlinx.coroutines.test.runTest import org.junit.Test import org.mockito.ArgumentMatcher import org.mockito.invocation.InvocationOnMock @@ -35,6 +36,24 @@ class MatchersTest : TestBase() { } } + @Test + fun anyClassClosedClass() { + mock().apply { + classClosed(Closed::class.java) + verify(this).classClosed(any()) + } + } + + @Test + fun anyCoroutinesClosedClass() { + mock().apply { + runTest { + coroutinesClosed(Closed()) + verify(this@apply).coroutinesClosed(any()) + } + } + } + @Test fun anyIntArray() { mock().apply { diff --git a/tests/src/test/kotlin/test/MockingTest.kt b/tests/src/test/kotlin/test/MockingTest.kt index a7ca713..9a42d3c 100644 --- a/tests/src/test/kotlin/test/MockingTest.kt +++ b/tests/src/test/kotlin/test/MockingTest.kt @@ -3,12 +3,14 @@ package test import com.nhaarman.expect.expect import com.nhaarman.expect.expectErrorWithMessage import com.nhaarman.expect.fail +import kotlinx.coroutines.test.runTest import org.mockito.kotlin.UseConstructor.Companion.parameterless import org.mockito.kotlin.UseConstructor.Companion.withArguments import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import org.mockito.kotlin.any import org.junit.Test import org.mockito.Mockito import org.mockito.exceptions.verification.WantedButNotInvoked @@ -274,6 +276,34 @@ class MockingTest : TestBase() { expect(result).toBe("foo") } + @Test + fun mockCoroutines_withClosedBooleanReturn_name() = runTest { + /* Given */ + val mock = mock(name = "myName") { + onBlocking { coroutinesClosedBooleanResult(any()) } doReturn true + } + + /* When */ + val result = mock.coroutinesClosedBooleanResult(Closed()) + + /* Then */ + expect(result).toBe(true) + } + + @Test + fun mockCoroutines_withClassClosedBooleanReturn_name() = runTest { + /* Given */ + val mock = mock(name = "myName") { + onBlocking { coroutinesClassClosedBooleanResult(any()) } doReturn true + } + + /* When */ + val result = mock.coroutinesClassClosedBooleanResult(Closed::class.java) + + /* Then */ + expect(result).toBe(true) + } + @Test fun mockStubbing_withSettingsAPI_defaultAnswer() { /* Given */