diff --git a/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/AwaitTest.kt b/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/AwaitTest.kt index bf7c35c..6abcae3 100644 --- a/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/AwaitTest.kt +++ b/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/AwaitTest.kt @@ -42,7 +42,7 @@ class AwaitTest : UnitTest() { val deferred = CompletableDeferred() val key = TestQueryKey("foo") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { deferred.await() } + on(key.id) { deferred.await() } } setContent { SwrClientProvider(client) { @@ -67,8 +67,8 @@ class AwaitTest : UnitTest() { val key1 = TestQueryKey("foo") val key2 = TestQueryKey("bar") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key1.id) { deferred1.await() } - mock(key2.id) { deferred2.await() } + on(key1.id) { deferred1.await() } + on(key2.id) { deferred2.await() } } setContent { SwrClientProvider(client) { @@ -100,9 +100,9 @@ class AwaitTest : UnitTest() { val key2 = TestQueryKey("bar") val key3 = TestInfiniteQueryKey() val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key1.id) { deferred1.await() } - mock(key2.id) { deferred2.await() } - mock(key3.id) { deferred3.await() } + on(key1.id) { deferred1.await() } + on(key2.id) { deferred2.await() } + on(key3.id) { deferred3.await() } } setContent { SwrClientProvider(client) { @@ -137,8 +137,8 @@ class AwaitTest : UnitTest() { val key1 = TestQueryKey("foo") val key2 = TestQueryKey("bar") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key1.id) { deferred1.await() } - mock(key2.id) { deferred2.await() } + on(key1.id) { deferred1.await() } + on(key2.id) { deferred2.await() } } setContent { SwrClientProvider(client) { @@ -176,7 +176,7 @@ class AwaitTest : UnitTest() { var isFirst = true val key = TestQueryKey("foo") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { + on(key.id) { if (isFirst) { isFirst = false deferred1.await() diff --git a/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/CatchTest.kt b/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/CatchTest.kt index 0858d20..13fc29a 100644 --- a/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/CatchTest.kt +++ b/soil-query-compose-runtime/src/commonTest/kotlin/soil/query/compose/runtime/CatchTest.kt @@ -38,7 +38,7 @@ class CatchTest : UnitTest() { var isFirst = true val key = TestQueryKey("foo") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { + on(key.id) { if (isFirst) { isFirst = false deferred1.await() @@ -82,7 +82,7 @@ class CatchTest : UnitTest() { var isFirst = true val key = TestQueryKey("foo") val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { + on(key.id) { if (isFirst) { isFirst = false deferred1.await() diff --git a/soil-query-compose/src/commonTest/kotlin/soil/query/compose/MutationComposableTest.kt b/soil-query-compose/src/commonTest/kotlin/soil/query/compose/MutationComposableTest.kt index a6b5422..896b54b 100644 --- a/soil-query-compose/src/commonTest/kotlin/soil/query/compose/MutationComposableTest.kt +++ b/soil-query-compose/src/commonTest/kotlin/soil/query/compose/MutationComposableTest.kt @@ -72,7 +72,7 @@ class MutationComposableTest : UnitTest() { fun testRememberMutation_throwError() = runComposeUiTest { val key = TestMutationKey() val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { throw RuntimeException("Failed to do something :(") } + on(key.id) { throw RuntimeException("Failed to do something :(") } } setContent { SwrClientProvider(client) { @@ -111,7 +111,7 @@ class MutationComposableTest : UnitTest() { fun testRememberMutation_throwErrorAsync() = runComposeUiTest { val key = TestMutationKey() val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { throw RuntimeException("Failed to do something :(") } + on(key.id) { throw RuntimeException("Failed to do something :(") } } setContent { SwrClientProvider(client) { diff --git a/soil-query-compose/src/commonTest/kotlin/soil/query/compose/QueryComposableTest.kt b/soil-query-compose/src/commonTest/kotlin/soil/query/compose/QueryComposableTest.kt index e5c8d78..95d2e6a 100644 --- a/soil-query-compose/src/commonTest/kotlin/soil/query/compose/QueryComposableTest.kt +++ b/soil-query-compose/src/commonTest/kotlin/soil/query/compose/QueryComposableTest.kt @@ -54,7 +54,7 @@ class QueryComposableTest : UnitTest() { fun testRememberQuery_select() = runComposeUiTest { val key = TestQueryKey() val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { "Hello, Soil!" } + on(key.id) { "Hello, Soil!" } } setContent { SwrClientProvider(client) { @@ -74,7 +74,7 @@ class QueryComposableTest : UnitTest() { fun testRememberQuery_throwError() = runComposeUiTest { val key = TestQueryKey() val client = SwrCache(coroutineScope = SwrCacheScope()).test { - mock(key.id) { throw RuntimeException("Failed to do something :(") } + on(key.id) { throw RuntimeException("Failed to do something :(") } } setContent { SwrClientProvider(client) { diff --git a/soil-query-test/src/commonMain/kotlin/soil/query/test/TestSwrClient.kt b/soil-query-test/src/commonMain/kotlin/soil/query/test/TestSwrClient.kt index afb46f3..98031c4 100644 --- a/soil-query-test/src/commonMain/kotlin/soil/query/test/TestSwrClient.kt +++ b/soil-query-test/src/commonMain/kotlin/soil/query/test/TestSwrClient.kt @@ -22,8 +22,9 @@ import soil.query.core.Marker * * ```kotlin * val client = SwrCache(..) - * val testClient = client.test() - * testClient.mock(MyQueryId) { "returned fake data" } + * val testClient = client.test { + * on(MyQueryId) { "returned fake data" } + * } * * testClient.doSomething() * ``` @@ -33,17 +34,17 @@ interface TestSwrClient : SwrClient { /** * Mocks the mutation process corresponding to [MutationId]. */ - fun mock(id: MutationId, mutate: FakeMutationMutate) + fun on(id: MutationId, mutate: FakeMutationMutate) /** * Mocks the query process corresponding to [QueryId]. */ - fun mock(id: QueryId, fetch: FakeQueryFetch) + fun on(id: QueryId, fetch: FakeQueryFetch) /** * Mocks the query process corresponding to [InfiniteQueryId]. */ - fun mock(id: InfiniteQueryId, fetch: FakeInfiniteQueryFetch) + fun on(id: InfiniteQueryId, fetch: FakeInfiniteQueryFetch) } /** @@ -61,15 +62,15 @@ internal class TestSwrClientImpl( private val mockQueries = mutableMapOf, FakeQueryFetch<*>>() private val mockInfiniteQueries = mutableMapOf, FakeInfiniteQueryFetch<*, *>>() - override fun mock(id: MutationId, mutate: FakeMutationMutate) { + override fun on(id: MutationId, mutate: FakeMutationMutate) { mockMutations[id] = mutate } - override fun mock(id: QueryId, fetch: FakeQueryFetch) { + override fun on(id: QueryId, fetch: FakeQueryFetch) { mockQueries[id] = fetch } - override fun mock(id: InfiniteQueryId, fetch: FakeInfiniteQueryFetch) { + override fun on(id: InfiniteQueryId, fetch: FakeInfiniteQueryFetch) { mockInfiniteQueries[id] = fetch } diff --git a/soil-query-test/src/commonTest/kotlin/soil/query/test/TestSwrClientTest.kt b/soil-query-test/src/commonTest/kotlin/soil/query/test/TestSwrClientTest.kt index 5a250a3..6994c75 100644 --- a/soil-query-test/src/commonTest/kotlin/soil/query/test/TestSwrClientTest.kt +++ b/soil-query-test/src/commonTest/kotlin/soil/query/test/TestSwrClientTest.kt @@ -26,7 +26,6 @@ import soil.query.buildMutationKey import soil.query.buildQueryKey import soil.query.core.Marker import soil.query.core.getOrThrow -import soil.query.mutate import soil.testing.UnitTest import kotlin.test.Test import kotlin.test.assertEquals @@ -42,10 +41,8 @@ class TestSwrClientTest : UnitTest() { mainDispatcher = UnconfinedTestDispatcher(testScheduler) ) ) - val testClient = client.test().apply { - mock(ExampleMutationKey.Id) { - "Hello, World!" - } + val testClient = client.test { + on(ExampleMutationKey.Id) { "Hello, World!" } } val key = ExampleMutationKey() val mutation = testClient.getMutation(key).also { it.launchIn(backgroundScope) } @@ -61,10 +58,8 @@ class TestSwrClientTest : UnitTest() { mainDispatcher = UnconfinedTestDispatcher(testScheduler) ) ) - val testClient = client.test().apply { - mock(ExampleQueryKey.Id) { - "Hello, World!" - } + val testClient = client.test { + on(ExampleQueryKey.Id) { "Hello, World!" } } val key = ExampleQueryKey() val query = testClient.getQuery(key).also { it.launchIn(backgroundScope) } @@ -80,10 +75,8 @@ class TestSwrClientTest : UnitTest() { mainDispatcher = UnconfinedTestDispatcher(testScheduler) ) ) - val testClient = client.test().apply { - mock(ExampleInfiniteQueryKey.Id) { - "Hello, World!" - } + val testClient = client.test { + on(ExampleInfiniteQueryKey.Id) { "Hello, World!" } } val key = ExampleInfiniteQueryKey() val query = testClient.getInfiniteQuery(key).also { it.launchIn(backgroundScope) }