feature/home-screen (Future functionality) Сovering layers with tests.

This commit is contained in:
HaliksaR 2020-11-28 00:58:41 +07:00
parent a38d7e43e2
commit 6d98c79e35
9 changed files with 233 additions and 20 deletions

View File

@ -37,6 +37,13 @@ android {
}
}
android.testOptions {
unitTests.all {
useJUnitPlatform()
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
@ -61,7 +68,10 @@ dependencies {
implementation "org.koin:koin-android-viewmodel:2.2.1"
implementation "org.koin:koin-android-ext:2.2.1"
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'io.kotest:kotest-runner-junit5:4.3.1'
testImplementation 'io.kotest:kotest-assertions-core:4.3.1'
testImplementation 'io.kotest:kotest-property:4.3.1'
testImplementation "io.mockk:mockk:1.10.2"
}

View File

@ -1,17 +0,0 @@
package com.vanced.manager.feature.home
import org.junit.Assert.assertEquals
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@ -0,0 +1,39 @@
package com.vanced.manager.feature.home.data.datasource
import com.vanced.manager.feature.home.data.api.GetAppInformationApi
import com.vanced.manager.feature.home.data.dto.*
import com.vanced.manager.feature.home.domain.entity.*
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class AppInformationDataSourceImplTest : ShouldSpec() {
private val api: GetAppInformationApi = mockk()
private val dataSource = AppInformationDataSourceImpl(api)
private val expectation = VancedApps(
VancedManager("", 1, "", ""),
YouTubeVanced("", 1, "", "", listOf(), listOf()),
YouTubeMusicVanced("", 1, "", ""),
MicroG("", 1, "", "")
)
private val verifiable = VancedAppsDto(
VancedManagerDto("", 1, "", ""),
YouTubeVancedDto("", 1, "", "", listOf(), listOf()),
YouTubeMusicVancedDto("", 1, "", ""),
MicroGDto("", 1, "", "")
)
init { // https://kotest.io/styles/
context("return information") {
should("all apps") {
coEvery { api.getAppInformation() } returns verifiable
dataSource.getAppInformation() shouldBe expectation
}
}
}
}

View File

@ -0,0 +1,51 @@
package com.vanced.manager.feature.home.data.repository
import com.vanced.manager.feature.home.data.datasource.AppInformationDataSource
import com.vanced.manager.feature.home.domain.entity.*
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class AppInformationRepositoryImplTest : ShouldSpec() {
private val dataSource: AppInformationDataSource = mockk()
private val repository = AppInformationRepositoryImpl(dataSource)
private val expectation = VancedApps(
VancedManager("", 1, "", ""),
YouTubeVanced("", 1, "", "", listOf(), listOf()),
YouTubeMusicVanced("", 1, "", ""),
MicroG("", 1, "", "")
)
init { // https://kotest.io/styles/
context("return information") {
should("all apps") {
coEvery { dataSource.getAppInformation() } returns expectation
repository.getAppInformation() shouldBe expectation
}
should("VancedManager") {
coEvery { dataSource.getAppInformation() } returns expectation
repository.getVancedManagerInformation() shouldBe expectation.vancedManager
}
should("YouTubeVanced") {
coEvery { dataSource.getAppInformation() } returns expectation
repository.getYouTubeVancedInformation() shouldBe expectation.youTubeVanced
}
should("YouTubeMusicVanced") {
coEvery { dataSource.getAppInformation() } returns expectation
repository.getYouTubeMusicVancedInformation() shouldBe expectation.youTubeMusicVanced
}
should("MicroG") {
coEvery { dataSource.getAppInformation() } returns expectation
repository.getMicroGInformation() shouldBe expectation.microG
}
}
}
}

View File

@ -0,0 +1,30 @@
package com.vanced.manager.feature.home.domain.usecase
import com.vanced.manager.feature.home.domain.entity.*
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class GetAppInformationUseCaseTest : ShouldSpec() {
private val repository: AppInformationRepository = mockk()
private val useCase = GetAppInformationUseCase(repository)
init { // https://habr.com/ru/post/520380/
should("return information all aps") {
val expectation = VancedApps(
VancedManager("", 1, "", ""),
YouTubeVanced("", 1, "", "", listOf(), listOf()),
YouTubeMusicVanced("", 1, "", ""),
MicroG("", 1, "", "")
)
coEvery { repository.getAppInformation() } returns expectation
useCase() shouldBe expectation
}
}
}

View File

@ -0,0 +1,25 @@
package com.vanced.manager.feature.home.domain.usecase
import com.vanced.manager.feature.home.domain.entity.MicroG
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class GetMicroGInformationUseCaseTest : ShouldSpec() {
private val repository: AppInformationRepository = mockk()
private val useCase = GetMicroGInformationUseCase(repository)
init { // https://github.com/mapbox/mapbox-navigation-android/blob/c5b8f6185ac1f22262664f14167da2d7ef2522e2/libnavigation-core/src/test/java/com/mapbox/navigation/core/routerefresh/RouteRefreshControllerTest.kt
should("return information MicroG") {
val expectation = MicroG("", 1, "", "")
coEvery { repository.getMicroGInformation() } returns expectation
useCase() shouldBe expectation
}
}
}

View File

@ -0,0 +1,25 @@
package com.vanced.manager.feature.home.domain.usecase
import com.vanced.manager.feature.home.domain.entity.VancedManager
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class GetVancedManagerInformationUseCaseTest : ShouldSpec() {
private val repository: AppInformationRepository = mockk()
private val useCase = GetVancedManagerInformationUseCase(repository)
init { // https://dev.to/kotest/testing-kotlin-js-with-kotest-i2j
should("return information VancedManager") {
val expectation = VancedManager("", 1, "", "")
coEvery { repository.getVancedManagerInformation() } returns expectation
useCase() shouldBe expectation
}
}
}

View File

@ -0,0 +1,25 @@
package com.vanced.manager.feature.home.domain.usecase
import com.vanced.manager.feature.home.domain.entity.YouTubeMusicVanced
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class GetYouTubeMusicVancedInformationUseCaseTest : ShouldSpec() {
private val repository: AppInformationRepository = mockk()
private val useCase = GetYouTubeMusicVancedInformationUseCase(repository)
init {
should("return information YouTubeMusicVanced") {
val expectation = YouTubeMusicVanced("", 1, "", "")
coEvery { repository.getYouTubeMusicVancedInformation() } returns expectation
useCase() shouldBe expectation
}
}
}

View File

@ -0,0 +1,25 @@
package com.vanced.manager.feature.home.domain.usecase
import com.vanced.manager.feature.home.domain.entity.YouTubeVanced
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
internal class GetYouTubeVancedInformationUseCaseTest : ShouldSpec() {
private val repository: AppInformationRepository = mockk()
private val useCase = GetYouTubeVancedInformationUseCase(repository)
init {
should("return information YouTubeVanced") {
val expectation = YouTubeVanced("", 1, "", "", listOf(), listOf())
coEvery { repository.getYouTubeVancedInformation() } returns expectation
useCase() shouldBe expectation
}
}
}