chore: core 多模块骨架
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.mingyuan.android_client.core.domain
|
||||
|
||||
/**
|
||||
* Base contract for a single-action use case.
|
||||
*
|
||||
* Keeping use cases as plain interfaces with a `suspend operator invoke` keeps domain logic
|
||||
* framework-agnostic and trivially testable on the JVM (see [com.mingyuan.android_client.core.domain.UseCaseTest]).
|
||||
*/
|
||||
interface UseCase<in Input, out Output> {
|
||||
suspend operator fun invoke(input: Input): Output
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mingyuan.android_client.core.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class UseCaseTest {
|
||||
|
||||
@Test
|
||||
fun `invoke delegates to the implementation`() = runTest {
|
||||
val double = object : UseCase<Int, Int> {
|
||||
override suspend fun invoke(input: Int): Int = input * 2
|
||||
}
|
||||
|
||||
assertThat(double(21)).isEqualTo(42)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user