From 508c722b8a9509cf18e0f51f66e6d72c39a8e583 Mon Sep 17 00:00:00 2001 From: Mustafa Ozhan Date: Fri, 21 Jun 2024 17:10:18 +0300 Subject: [PATCH] [Oztechan/CCC#3582] Add back the DataSource Test Cases --- .../client-datasource-currency.gradle.kts | 11 +------ .../currency/CurrencyDataSourceTest.kt | 29 +++++------------ .../client-datasource-watcher.gradle.kts | 11 +------ .../watcher/WatcherDataSourceTest.kt | 31 +++++-------------- .../common-datasource-conversion.gradle.kts | 11 +------ .../conversion/ConversionDataSourceTest.kt | 25 +++++---------- 6 files changed, 27 insertions(+), 91 deletions(-) diff --git a/client/datasource/currency/client-datasource-currency.gradle.kts b/client/datasource/currency/client-datasource-currency.gradle.kts index 9fc370bcf5..ffbafb53c4 100644 --- a/client/datasource/currency/client-datasource-currency.gradle.kts +++ b/client/datasource/currency/client-datasource-currency.gradle.kts @@ -2,7 +2,7 @@ plugins { libs.plugins.apply { alias(kotlinMultiplatform) alias(androidLibrary) - alias(ksp) + alias(mokkery) } } @@ -29,21 +29,12 @@ kotlin { commonTest.dependencies { libs.common.apply { implementation(test) - implementation(mockative) implementation(coroutinesTest) } } } } -dependencies { - configurations - .filter { it.name.startsWith("ksp") && it.name.contains("Test") } - .forEach { - add(it.name, libs.processors.mockative) - } -} - android { ProjectSettings.apply { namespace = Modules.Client.DataSource.currency.packageName diff --git a/client/datasource/currency/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/currency/CurrencyDataSourceTest.kt b/client/datasource/currency/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/currency/CurrencyDataSourceTest.kt index 4ceae8f35b..11c381838e 100644 --- a/client/datasource/currency/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/currency/CurrencyDataSourceTest.kt +++ b/client/datasource/currency/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/currency/CurrencyDataSourceTest.kt @@ -8,12 +8,11 @@ import com.oztechan.ccc.common.core.database.sql.CurrencyQueries import com.squareup.sqldelight.Query import com.squareup.sqldelight.db.SqlCursor import com.squareup.sqldelight.db.SqlDriver -import io.mockative.Mock -import io.mockative.classOf -import io.mockative.configure -import io.mockative.every -import io.mockative.mock -import io.mockative.verify +import dev.mokkery.MockMode +import dev.mokkery.answering.returns +import dev.mokkery.every +import dev.mokkery.mock +import dev.mokkery.verify import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import kotlin.random.Random @@ -27,15 +26,9 @@ internal class CurrencyDataSourceTest { CurrencyDataSourceImpl(currencyQueries, UnconfinedTestDispatcher()) } - @Mock - private val currencyQueries = - configure(mock(classOf())) { stubsUnitByDefault = true } - - @Mock - private val sqlDriver = mock(classOf()) - - @Mock - private val sqlCursor = configure(mock(classOf())) { stubsUnitByDefault = true } + private val currencyQueries = mock(MockMode.autoUnit) + private val sqlDriver = mock() + private val sqlCursor = mock(MockMode.autoUnit) private val currency = Currency("EUR", "", "", 0.0, 0L) private val query = Query(-1, mutableListOf(), sqlDriver, query = "") { @@ -63,7 +56,6 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.getCurrencies() } - .wasInvoked() } @Test @@ -76,7 +68,6 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.getActiveCurrencies() } - .wasInvoked() } @Test @@ -89,7 +80,6 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.getActiveCurrencies() } - .wasInvoked() } @Test @@ -102,7 +92,6 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.updateCurrencyStateByCode(mockState.toLong(), mockCode) } - .wasInvoked() } @Test @@ -114,7 +103,6 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.updateCurrencyStates(mockState.toLong()) } - .wasInvoked() } @Test @@ -127,6 +115,5 @@ internal class CurrencyDataSourceTest { } verify { currencyQueries.getCurrencyByCode(currency.code) } - .wasInvoked() } } diff --git a/client/datasource/watcher/client-datasource-watcher.gradle.kts b/client/datasource/watcher/client-datasource-watcher.gradle.kts index 17b7a6098e..32029090fb 100644 --- a/client/datasource/watcher/client-datasource-watcher.gradle.kts +++ b/client/datasource/watcher/client-datasource-watcher.gradle.kts @@ -2,7 +2,7 @@ plugins { libs.plugins.apply { alias(kotlinMultiplatform) alias(androidLibrary) - alias(ksp) + alias(mokkery) } } @@ -29,21 +29,12 @@ kotlin { commonTest.dependencies { libs.common.apply { implementation(test) - implementation(mockative) implementation(coroutinesTest) } } } } -dependencies { - configurations - .filter { it.name.startsWith("ksp") && it.name.contains("Test") } - .forEach { - add(it.name, libs.processors.mockative) - } -} - android { ProjectSettings.apply { namespace = Modules.Client.DataSource.watcher.packageName diff --git a/client/datasource/watcher/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/watcher/WatcherDataSourceTest.kt b/client/datasource/watcher/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/watcher/WatcherDataSourceTest.kt index ee9f3051c8..c8e88fce39 100644 --- a/client/datasource/watcher/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/watcher/WatcherDataSourceTest.kt +++ b/client/datasource/watcher/src/commonTest/kotlin/com/oztechan/ccc/client/datasource/watcher/WatcherDataSourceTest.kt @@ -8,12 +8,11 @@ import com.oztechan.ccc.common.core.database.sql.WatcherQueries import com.squareup.sqldelight.Query import com.squareup.sqldelight.db.SqlCursor import com.squareup.sqldelight.db.SqlDriver -import io.mockative.Mock -import io.mockative.classOf -import io.mockative.configure -import io.mockative.every -import io.mockative.mock -import io.mockative.verify +import dev.mokkery.MockMode +import dev.mokkery.answering.returns +import dev.mokkery.every +import dev.mokkery.mock +import dev.mokkery.verify import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import kotlin.random.Random @@ -27,15 +26,9 @@ internal class WatcherDataSourceTest { WatcherDataSourceImpl(watcherQueries, UnconfinedTestDispatcher()) } - @Mock - private val watcherQueries = - configure(mock(classOf())) { stubsUnitByDefault = true } - - @Mock - private val sqlDriver = mock(classOf()) - - @Mock - private val sqlCursor = configure(mock(classOf())) { stubsUnitByDefault = true } + private val watcherQueries = mock(MockMode.autoUnit) + private val sqlDriver = mock() + private val sqlCursor = mock(MockMode.autoUnit) private val base = "EUR" private val target = "USD" @@ -64,7 +57,6 @@ internal class WatcherDataSourceTest { subject.getWatchersFlow() verify { watcherQueries.getWatchers() } - .wasInvoked() } @Test @@ -72,7 +64,6 @@ internal class WatcherDataSourceTest { subject.addWatcher(base, target) verify { watcherQueries.addWatcher(base, target) } - .wasInvoked() } @Test @@ -83,7 +74,6 @@ internal class WatcherDataSourceTest { subject.getWatchers() verify { watcherQueries.getWatchers() } - .wasInvoked() } @Test @@ -91,7 +81,6 @@ internal class WatcherDataSourceTest { subject.deleteWatcher(id) verify { watcherQueries.deleteWatcher(id) } - .wasInvoked() } @Test @@ -99,7 +88,6 @@ internal class WatcherDataSourceTest { subject.updateWatcherBaseById(base, id) verify { watcherQueries.updateWatcherBaseById(base, id) } - .wasInvoked() } @Test @@ -107,7 +95,6 @@ internal class WatcherDataSourceTest { subject.updateWatcherTargetById(target, id) verify { watcherQueries.updateWatcherTargetById(target, id) } - .wasInvoked() } @Test @@ -116,7 +103,6 @@ internal class WatcherDataSourceTest { subject.updateWatcherRelationById(relation, id) verify { watcherQueries.updateWatcherRelationById(relation.toLong(), id) } - .wasInvoked() } @Test @@ -126,6 +112,5 @@ internal class WatcherDataSourceTest { subject.updateWatcherRateById(rate, id) verify { watcherQueries.updateWatcherRateById(rate, id) } - .wasInvoked() } } diff --git a/common/datasource/conversion/common-datasource-conversion.gradle.kts b/common/datasource/conversion/common-datasource-conversion.gradle.kts index 116d04cce8..be2f37b7f2 100644 --- a/common/datasource/conversion/common-datasource-conversion.gradle.kts +++ b/common/datasource/conversion/common-datasource-conversion.gradle.kts @@ -2,7 +2,7 @@ plugins { libs.plugins.apply { alias(kotlinMultiplatform) alias(androidLibrary) - alias(ksp) + alias(mokkery) } } @@ -31,21 +31,12 @@ kotlin { commonTest.dependencies { libs.common.apply { implementation(test) - implementation(mockative) implementation(coroutinesTest) } } } } -dependencies { - configurations - .filter { it.name.startsWith("ksp") && it.name.contains("Test") } - .forEach { - add(it.name, libs.processors.mockative) - } -} - android { ProjectSettings.apply { namespace = Modules.Common.DataSource.conversion.packageName diff --git a/common/datasource/conversion/src/commonTest/kotlin/com/oztechan/ccc/common/datasource/conversion/ConversionDataSourceTest.kt b/common/datasource/conversion/src/commonTest/kotlin/com/oztechan/ccc/common/datasource/conversion/ConversionDataSourceTest.kt index b0b719b491..fb2dbdab6d 100644 --- a/common/datasource/conversion/src/commonTest/kotlin/com/oztechan/ccc/common/datasource/conversion/ConversionDataSourceTest.kt +++ b/common/datasource/conversion/src/commonTest/kotlin/com/oztechan/ccc/common/datasource/conversion/ConversionDataSourceTest.kt @@ -8,12 +8,11 @@ import com.oztechan.ccc.common.datasource.conversion.mapper.toConversionDBModel import com.squareup.sqldelight.Query import com.squareup.sqldelight.db.SqlCursor import com.squareup.sqldelight.db.SqlDriver -import io.mockative.Mock -import io.mockative.classOf -import io.mockative.configure -import io.mockative.every -import io.mockative.mock -import io.mockative.verify +import dev.mokkery.MockMode +import dev.mokkery.answering.returns +import dev.mokkery.every +import dev.mokkery.mock +import dev.mokkery.verify import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import kotlin.test.BeforeTest @@ -26,15 +25,9 @@ internal class ConversionDataSourceTest { ConversionDataSourceImpl(conversionQueries, UnconfinedTestDispatcher()) } - @Mock - private val conversionQueries = - configure(mock(classOf())) { stubsUnitByDefault = true } - - @Mock - private val sqlDriver = mock(classOf()) - - @Mock - private val sqlCursor = configure(mock(classOf())) { stubsUnitByDefault = true } + private val conversionQueries = mock(MockMode.autoUnit) + private val sqlDriver = mock() + private val sqlCursor = mock(MockMode.autoUnit) private val query = Query(-1, mutableListOf(), sqlDriver, query = "") { Fakes.conversionModel.toConversionDBModel() @@ -58,7 +51,6 @@ internal class ConversionDataSourceTest { } verify { conversionQueries.insertConversion(Fakes.conversionModel.toConversionDBModel()) } - .wasInvoked() } @Test @@ -71,6 +63,5 @@ internal class ConversionDataSourceTest { } verify { conversionQueries.getConversionByBase(Fakes.conversionModel.base) } - .wasInvoked() } }