nirazo
02/25/2021, 10:11 AMexecute
method from APP to get value.
The return values from UseCases are defined as Results, and puts it in Output of UseCase, and returns it to my APP.
Define of Results:
sealed class Results<out T, out S> {
class Success<out T>(val data: T) : Results<T, Nothing>()
class Failure<out S>(val cause: S) : Results<Nothing, S>()
}
Sample useCase and it’s IO:
interface SampleUseCaseInterface {
suspend fun execute(): sampleUseCaseIO.Output
}
class sampleUseCase() : SampleUseCaseInterface {
override suspend fun execute(): sampleUseCaseIO.Output =
sampleUseCaseIO.Output(Results.Success("success!"))
}
class sampleUseCaseIO {
data class Output(val results: Results<String, Error>)
}
Now, I want to mock the execute method of UseCase and return an arbitrary Output in order to write a Unit Test in an iOS app.
However, now the following error is displayed and it is not possible to create an arbitrary output.
Both data and error are required to be included in Results, and the required Output cannot be created.
Is there any way to avoid this?
Also, is it possible to realize a mechanism like Either on the iOS side with Kotlin/Native?edrd
02/25/2021, 9:41 PMnirazo
02/26/2021, 1:54 AM