Skip to content

Commit

Permalink
[#3582] Add back the DataSource Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Jun 30, 2024
1 parent f6aceed commit 508c722
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 91 deletions.
11 changes: 1 addition & 10 deletions client/datasource/currency/client-datasource-currency.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
libs.plugins.apply {
alias(kotlinMultiplatform)
alias(androidLibrary)
alias(ksp)
alias(mokkery)
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,15 +26,9 @@ internal class CurrencyDataSourceTest {
CurrencyDataSourceImpl(currencyQueries, UnconfinedTestDispatcher())
}

@Mock
private val currencyQueries =
configure(mock(classOf<CurrencyQueries>())) { stubsUnitByDefault = true }

@Mock
private val sqlDriver = mock(classOf<SqlDriver>())

@Mock
private val sqlCursor = configure(mock(classOf<SqlCursor>())) { stubsUnitByDefault = true }
private val currencyQueries = mock<CurrencyQueries>(MockMode.autoUnit)
private val sqlDriver = mock<SqlDriver>()
private val sqlCursor = mock<SqlCursor>(MockMode.autoUnit)

private val currency = Currency("EUR", "", "", 0.0, 0L)
private val query = Query(-1, mutableListOf(), sqlDriver, query = "") {
Expand Down Expand Up @@ -63,7 +56,6 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.getCurrencies() }
.wasInvoked()
}

@Test
Expand All @@ -76,7 +68,6 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.getActiveCurrencies() }
.wasInvoked()
}

@Test
Expand All @@ -89,7 +80,6 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.getActiveCurrencies() }
.wasInvoked()
}

@Test
Expand All @@ -102,7 +92,6 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.updateCurrencyStateByCode(mockState.toLong(), mockCode) }
.wasInvoked()
}

@Test
Expand All @@ -114,7 +103,6 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.updateCurrencyStates(mockState.toLong()) }
.wasInvoked()
}

@Test
Expand All @@ -127,6 +115,5 @@ internal class CurrencyDataSourceTest {
}

verify { currencyQueries.getCurrencyByCode(currency.code) }
.wasInvoked()
}
}
11 changes: 1 addition & 10 deletions client/datasource/watcher/client-datasource-watcher.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
libs.plugins.apply {
alias(kotlinMultiplatform)
alias(androidLibrary)
alias(ksp)
alias(mokkery)
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,15 +26,9 @@ internal class WatcherDataSourceTest {
WatcherDataSourceImpl(watcherQueries, UnconfinedTestDispatcher())
}

@Mock
private val watcherQueries =
configure(mock(classOf<WatcherQueries>())) { stubsUnitByDefault = true }

@Mock
private val sqlDriver = mock(classOf<SqlDriver>())

@Mock
private val sqlCursor = configure(mock(classOf<SqlCursor>())) { stubsUnitByDefault = true }
private val watcherQueries = mock<WatcherQueries>(MockMode.autoUnit)
private val sqlDriver = mock<SqlDriver>()
private val sqlCursor = mock<SqlCursor>(MockMode.autoUnit)

private val base = "EUR"
private val target = "USD"
Expand Down Expand Up @@ -64,15 +57,13 @@ internal class WatcherDataSourceTest {
subject.getWatchersFlow()

verify { watcherQueries.getWatchers() }
.wasInvoked()
}

@Test
fun addWatcher() = runTest {
subject.addWatcher(base, target)

verify { watcherQueries.addWatcher(base, target) }
.wasInvoked()
}

@Test
Expand All @@ -83,31 +74,27 @@ internal class WatcherDataSourceTest {
subject.getWatchers()

verify { watcherQueries.getWatchers() }
.wasInvoked()
}

@Test
fun deleteWatcher() = runTest {
subject.deleteWatcher(id)

verify { watcherQueries.deleteWatcher(id) }
.wasInvoked()
}

@Test
fun updateWatcherBaseById() = runTest {
subject.updateWatcherBaseById(base, id)

verify { watcherQueries.updateWatcherBaseById(base, id) }
.wasInvoked()
}

@Test
fun updateWatcherTargetById() = runTest {
subject.updateWatcherTargetById(target, id)

verify { watcherQueries.updateWatcherTargetById(target, id) }
.wasInvoked()
}

@Test
Expand All @@ -116,7 +103,6 @@ internal class WatcherDataSourceTest {
subject.updateWatcherRelationById(relation, id)

verify { watcherQueries.updateWatcherRelationById(relation.toLong(), id) }
.wasInvoked()
}

@Test
Expand All @@ -126,6 +112,5 @@ internal class WatcherDataSourceTest {
subject.updateWatcherRateById(rate, id)

verify { watcherQueries.updateWatcherRateById(rate, id) }
.wasInvoked()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
libs.plugins.apply {
alias(kotlinMultiplatform)
alias(androidLibrary)
alias(ksp)
alias(mokkery)
}
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,15 +25,9 @@ internal class ConversionDataSourceTest {
ConversionDataSourceImpl(conversionQueries, UnconfinedTestDispatcher())
}

@Mock
private val conversionQueries =
configure(mock(classOf<ConversionQueries>())) { stubsUnitByDefault = true }

@Mock
private val sqlDriver = mock(classOf<SqlDriver>())

@Mock
private val sqlCursor = configure(mock(classOf<SqlCursor>())) { stubsUnitByDefault = true }
private val conversionQueries = mock<ConversionQueries>(MockMode.autoUnit)
private val sqlDriver = mock<SqlDriver>()
private val sqlCursor = mock<SqlCursor>(MockMode.autoUnit)

private val query = Query(-1, mutableListOf(), sqlDriver, query = "") {
Fakes.conversionModel.toConversionDBModel()
Expand All @@ -58,7 +51,6 @@ internal class ConversionDataSourceTest {
}

verify { conversionQueries.insertConversion(Fakes.conversionModel.toConversionDBModel()) }
.wasInvoked()
}

@Test
Expand All @@ -71,6 +63,5 @@ internal class ConversionDataSourceTest {
}

verify { conversionQueries.getConversionByBase(Fakes.conversionModel.base) }
.wasInvoked()
}
}

0 comments on commit 508c722

Please sign in to comment.