-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit dfc0a2a.
- Loading branch information
1 parent
dd9da8d
commit f6aceed
Showing
6 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...c/commonTest/kotlin/com/oztechan/ccc/client/datasource/currency/CurrencyDataSourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.oztechan.ccc.client.datasource.currency | ||
|
||
import co.touchlab.kermit.CommonWriter | ||
import co.touchlab.kermit.Logger | ||
import com.oztechan.ccc.common.core.database.mapper.toLong | ||
import com.oztechan.ccc.common.core.database.sql.Currency | ||
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 kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.random.Random | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
internal class CurrencyDataSourceTest { | ||
|
||
private val subject: CurrencyDataSource by lazy { | ||
@Suppress("OPT_IN_USAGE") | ||
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 currency = Currency("EUR", "", "", 0.0, 0L) | ||
private val query = Query(-1, mutableListOf(), sqlDriver, query = "") { | ||
currency | ||
} | ||
|
||
@BeforeTest | ||
fun setup() { | ||
Logger.setLogWriters(CommonWriter()) | ||
|
||
every { sqlDriver.executeQuery(-1, "", 0, null) } | ||
.returns(sqlCursor) | ||
|
||
every { sqlCursor.next() } | ||
.returns(false) | ||
} | ||
|
||
@Test | ||
fun getCurrenciesFlow() { | ||
every { currencyQueries.getCurrencies() } | ||
.returns(query) | ||
|
||
runTest { | ||
subject.getCurrenciesFlow() | ||
} | ||
|
||
verify { currencyQueries.getCurrencies() } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun getActiveCurrenciesFlow() { | ||
every { currencyQueries.getActiveCurrencies() } | ||
.returns(query) | ||
|
||
runTest { | ||
subject.getActiveCurrenciesFlow() | ||
} | ||
|
||
verify { currencyQueries.getActiveCurrencies() } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun getActiveCurrencies() { | ||
every { currencyQueries.getActiveCurrencies() } | ||
.returns(query) | ||
|
||
runTest { | ||
subject.getActiveCurrencies() | ||
} | ||
|
||
verify { currencyQueries.getActiveCurrencies() } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun updateCurrencyStateByCode() { | ||
val mockCode = "mock" | ||
val mockState = Random.nextBoolean() | ||
|
||
runTest { | ||
subject.updateCurrencyStateByCode(mockCode, mockState) | ||
} | ||
|
||
verify { currencyQueries.updateCurrencyStateByCode(mockState.toLong(), mockCode) } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun updateCurrencyStates() { | ||
val mockState = Random.nextBoolean() | ||
|
||
runTest { | ||
subject.updateCurrencyStates(mockState) | ||
} | ||
|
||
verify { currencyQueries.updateCurrencyStates(mockState.toLong()) } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun getCurrencyByCode() { | ||
every { currencyQueries.getCurrencyByCode(currency.code) } | ||
.returns(query) | ||
|
||
runTest { | ||
subject.getCurrencyByCode(currency.code) | ||
} | ||
|
||
verify { currencyQueries.getCurrencyByCode(currency.code) } | ||
.wasInvoked() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...src/commonTest/kotlin/com/oztechan/ccc/client/datasource/watcher/WatcherDataSourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.oztechan.ccc.client.datasource.watcher | ||
|
||
import co.touchlab.kermit.CommonWriter | ||
import co.touchlab.kermit.Logger | ||
import com.oztechan.ccc.common.core.database.mapper.toLong | ||
import com.oztechan.ccc.common.core.database.sql.Watcher | ||
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 kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.random.Random | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
internal class WatcherDataSourceTest { | ||
|
||
private val subject: WatcherDataSource by lazy { | ||
@Suppress("OPT_IN_USAGE") | ||
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 base = "EUR" | ||
private val target = "USD" | ||
private val id = 12L | ||
|
||
private val query = Query(-1, mutableListOf(), sqlDriver, query = "") { | ||
Watcher(id, base, target, 1L, 0.0) | ||
} | ||
|
||
@BeforeTest | ||
fun setup() { | ||
Logger.setLogWriters(CommonWriter()) | ||
|
||
every { sqlDriver.executeQuery(-1, "", 0, null) } | ||
.returns(sqlCursor) | ||
|
||
every { sqlCursor.next() } | ||
.returns(false) | ||
} | ||
|
||
@Test | ||
fun getWatchersFlow() = runTest { | ||
every { watcherQueries.getWatchers() } | ||
.returns(query) | ||
|
||
subject.getWatchersFlow() | ||
|
||
verify { watcherQueries.getWatchers() } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun addWatcher() = runTest { | ||
subject.addWatcher(base, target) | ||
|
||
verify { watcherQueries.addWatcher(base, target) } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun getWatchers() = runTest { | ||
every { watcherQueries.getWatchers() } | ||
.returns(query) | ||
|
||
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 | ||
fun updateWatcherRelationById() = runTest { | ||
val relation = Random.nextBoolean() | ||
subject.updateWatcherRelationById(relation, id) | ||
|
||
verify { watcherQueries.updateWatcherRelationById(relation.toLong(), id) } | ||
.wasInvoked() | ||
} | ||
|
||
@Test | ||
fun updateWatcherRateById() = runTest { | ||
val rate = 1.2 | ||
|
||
subject.updateWatcherRateById(rate, id) | ||
|
||
verify { watcherQueries.updateWatcherRateById(rate, id) } | ||
.wasInvoked() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.