Skip to content
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

Add examples #4

Merged
merged 2 commits into from
Feb 11, 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
165 changes: 165 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved.
*
* Use of this source code is governed by Apache v2.0
*/

import tech.antibytes.gradle.dependency.Dependency
import tech.antibytes.gradle.kmock.config.KMockConfiguration
import tech.antibytes.gradle.kmock.dependency.Dependency as LocalDependency

plugins {
id("org.jetbrains.kotlin.multiplatform")

// Android
id("com.android.library")

id("tech.antibytes.gradle.configuration")
id("tech.antibytes.gradle.coverage")
}

group = KMockConfiguration.group

kotlin {
android()

js(IR) {
nodejs()
browser()
}

jvm()

ios()

linuxX64()

sourceSets {
val commonMain by getting {
dependencies {
implementation(Dependency.multiplatform.kotlin.common)
implementation(Dependency.multiplatform.coroutines.common)
implementation(Dependency.multiplatform.stately.isolate)
implementation(Dependency.multiplatform.stately.concurrency)

implementation(LocalDependency.antibytes.test.core)
}
}
val commonTest by getting {
dependencies {
implementation(Dependency.multiplatform.test.common)
implementation(Dependency.multiplatform.test.annotations)

implementation(LocalDependency.antibytes.test.annotations)
implementation(LocalDependency.antibytes.test.coroutine)
implementation(LocalDependency.antibytes.test.fixture)

api(project(":kmock"))
}
}

val androidMain by getting {
dependencies {
dependsOn(commonMain)
implementation(Dependency.multiplatform.kotlin.android)
}
}
val androidTest by getting {
dependencies {
dependsOn(commonTest)

implementation(Dependency.multiplatform.test.jvm)
implementation(Dependency.multiplatform.test.junit)
implementation(Dependency.android.test.robolectric)
}
}

val jsMain by getting {
dependencies {
dependsOn(commonMain)
implementation(Dependency.multiplatform.kotlin.js)
implementation(Dependency.js.nodejs)
}
}
val jsTest by getting {
dependencies {
dependsOn(commonTest)

implementation(Dependency.multiplatform.test.js)
}
}

val jvmMain by getting {
dependencies {
dependsOn(commonMain)
implementation(Dependency.multiplatform.kotlin.jdk8)
}
}
val jvmTest by getting {
dependencies {
dependsOn(commonTest)

implementation(Dependency.multiplatform.test.jvm)
implementation(Dependency.multiplatform.test.junit)
}
}

val nativeMain by creating {
dependencies {
dependsOn(commonMain)
}
}

val nativeTest by creating {
dependencies {
dependsOn(commonTest)
}
}

val darwinMain by creating {
dependencies {
dependsOn(nativeMain)
}
}
val darwinTest by creating {
dependencies {
dependsOn(nativeTest)
}
}

val otherMain by creating {
dependencies {
dependsOn(nativeMain)
}
}

val otherTest by creating {
dependencies {
dependsOn(nativeTest)
}
}

val linuxX64Main by getting {
dependencies {
dependsOn(otherMain)
}
}

val linuxX64Test by getting {
dependencies {
dependsOn(otherTest)
}
}

val iosMain by getting {
dependencies {
dependsOn(darwinMain)
}
}
val iosTest by getting {
dependencies {
dependsOn(darwinTest)
}
}
}
}
7 changes: 7 additions & 0 deletions examples/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
~ Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved.
~
~ Use of this source code is governed by Apache v2.0
-->

<manifest package="tech.antibytes.kmock.example" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved.
*
* Use of this source code is governed by Apache v2.0
*/

package tech.antibytes.kmock.example

import kotlinx.coroutines.flow.SharedFlow

interface ExampleContract {
interface SampleDomainObject {
var id: String
val value: Int
}

interface SampleRemoteRepository {
suspend fun fetch(url: String): SampleDomainObject
fun find(id: String): SampleDomainObject
}

interface SampleLocalRepository {
suspend fun store(id: String, value: Int): SampleDomainObject
fun contains(id: String): Boolean
fun fetch(id: String): SampleDomainObject
}

interface SampleController {
suspend fun fetchAndStore(url: String): SampleDomainObject
fun find(id: String): SharedFlow<SampleDomainObject>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved.
*
* Use of this source code is governed by Apache v2.0
*/

package tech.antibytes.kmock.example

import co.touchlab.stately.concurrency.AtomicReference
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch

class SampleController(
private val localRepository: ExampleContract.SampleLocalRepository,
private val remoteRepository: ExampleContract.SampleRemoteRepository
) : ExampleContract.SampleController {
override suspend fun fetchAndStore(url: String): ExampleContract.SampleDomainObject {
val domainObject = remoteRepository.fetch(url)
domainObject.id
domainObject.id = "42"

return localRepository.store(domainObject.id, domainObject.value)
}

override fun find(id: String): SharedFlow<ExampleContract.SampleDomainObject> {
val ref = AtomicReference(id)
val flow = MutableSharedFlow<ExampleContract.SampleDomainObject>()

CoroutineScope(Dispatchers.Default).launch {
localRepository.contains(ref.get())

val objc = remoteRepository.find(ref.get())

localRepository.fetch(objc.id)

objc.id = "23"

flow.emit(objc)
}

return flow
}
}
Loading