Skip to content

Commit f399609

Browse files
authored
Update test and split core (#58)
* wip * format * fix * fix res * fix res * update log tests
1 parent 1df41c7 commit f399609

File tree

50 files changed

+236
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+236
-123
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ master ]
88

9+
env:
10+
CI: true
11+
912
jobs:
1013
build:
1114
runs-on: ubuntu-latest

.github/workflows/review-suggest.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: reviewdog-suggester
22
on:
33
pull_request:
44
types: [opened, synchronize, reopened]
5+
6+
env:
7+
CI: true
8+
59
jobs:
610
kotlin:
711
name: runner / suggester / spotless

.github/workflows/unit-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ master ]
88

9+
env:
10+
CI: true
11+
912
jobs:
1013
build:
1114
runs-on: ubuntu-latest

.idea/gradle.xml

Lines changed: 3 additions & 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 & 0 deletions
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
@@ -59,6 +59,7 @@ dependencies {
5959
implementation(domain)
6060
implementation(data)
6161
implementation(core)
62+
implementation(coreUi)
6263
implementation(featureMain)
6364
implementation(featureAdd)
6465
implementation(featureSearch)

app/src/main/java/com/hoc/flowmvi/core/CoreModule.kt

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

33
import com.hoc.flowmvi.core.dispatchers.CoroutineDispatchers
4-
import com.hoc.flowmvi.core.navigator.Navigator
4+
import com.hoc.flowmvi.core_ui.navigator.Navigator
55
import org.koin.dsl.module
66

77
val coreModule = module {

app/src/main/java/com/hoc/flowmvi/core/NavigatorImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.hoc.flowmvi.core
22

33
import android.content.Context
4-
import com.hoc.flowmvi.core.navigator.IntentProviders
5-
import com.hoc.flowmvi.core.navigator.Navigator
4+
import com.hoc.flowmvi.core_ui.navigator.IntentProviders
5+
import com.hoc.flowmvi.core_ui.navigator.Navigator
66

77
class NavigatorImpl(
88
private val add: IntentProviders.Add,

buildSrc/src/main/kotlin/deps.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@file:Suppress("unused", "ClassName", "SpellCheckingInspection")
22

3+
import org.gradle.api.Project
34
import org.gradle.api.artifacts.dsl.DependencyHandler
45
import org.gradle.kotlin.dsl.project
56
import org.gradle.plugin.use.PluginDependenciesSpec
@@ -97,12 +98,14 @@ inline val PDsS.kotlinKapt: PDS get() = id("kotlin-kapt")
9798

9899
inline val DependencyHandler.domain get() = project(":domain")
99100
inline val DependencyHandler.core get() = project(":core")
101+
inline val DependencyHandler.coreUi get() = project(":core-ui")
100102
inline val DependencyHandler.data get() = project(":data")
101103
inline val DependencyHandler.featureMain get() = project(":feature-main")
102104
inline val DependencyHandler.featureAdd get() = project(":feature-add")
103105
inline val DependencyHandler.featureSearch get() = project(":feature-search")
104106
inline val DependencyHandler.mviBase get() = project(":mvi-base")
105107
inline val DependencyHandler.mviTesting get() = project(":mvi-testing")
108+
inline val DependencyHandler.testUtils get() = project(":test-utils")
106109

107110
fun DependencyHandler.addUnitTest(testImplementation: Boolean = true) {
108111
val configName = if (testImplementation) "testImplementation" else "implementation"
@@ -112,3 +115,8 @@ fun DependencyHandler.addUnitTest(testImplementation: Boolean = true) {
112115
add(configName, deps.test.kotlinJUnit)
113116
add(configName, deps.coroutines.test)
114117
}
118+
119+
val Project.isCiBuild: Boolean
120+
get() = providers.environmentVariable("CI")
121+
.forUseAtConfigurationTime()
122+
.orNull == "true"

core-ui/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

core-ui/build.gradle.kts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
plugins {
2+
androidLib
3+
kotlinAndroid
4+
}
5+
6+
android {
7+
compileSdk = appConfig.compileSdkVersion
8+
buildToolsVersion = appConfig.buildToolsVersion
9+
10+
defaultConfig {
11+
minSdk = appConfig.minSdkVersion
12+
targetSdk = appConfig.targetSdkVersion
13+
14+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15+
consumerProguardFiles("consumer-rules.pro")
16+
}
17+
18+
buildTypes {
19+
release {
20+
isMinifyEnabled = false
21+
proguardFiles(
22+
getDefaultProguardFile("proguard-android-optimize.txt"),
23+
"proguard-rules.pro"
24+
)
25+
}
26+
}
27+
28+
compileOptions {
29+
sourceCompatibility = JavaVersion.VERSION_1_8
30+
targetCompatibility = JavaVersion.VERSION_1_8
31+
}
32+
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }
33+
34+
testOptions {
35+
unitTests.isIncludeAndroidResources = true
36+
unitTests.isReturnDefaultValues = true
37+
}
38+
}
39+
40+
dependencies {
41+
implementation(deps.coroutines.core)
42+
implementation(deps.coroutines.android)
43+
44+
implementation(deps.androidx.coreKtx)
45+
implementation(deps.androidx.swipeRefreshLayout)
46+
implementation(deps.androidx.recyclerView)
47+
implementation(deps.androidx.material)
48+
49+
implementation(deps.lifecycle.commonJava8)
50+
implementation(deps.lifecycle.runtimeKtx)
51+
52+
implementation(deps.timber)
53+
54+
addUnitTest()
55+
}
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.hoc.flowmvi.core_ui

core/src/main/AndroidManifest.xml renamed to core-ui/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.hoc.flowmvi.core">
3+
package="com.hoc.flowmvi.core_ui">
44

55
<application>
66

core/src/main/java/com/hoc/flowmvi/core/CollectIn.kt renamed to core-ui/src/main/java/com/hoc/flowmvi/core_ui/CollectIn.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.hoc.flowmvi.core
1+
package com.hoc.flowmvi.core_ui
22

33
import androidx.fragment.app.Fragment
44
import androidx.lifecycle.Lifecycle

core/src/main/java/com/hoc/flowmvi/core/FlowBinding.kt renamed to core-ui/src/main/java/com/hoc/flowmvi/core_ui/FlowBinding.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.hoc.flowmvi.core
1+
package com.hoc.flowmvi.core_ui
22

33
import android.content.Context
44
import android.os.Looper

core/src/main/java/com/hoc/flowmvi/core/SwipeLeftToDeleteCallback.kt renamed to core-ui/src/main/java/com/hoc/flowmvi/core_ui/SwipeLeftToDeleteCallback.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.hoc.flowmvi.core
1+
package com.hoc.flowmvi.core_ui
22

33
import android.content.Context
44
import android.graphics.Canvas

core/src/main/java/com/hoc/flowmvi/core/navigator/Navigator.kt renamed to core-ui/src/main/java/com/hoc/flowmvi/core_ui/navigator/Navigator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.hoc.flowmvi.core.navigator
1+
package com.hoc.flowmvi.core_ui.navigator
22

33
import android.content.Context
44
import android.content.Intent
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.hoc.flowmvi.core_ui

core/build.gradle.kts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,8 @@
11
plugins {
2-
androidLib
3-
kotlinAndroid
4-
}
5-
6-
android {
7-
compileSdk = appConfig.compileSdkVersion
8-
buildToolsVersion = appConfig.buildToolsVersion
9-
10-
defaultConfig {
11-
minSdk = appConfig.minSdkVersion
12-
targetSdk = appConfig.targetSdkVersion
13-
14-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15-
consumerProguardFiles("consumer-rules.pro")
16-
}
17-
18-
buildTypes {
19-
release {
20-
isMinifyEnabled = true
21-
proguardFiles(
22-
getDefaultProguardFile("proguard-android-optimize.txt"),
23-
"proguard-rules.pro"
24-
)
25-
}
26-
}
27-
28-
compileOptions {
29-
sourceCompatibility = JavaVersion.VERSION_1_8
30-
targetCompatibility = JavaVersion.VERSION_1_8
31-
}
32-
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }
33-
34-
testOptions {
35-
unitTests.isIncludeAndroidResources = true
36-
unitTests.isReturnDefaultValues = true
37-
}
2+
kotlin
383
}
394

405
dependencies {
416
implementation(deps.coroutines.core)
42-
implementation(deps.coroutines.android)
43-
44-
implementation(deps.androidx.coreKtx)
45-
implementation(deps.androidx.swipeRefreshLayout)
46-
implementation(deps.androidx.recyclerView)
47-
implementation(deps.androidx.material)
48-
49-
implementation(deps.lifecycle.commonJava8)
50-
implementation(deps.lifecycle.runtimeKtx)
51-
52-
implementation(deps.timber)
53-
547
addUnitTest()
558
}

core/src/androidTest/java/com/hoc/flowmvi/core/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818

1919
buildTypes {
2020
release {
21-
isMinifyEnabled = true
21+
isMinifyEnabled = false
2222
proguardFiles(
2323
getDefaultProguardFile("proguard-android-optimize.txt"),
2424
"proguard-rules.pro"
@@ -55,4 +55,5 @@ dependencies {
5555
implementation(deps.timber)
5656

5757
addUnitTest()
58+
testImplementation(testUtils)
5859
}

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import arrow.core.Either
44
import arrow.core.getOrHandle
55
import arrow.core.identity
66
import com.hoc.flowmvi.core.Mapper
7-
import com.hoc.flowmvi.core.dispatchers.CoroutineDispatchers
87
import com.hoc.flowmvi.data.remote.UserApiService
98
import com.hoc.flowmvi.data.remote.UserBody
109
import com.hoc.flowmvi.data.remote.UserResponse
1110
import com.hoc.flowmvi.domain.entity.User
1211
import com.hoc.flowmvi.domain.repository.UserError
12+
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
13+
import com.hoc.flowmvi.test_utils.TestDispatchers
1314
import io.mockk.clearAllMocks
1415
import io.mockk.coEvery
1516
import io.mockk.coVerify
@@ -19,17 +20,13 @@ import io.mockk.every
1920
import io.mockk.mockk
2021
import io.mockk.verify
2122
import io.mockk.verifySequence
22-
import kotlinx.coroutines.CoroutineDispatcher
2323
import kotlinx.coroutines.CoroutineStart
24-
import kotlinx.coroutines.Dispatchers
2524
import kotlinx.coroutines.ExperimentalCoroutinesApi
2625
import kotlinx.coroutines.delay
2726
import kotlinx.coroutines.flow.toList
2827
import kotlinx.coroutines.launch
29-
import kotlinx.coroutines.test.TestCoroutineDispatcher
30-
import kotlinx.coroutines.test.resetMain
3128
import kotlinx.coroutines.test.runBlockingTest
32-
import kotlinx.coroutines.test.setMain
29+
import org.junit.Rule
3330
import java.io.IOException
3431
import kotlin.test.AfterTest
3532
import kotlin.test.BeforeTest
@@ -95,16 +92,12 @@ private val USERS = listOf(
9592
),
9693
)
9794

98-
@ExperimentalCoroutinesApi
99-
class TestDispatchersImpl(testDispatcher: TestCoroutineDispatcher) : CoroutineDispatchers {
100-
override val main: CoroutineDispatcher = testDispatcher
101-
override val io: CoroutineDispatcher = testDispatcher
102-
}
103-
10495
@ExperimentalCoroutinesApi
10596
@ExperimentalTime
10697
class UserRepositoryImplTest {
107-
private val testDispatcher = TestCoroutineDispatcher()
98+
@get:Rule
99+
val coroutineRule = TestCoroutineDispatcherRule()
100+
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher
108101

109102
private lateinit var repo: UserRepositoryImpl
110103
private lateinit var userApiService: UserApiService
@@ -114,16 +107,14 @@ class UserRepositoryImplTest {
114107

115108
@BeforeTest
116109
fun setup() {
117-
Dispatchers.setMain(testDispatcher)
118-
119110
userApiService = mockk()
120111
responseToDomain = mockk()
121112
domainToBody = mockk()
122113
errorMapper = mockk()
123114

124115
repo = UserRepositoryImpl(
125116
userApiService = userApiService,
126-
dispatchers = TestDispatchersImpl(testDispatcher),
117+
dispatchers = TestDispatchers(coroutineRule.testCoroutineDispatcher),
127118
responseToDomain = responseToDomain,
128119
domainToBody = domainToBody,
129120
errorMapper = errorMapper
@@ -132,9 +123,6 @@ class UserRepositoryImplTest {
132123

133124
@AfterTest
134125
fun tearDown() {
135-
testDispatcher.cleanupTestCoroutines()
136-
Dispatchers.resetMain()
137-
138126
confirmVerified(
139127
userApiService,
140128
responseToDomain,

domain/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dependencies {
88
implementation(deps.arrow.core)
99

1010
addUnitTest()
11+
testImplementation(testUtils)
1112
}

0 commit comments

Comments
 (0)