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 all 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
7 changes: 6 additions & 1 deletion app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hoc.flowmvi

import androidx.lifecycle.SavedStateHandle
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
import io.mockk.every
import io.mockk.mockkClass
import kotlinx.coroutines.ExperimentalCoroutinesApi
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
4 changes: 2 additions & 2 deletions data/src/main/java/com/hoc/flowmvi/data/UserRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.io.IOException
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
import arrow.core.Either.Companion.catch as catchEither

Expand Down Expand Up @@ -69,7 +69,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 @@ -13,6 +13,7 @@ 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
Expand All @@ -30,7 +31,8 @@ import kotlin.time.ExperimentalTime
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
27 changes: 13 additions & 14 deletions data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import java.io.IOException
import kotlin.test.AfterTest
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 All @@ -120,7 +119,7 @@ class UserRepositoryImplTest {

repo = UserRepositoryImpl(
userApiService = userApiService,
dispatchers = TestDispatchers(coroutineRule.testCoroutineDispatcher),
dispatchers = TestDispatchers(coroutineRule.testDispatcher),
responseToDomain = responseToDomain,
domainToBody = domainToBody,
errorMapper = errorMapper
Expand All @@ -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
23 changes: 11 additions & 12 deletions domain/src/test/java/com/hoc/flowmvi/domain/UseCaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -57,7 +57,6 @@ private val USERS = listOf(
class UseCaseTest {
@get:Rule
val coroutineRule = TestCoroutineDispatcherRule()
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher

private lateinit var userRepository: UserRepository
private lateinit var getUsersUseCase: GetUsersUseCase
Expand Down Expand Up @@ -86,7 +85,7 @@ class UseCaseTest {
}

@Test
fun test_getUsersUseCase_whenSuccess_emitsUsers() = testDispatcher.runBlockingTest {
fun test_getUsersUseCase_whenSuccess_emitsUsers() = runTest {
val usersRight = USERS.right()
every { userRepository.getUsers() } returns flowOf(usersRight)

Expand All @@ -97,7 +96,7 @@ class UseCaseTest {
}

@Test
fun test_getUsersUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
fun test_getUsersUseCase_whenError_throwsError() = runTest {
every { userRepository.getUsers() } returns flowOf(errorLeft)

val result = getUsersUseCase()
Expand All @@ -107,7 +106,7 @@ class UseCaseTest {
}

@Test
fun test_refreshUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
fun test_refreshUseCase_whenSuccess_returnsUnit() = runTest {
coEvery { userRepository.refresh() } returns Unit.right()

val result = refreshUseCase()
Expand All @@ -117,7 +116,7 @@ class UseCaseTest {
}

@Test
fun test_refreshUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
fun test_refreshUseCase_whenError_throwsError() = runTest {
coEvery { userRepository.refresh() } returns errorLeft

val result = refreshUseCase()
Expand All @@ -127,7 +126,7 @@ class UseCaseTest {
}

@Test
fun test_removeUserUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
fun test_removeUserUseCase_whenSuccess_returnsUnit() = runTest {
coEvery { userRepository.remove(any()) } returns Unit.right()

val result = removeUserUseCase(USERS[0])
Expand All @@ -137,7 +136,7 @@ class UseCaseTest {
}

@Test
fun test_removeUserUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
fun test_removeUserUseCase_whenError_throwsError() = runTest {
coEvery { userRepository.remove(any()) } returns errorLeft

val result = removeUserUseCase(USERS[0])
Expand All @@ -147,7 +146,7 @@ class UseCaseTest {
}

@Test
fun test_addUserUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
fun test_addUserUseCase_whenSuccess_returnsUnit() = runTest {
coEvery { userRepository.add(any()) } returns Unit.right()

val result = addUserUseCase(USERS[0])
Expand All @@ -157,7 +156,7 @@ class UseCaseTest {
}

@Test
fun test_addUserUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
fun test_addUserUseCase_whenError_throwsError() = runTest {
coEvery { userRepository.add(any()) } returns errorLeft

val result = addUserUseCase(USERS[0])
Expand All @@ -167,7 +166,7 @@ class UseCaseTest {
}

@Test
fun test_searchUsersUseCase_whenSuccess_returnsUsers() = testDispatcher.runBlockingTest {
fun test_searchUsersUseCase_whenSuccess_returnsUsers() = runTest {
coEvery { userRepository.search(any()) } returns USERS.right()

val query = "hoc081098"
Expand All @@ -178,7 +177,7 @@ class UseCaseTest {
}

@Test
fun test_searchUsersUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
fun test_searchUsersUseCase_whenError_throwsError() = runTest {
coEvery { userRepository.search(any()) } returns errorLeft

val query = "hoc081098"
Expand Down
Loading