Skip to content

Kotlin 1.6.10, coroutines 1.6 #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ dependencies {
androidTestImplementation(deps.test.androidXSspresso)

addUnitTest()
testImplementation(testUtils)
testImplementation(deps.koin.testJunit4)
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/hoc/flowmvi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class App : Application() {
startKoin {
androidContext(this@App)

androidLogger(if (BuildConfig.DEBUG) Level.DEBUG else Level.NONE)
// TODO(koin): https://github.com/InsertKoinIO/koin/issues/1188
androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)

modules(allModules)
}
Expand Down
11 changes: 8 additions & 3 deletions app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.hoc.flowmvi

import androidx.lifecycle.SavedStateHandle
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
import io.mockk.every
import io.mockk.mockkClass
import kotlin.test.Test
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import org.junit.Rule
Expand All @@ -11,8 +14,6 @@ import org.koin.dsl.koinApplication
import org.koin.test.AutoCloseKoinTest
import org.koin.test.check.checkModules
import org.koin.test.mock.MockProviderRule
import kotlin.test.Test
import kotlin.time.ExperimentalTime

@ExperimentalStdlibApi
@FlowPreview
Expand All @@ -27,12 +28,16 @@ class CheckModulesTest : AutoCloseKoinTest() {
}
}
}
@get:Rule
val coroutineRule = TestCoroutineDispatcherRule()

@Test
fun verifyKoinApp() {
koinApplication {
modules(allModules)
printLogger(Level.DEBUG)

// TODO(koin): https://github.com/InsertKoinIO/koin/issues/1188
printLogger(Level.ERROR)

checkModules {
withInstance<SavedStateHandle>()
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

const val ktlintVersion = "0.43.2"
const val kotlinVersion = "1.5.31"
const val kotlinVersion = "1.6.10"

object appConfig {
const val applicationId = "com.hoc.flowmvi"
Expand Down Expand Up @@ -52,7 +52,7 @@ object deps {
}

object coroutines {
private const val version = "1.5.2"
private const val version = "1.6.0"

const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import java.io.IOException
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import arrow.core.Either.Companion.catch as catchEither
import kotlin.time.Duration.Companion.milliseconds

@ExperimentalTime
@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -69,7 +70,7 @@ internal class UserRepositoryImpl(
return withContext(dispatchers.io) {
retrySuspend(
times = 3,
initialDelay = Duration.milliseconds(500),
initialDelay = 500.milliseconds,
factor = 2.0,
shouldRetry = { it is IOException }
) { times ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import android.util.Log
import com.hoc.flowmvi.core.dispatchers.CoroutineDispatchers
import com.hoc.flowmvi.domain.repository.UserRepository
import com.hoc.flowmvi.test_utils.getOrThrow
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.test.Test
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
Expand All @@ -13,24 +18,21 @@ import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import org.koin.core.logger.Level
import org.koin.dsl.module
import org.koin.test.KoinTest
import org.koin.test.KoinTestRule
import org.koin.test.inject
import timber.log.Timber
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.test.Test
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime

@ExperimentalCoroutinesApi
@ExperimentalTime
@ExperimentalStdlibApi
class UserRepositoryImplRealAPITest : KoinTest {
@get:Rule
val koinRuleTest = KoinTestRule.create {
printLogger()
// TODO(koin): https://github.com/InsertKoinIO/koin/issues/1188
printLogger(Level.ERROR)
modules(
dataModule,
module {
Expand Down
37 changes: 18 additions & 19 deletions data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import io.mockk.verifySequence
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Rule
import java.io.IOException
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand All @@ -41,6 +34,13 @@ import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Rule

private val USER_BODY = UserBody(
email = "email1@gmail.com",
Expand Down Expand Up @@ -103,7 +103,6 @@ private val VALID_NEL_USERS = USERS.map(User::validNel)
class UserRepositoryImplTest {
@get:Rule
val coroutineRule = TestCoroutineDispatcherRule()
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher

private lateinit var repo: UserRepositoryImpl
private lateinit var userApiService: UserApiService
Expand Down Expand Up @@ -139,7 +138,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_refresh_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
fun test_refresh_withApiCallSuccess_returnsRight() = runTest {
coEvery { userApiService.getUsers() } returns USER_RESPONSES
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS

Expand All @@ -157,7 +156,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_refresh_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
fun test_refresh_withApiCallError_returnsLeft() = runTest {
val ioException = IOException()
coEvery { userApiService.getUsers() } throws ioException
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
Expand All @@ -171,7 +170,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_remove_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
fun test_remove_withApiCallSuccess_returnsRight() = runTest {
val user = USERS[0]
val userResponse = USER_RESPONSES[0]

Expand All @@ -188,7 +187,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_remove_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
fun test_remove_withApiCallError_returnsLeft() = runTest {
val user = USERS[0]
coEvery { userApiService.remove(user.id) } throws IOException()
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
Expand All @@ -202,7 +201,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_add_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
fun test_add_withApiCallSuccess_returnsRight() = runTest {
val user = USERS[0]
val userResponse = USER_RESPONSES[0]

Expand All @@ -221,7 +220,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_add_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
fun test_add_withApiCallError_returnsLeft() = runTest {
val user = USERS[0]
coEvery { userApiService.add(USER_BODY) } throws IOException()
every { domainToBody(user) } returns USER_BODY
Expand All @@ -238,7 +237,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_search_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
fun test_search_withApiCallSuccess_returnsRight() = runTest {
val q = "hoc081098"
coEvery { userApiService.search(q) } returns USER_RESPONSES
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS
Expand All @@ -258,7 +257,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_search_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
fun test_search_withApiCallError_returnsLeft() = runTest {
val q = "hoc081098"
coEvery { userApiService.search(q) } throws IOException()
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
Expand All @@ -273,7 +272,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_getUsers_withApiCallSuccess_emitsInitial() = testDispatcher.runBlockingTest {
fun test_getUsers_withApiCallSuccess_emitsInitial() = runTest {
coEvery { userApiService.getUsers() } returns USER_RESPONSES
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS

Expand All @@ -299,7 +298,7 @@ class UserRepositoryImplTest {
}

@Test
fun test_getUsers_withApiCallError_rethrows() = testDispatcher.runBlockingTest {
fun test_getUsers_withApiCallError_rethrows() = runTest {
coEvery { userApiService.getUsers() } throws IOException()
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError

Expand All @@ -322,7 +321,7 @@ class UserRepositoryImplTest {

@Test
fun test_getUsers_withApiCallSuccess_emitsInitialAndUpdatedUsers() =
testDispatcher.runBlockingTest {
runTest {
val user = USERS.last()
val userResponse = USER_RESPONSES.last()
coEvery { userApiService.getUsers() } returns USER_RESPONSES.dropLast(1)
Expand Down
Loading