Skip to content

Commit 1874bba

Browse files
Kotlin 1.6.10, coroutines 1.6 (#86)
* kotlin 1.6.10, coroutines 1.6 * Update app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update data/src/main/java/com/hoc/flowmvi/data/UserRepositoryImpl.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplRealAPITest.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplRealAPITest.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update mvi/mvi-testing/src/main/java/com/hoc/flowmvi/mvi_testing/BaseMviViewModelTest.kt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * spotless * fix * fix vm tests Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4c9a8a5 commit 1874bba

File tree

17 files changed

+386
-255
lines changed

17 files changed

+386
-255
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ dependencies {
7575
androidTestImplementation(deps.test.androidXSspresso)
7676

7777
addUnitTest()
78+
testImplementation(testUtils)
7879
testImplementation(deps.koin.testJunit4)
7980
}

app/src/main/java/com/hoc/flowmvi/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class App : Application() {
4747
startKoin {
4848
androidContext(this@App)
4949

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

5253
modules(allModules)
5354
}

app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.hoc.flowmvi
22

33
import androidx.lifecycle.SavedStateHandle
4+
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
45
import io.mockk.every
56
import io.mockk.mockkClass
67
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -27,12 +28,16 @@ class CheckModulesTest : AutoCloseKoinTest() {
2728
}
2829
}
2930
}
31+
@get:Rule
32+
val coroutineRule = TestCoroutineDispatcherRule()
3033

3134
@Test
3235
fun verifyKoinApp() {
3336
koinApplication {
3437
modules(allModules)
35-
printLogger(Level.DEBUG)
38+
39+
// TODO(koin): https://github.com/InsertKoinIO/koin/issues/1188
40+
printLogger(Level.ERROR)
3641

3742
checkModules {
3843
withInstance<SavedStateHandle>()

buildSrc/src/main/kotlin/deps.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.gradle.plugin.use.PluginDependenciesSpec
77
import org.gradle.plugin.use.PluginDependencySpec
88

99
const val ktlintVersion = "0.43.2"
10-
const val kotlinVersion = "1.5.31"
10+
const val kotlinVersion = "1.6.10"
1111

1212
object appConfig {
1313
const val applicationId = "com.hoc.flowmvi"
@@ -52,7 +52,7 @@ object deps {
5252
}
5353

5454
object coroutines {
55-
private const val version = "1.5.2"
55+
private const val version = "1.6.0"
5656

5757
const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
5858
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"

data/src/main/java/com/hoc/flowmvi/data/UserRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.scan
2828
import kotlinx.coroutines.withContext
2929
import timber.log.Timber
3030
import java.io.IOException
31-
import kotlin.time.Duration
31+
import kotlin.time.Duration.Companion.milliseconds
3232
import kotlin.time.ExperimentalTime
3333
import arrow.core.Either.Companion.catch as catchEither
3434

@@ -69,7 +69,7 @@ internal class UserRepositoryImpl(
6969
return withContext(dispatchers.io) {
7070
retrySuspend(
7171
times = 3,
72-
initialDelay = Duration.milliseconds(500),
72+
initialDelay = 500.milliseconds,
7373
factor = 2.0,
7474
shouldRetry = { it is IOException }
7575
) { times ->

data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplRealAPITest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlinx.coroutines.runBlocking
1313
import org.junit.Rule
1414
import org.junit.rules.TestWatcher
1515
import org.junit.runner.Description
16+
import org.koin.core.logger.Level
1617
import org.koin.dsl.module
1718
import org.koin.test.KoinTest
1819
import org.koin.test.KoinTestRule
@@ -30,7 +31,8 @@ import kotlin.time.ExperimentalTime
3031
class UserRepositoryImplRealAPITest : KoinTest {
3132
@get:Rule
3233
val koinRuleTest = KoinTestRule.create {
33-
printLogger()
34+
// TODO(koin): https://github.com/InsertKoinIO/koin/issues/1188
35+
printLogger(Level.ERROR)
3436
modules(
3537
dataModule,
3638
module {

data/src/test/java/com/hoc/flowmvi/data/UserRepositoryImplTest.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
2929
import kotlinx.coroutines.delay
3030
import kotlinx.coroutines.flow.toList
3131
import kotlinx.coroutines.launch
32-
import kotlinx.coroutines.test.runBlockingTest
32+
import kotlinx.coroutines.test.runTest
3333
import org.junit.Rule
3434
import java.io.IOException
3535
import kotlin.test.AfterTest
@@ -103,7 +103,6 @@ private val VALID_NEL_USERS = USERS.map(User::validNel)
103103
class UserRepositoryImplTest {
104104
@get:Rule
105105
val coroutineRule = TestCoroutineDispatcherRule()
106-
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher
107106

108107
private lateinit var repo: UserRepositoryImpl
109108
private lateinit var userApiService: UserApiService
@@ -120,7 +119,7 @@ class UserRepositoryImplTest {
120119

121120
repo = UserRepositoryImpl(
122121
userApiService = userApiService,
123-
dispatchers = TestDispatchers(coroutineRule.testCoroutineDispatcher),
122+
dispatchers = TestDispatchers(coroutineRule.testDispatcher),
124123
responseToDomain = responseToDomain,
125124
domainToBody = domainToBody,
126125
errorMapper = errorMapper
@@ -139,7 +138,7 @@ class UserRepositoryImplTest {
139138
}
140139

141140
@Test
142-
fun test_refresh_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
141+
fun test_refresh_withApiCallSuccess_returnsRight() = runTest {
143142
coEvery { userApiService.getUsers() } returns USER_RESPONSES
144143
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS
145144

@@ -157,7 +156,7 @@ class UserRepositoryImplTest {
157156
}
158157

159158
@Test
160-
fun test_refresh_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
159+
fun test_refresh_withApiCallError_returnsLeft() = runTest {
161160
val ioException = IOException()
162161
coEvery { userApiService.getUsers() } throws ioException
163162
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
@@ -171,7 +170,7 @@ class UserRepositoryImplTest {
171170
}
172171

173172
@Test
174-
fun test_remove_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
173+
fun test_remove_withApiCallSuccess_returnsRight() = runTest {
175174
val user = USERS[0]
176175
val userResponse = USER_RESPONSES[0]
177176

@@ -188,7 +187,7 @@ class UserRepositoryImplTest {
188187
}
189188

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

204203
@Test
205-
fun test_add_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
204+
fun test_add_withApiCallSuccess_returnsRight() = runTest {
206205
val user = USERS[0]
207206
val userResponse = USER_RESPONSES[0]
208207

@@ -221,7 +220,7 @@ class UserRepositoryImplTest {
221220
}
222221

223222
@Test
224-
fun test_add_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
223+
fun test_add_withApiCallError_returnsLeft() = runTest {
225224
val user = USERS[0]
226225
coEvery { userApiService.add(USER_BODY) } throws IOException()
227226
every { domainToBody(user) } returns USER_BODY
@@ -238,7 +237,7 @@ class UserRepositoryImplTest {
238237
}
239238

240239
@Test
241-
fun test_search_withApiCallSuccess_returnsRight() = testDispatcher.runBlockingTest {
240+
fun test_search_withApiCallSuccess_returnsRight() = runTest {
242241
val q = "hoc081098"
243242
coEvery { userApiService.search(q) } returns USER_RESPONSES
244243
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS
@@ -258,7 +257,7 @@ class UserRepositoryImplTest {
258257
}
259258

260259
@Test
261-
fun test_search_withApiCallError_returnsLeft() = testDispatcher.runBlockingTest {
260+
fun test_search_withApiCallError_returnsLeft() = runTest {
262261
val q = "hoc081098"
263262
coEvery { userApiService.search(q) } throws IOException()
264263
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
@@ -273,7 +272,7 @@ class UserRepositoryImplTest {
273272
}
274273

275274
@Test
276-
fun test_getUsers_withApiCallSuccess_emitsInitial() = testDispatcher.runBlockingTest {
275+
fun test_getUsers_withApiCallSuccess_emitsInitial() = runTest {
277276
coEvery { userApiService.getUsers() } returns USER_RESPONSES
278277
every { responseToDomain(any()) } returnsMany VALID_NEL_USERS
279278

@@ -299,7 +298,7 @@ class UserRepositoryImplTest {
299298
}
300299

301300
@Test
302-
fun test_getUsers_withApiCallError_rethrows() = testDispatcher.runBlockingTest {
301+
fun test_getUsers_withApiCallError_rethrows() = runTest {
303302
coEvery { userApiService.getUsers() } throws IOException()
304303
every { errorMapper(ofType<IOException>()) } returns UserError.NetworkError
305304

@@ -322,7 +321,7 @@ class UserRepositoryImplTest {
322321

323322
@Test
324323
fun test_getUsers_withApiCallSuccess_emitsInitialAndUpdatedUsers() =
325-
testDispatcher.runBlockingTest {
324+
runTest {
326325
val user = USERS.last()
327326
val userResponse = USER_RESPONSES.last()
328327
coEvery { userApiService.getUsers() } returns USER_RESPONSES.dropLast(1)

domain/src/test/java/com/hoc/flowmvi/domain/UseCaseTest.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import io.mockk.verify
2222
import kotlinx.coroutines.ExperimentalCoroutinesApi
2323
import kotlinx.coroutines.flow.first
2424
import kotlinx.coroutines.flow.flowOf
25-
import kotlinx.coroutines.test.runBlockingTest
25+
import kotlinx.coroutines.test.runTest
2626
import org.junit.Rule
2727
import kotlin.test.AfterTest
2828
import kotlin.test.BeforeTest
@@ -57,7 +57,6 @@ private val USERS = listOf(
5757
class UseCaseTest {
5858
@get:Rule
5959
val coroutineRule = TestCoroutineDispatcherRule()
60-
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher
6160

6261
private lateinit var userRepository: UserRepository
6362
private lateinit var getUsersUseCase: GetUsersUseCase
@@ -86,7 +85,7 @@ class UseCaseTest {
8685
}
8786

8887
@Test
89-
fun test_getUsersUseCase_whenSuccess_emitsUsers() = testDispatcher.runBlockingTest {
88+
fun test_getUsersUseCase_whenSuccess_emitsUsers() = runTest {
9089
val usersRight = USERS.right()
9190
every { userRepository.getUsers() } returns flowOf(usersRight)
9291

@@ -97,7 +96,7 @@ class UseCaseTest {
9796
}
9897

9998
@Test
100-
fun test_getUsersUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
99+
fun test_getUsersUseCase_whenError_throwsError() = runTest {
101100
every { userRepository.getUsers() } returns flowOf(errorLeft)
102101

103102
val result = getUsersUseCase()
@@ -107,7 +106,7 @@ class UseCaseTest {
107106
}
108107

109108
@Test
110-
fun test_refreshUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
109+
fun test_refreshUseCase_whenSuccess_returnsUnit() = runTest {
111110
coEvery { userRepository.refresh() } returns Unit.right()
112111

113112
val result = refreshUseCase()
@@ -117,7 +116,7 @@ class UseCaseTest {
117116
}
118117

119118
@Test
120-
fun test_refreshUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
119+
fun test_refreshUseCase_whenError_throwsError() = runTest {
121120
coEvery { userRepository.refresh() } returns errorLeft
122121

123122
val result = refreshUseCase()
@@ -127,7 +126,7 @@ class UseCaseTest {
127126
}
128127

129128
@Test
130-
fun test_removeUserUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
129+
fun test_removeUserUseCase_whenSuccess_returnsUnit() = runTest {
131130
coEvery { userRepository.remove(any()) } returns Unit.right()
132131

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

139138
@Test
140-
fun test_removeUserUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
139+
fun test_removeUserUseCase_whenError_throwsError() = runTest {
141140
coEvery { userRepository.remove(any()) } returns errorLeft
142141

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

149148
@Test
150-
fun test_addUserUseCase_whenSuccess_returnsUnit() = testDispatcher.runBlockingTest {
149+
fun test_addUserUseCase_whenSuccess_returnsUnit() = runTest {
151150
coEvery { userRepository.add(any()) } returns Unit.right()
152151

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

159158
@Test
160-
fun test_addUserUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
159+
fun test_addUserUseCase_whenError_throwsError() = runTest {
161160
coEvery { userRepository.add(any()) } returns errorLeft
162161

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

169168
@Test
170-
fun test_searchUsersUseCase_whenSuccess_returnsUsers() = testDispatcher.runBlockingTest {
169+
fun test_searchUsersUseCase_whenSuccess_returnsUsers() = runTest {
171170
coEvery { userRepository.search(any()) } returns USERS.right()
172171

173172
val query = "hoc081098"
@@ -178,7 +177,7 @@ class UseCaseTest {
178177
}
179178

180179
@Test
181-
fun test_searchUsersUseCase_whenError_throwsError() = testDispatcher.runBlockingTest {
180+
fun test_searchUsersUseCase_whenError_throwsError() = runTest {
182181
coEvery { userRepository.search(any()) } returns errorLeft
183182

184183
val query = "hoc081098"

0 commit comments

Comments
 (0)