Skip to content

Update test and split core #58

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 7 commits into from
Nov 6, 2021
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ master ]

env:
CI: true

jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/review-suggest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: reviewdog-suggester
on:
pull_request:
types: [opened, synchronize, reopened]

env:
CI: true

jobs:
kotlin:
name: runner / suggester / spotless
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ master ]

env:
CI: true

jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .idea/gradle.xml

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

1 change: 1 addition & 0 deletions .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 @@ -59,6 +59,7 @@ dependencies {
implementation(domain)
implementation(data)
implementation(core)
implementation(coreUi)
implementation(featureMain)
implementation(featureAdd)
implementation(featureSearch)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hoc/flowmvi/core/CoreModule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hoc.flowmvi.core

import com.hoc.flowmvi.core.dispatchers.CoroutineDispatchers
import com.hoc.flowmvi.core.navigator.Navigator
import com.hoc.flowmvi.core_ui.navigator.Navigator
import org.koin.dsl.module

val coreModule = module {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hoc/flowmvi/core/NavigatorImpl.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.hoc.flowmvi.core

import android.content.Context
import com.hoc.flowmvi.core.navigator.IntentProviders
import com.hoc.flowmvi.core.navigator.Navigator
import com.hoc.flowmvi.core_ui.navigator.IntentProviders
import com.hoc.flowmvi.core_ui.navigator.Navigator

class NavigatorImpl(
private val add: IntentProviders.Add,
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@file:Suppress("unused", "ClassName", "SpellCheckingInspection")

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

inline val DependencyHandler.domain get() = project(":domain")
inline val DependencyHandler.core get() = project(":core")
inline val DependencyHandler.coreUi get() = project(":core-ui")
inline val DependencyHandler.data get() = project(":data")
inline val DependencyHandler.featureMain get() = project(":feature-main")
inline val DependencyHandler.featureAdd get() = project(":feature-add")
inline val DependencyHandler.featureSearch get() = project(":feature-search")
inline val DependencyHandler.mviBase get() = project(":mvi-base")
inline val DependencyHandler.mviTesting get() = project(":mvi-testing")
inline val DependencyHandler.testUtils get() = project(":test-utils")

fun DependencyHandler.addUnitTest(testImplementation: Boolean = true) {
val configName = if (testImplementation) "testImplementation" else "implementation"
Expand All @@ -112,3 +115,8 @@ fun DependencyHandler.addUnitTest(testImplementation: Boolean = true) {
add(configName, deps.test.kotlinJUnit)
add(configName, deps.coroutines.test)
}

val Project.isCiBuild: Boolean
get() = providers.environmentVariable("CI")
.forUseAtConfigurationTime()
.orNull == "true"
1 change: 1 addition & 0 deletions core-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions core-ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
androidLib
kotlinAndroid
}

android {
compileSdk = appConfig.compileSdkVersion
buildToolsVersion = appConfig.buildToolsVersion

defaultConfig {
minSdk = appConfig.minSdkVersion
targetSdk = appConfig.targetSdkVersion

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }

testOptions {
unitTests.isIncludeAndroidResources = true
unitTests.isReturnDefaultValues = true
}
}

dependencies {
implementation(deps.coroutines.core)
implementation(deps.coroutines.android)

implementation(deps.androidx.coreKtx)
implementation(deps.androidx.swipeRefreshLayout)
implementation(deps.androidx.recyclerView)
implementation(deps.androidx.material)

implementation(deps.lifecycle.commonJava8)
implementation(deps.lifecycle.runtimeKtx)

implementation(deps.timber)

addUnitTest()
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.hoc.flowmvi.core_ui
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hoc.flowmvi.core">
package="com.hoc.flowmvi.core_ui">

<application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hoc.flowmvi.core
package com.hoc.flowmvi.core_ui

import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hoc.flowmvi.core
package com.hoc.flowmvi.core_ui

import android.content.Context
import android.os.Looper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hoc.flowmvi.core
package com.hoc.flowmvi.core_ui

import android.content.Context
import android.graphics.Canvas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hoc.flowmvi.core.navigator
package com.hoc.flowmvi.core_ui.navigator

import android.content.Context
import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.hoc.flowmvi.core_ui
49 changes: 1 addition & 48 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
plugins {
androidLib
kotlinAndroid
}

android {
compileSdk = appConfig.compileSdkVersion
buildToolsVersion = appConfig.buildToolsVersion

defaultConfig {
minSdk = appConfig.minSdkVersion
targetSdk = appConfig.targetSdkVersion

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }

testOptions {
unitTests.isIncludeAndroidResources = true
unitTests.isReturnDefaultValues = true
}
kotlin
}

dependencies {
implementation(deps.coroutines.core)
implementation(deps.coroutines.android)

implementation(deps.androidx.coreKtx)
implementation(deps.androidx.swipeRefreshLayout)
implementation(deps.androidx.recyclerView)
implementation(deps.androidx.material)

implementation(deps.lifecycle.commonJava8)
implementation(deps.lifecycle.runtimeKtx)

implementation(deps.timber)

addUnitTest()
}

This file was deleted.

3 changes: 2 additions & 1 deletion data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {

buildTypes {
release {
isMinifyEnabled = true
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down Expand Up @@ -55,4 +55,5 @@ dependencies {
implementation(deps.timber)

addUnitTest()
testImplementation(testUtils)
}
26 changes: 7 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 @@ -4,12 +4,13 @@ import arrow.core.Either
import arrow.core.getOrHandle
import arrow.core.identity
import com.hoc.flowmvi.core.Mapper
import com.hoc.flowmvi.core.dispatchers.CoroutineDispatchers
import com.hoc.flowmvi.data.remote.UserApiService
import com.hoc.flowmvi.data.remote.UserBody
import com.hoc.flowmvi.data.remote.UserResponse
import com.hoc.flowmvi.domain.entity.User
import com.hoc.flowmvi.domain.repository.UserError
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
import com.hoc.flowmvi.test_utils.TestDispatchers
import io.mockk.clearAllMocks
import io.mockk.coEvery
import io.mockk.coVerify
Expand All @@ -19,17 +20,13 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import io.mockk.verifySequence
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.setMain
import org.junit.Rule
import java.io.IOException
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -95,16 +92,12 @@ private val USERS = listOf(
),
)

@ExperimentalCoroutinesApi
class TestDispatchersImpl(testDispatcher: TestCoroutineDispatcher) : CoroutineDispatchers {
override val main: CoroutineDispatcher = testDispatcher
override val io: CoroutineDispatcher = testDispatcher
}

@ExperimentalCoroutinesApi
@ExperimentalTime
class UserRepositoryImplTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutineRule = TestCoroutineDispatcherRule()
private val testDispatcher get() = coroutineRule.testCoroutineDispatcher

private lateinit var repo: UserRepositoryImpl
private lateinit var userApiService: UserApiService
Expand All @@ -114,16 +107,14 @@ class UserRepositoryImplTest {

@BeforeTest
fun setup() {
Dispatchers.setMain(testDispatcher)

userApiService = mockk()
responseToDomain = mockk()
domainToBody = mockk()
errorMapper = mockk()

repo = UserRepositoryImpl(
userApiService = userApiService,
dispatchers = TestDispatchersImpl(testDispatcher),
dispatchers = TestDispatchers(coroutineRule.testCoroutineDispatcher),
responseToDomain = responseToDomain,
domainToBody = domainToBody,
errorMapper = errorMapper
Expand All @@ -132,9 +123,6 @@ class UserRepositoryImplTest {

@AfterTest
fun tearDown() {
testDispatcher.cleanupTestCoroutines()
Dispatchers.resetMain()

confirmVerified(
userApiService,
responseToDomain,
Expand Down
1 change: 1 addition & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies {
implementation(deps.arrow.core)

addUnitTest()
testImplementation(testUtils)
}
Loading