Mario Adam
05/22/2023, 1:06 PMabstract class DataStateUseCase<in Params, ReturnType> where ReturnType : Any? {
abstract suspend fun FlowCollector<DataState<ReturnType>>.execute(params: Params)
suspend operator fun invoke(params: Params) = flow {
execute(params)
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
}
I want the execute
method to be visible for testing - and so I tried to annotate it with @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
. Yet in my test code I cannot access the method (same package, same project). Why is that? Is it even possible?Sam
05/22/2023, 1:12 PM@VisibleForTesting
doesn’t change that, it just documents it. I think your issue is probably not due to visibility, but rather due to the function having multiple receivers. Do you have an example of how you’re trying to call the function?Mario Adam
05/22/2023, 1:15 PMsut.login(…)
in my IDE it doesn’t provide this method.Mario Adam
05/22/2023, 1:17 PMFlowCollector
Sam
05/22/2023, 1:18 PMFlowCollector
) to be in receiver position (either explicit or implicit). That means that the dispatch receiver (the DataStateUseCase
) needs to be brought into scope using with
(or as a context receiver). E.g.
flow {
with(useCase) {
execute(...)
}
}
Mario Adam
05/22/2023, 1:20 PMcoVerify
- from MockK)Sam
05/22/2023, 1:25 PMcoVerify {
with(useCase) {
any<FlowCollector<...>>().execute(...)
}
}
Sam
05/22/2023, 1:25 PMMario Adam
05/22/2023, 1:38 PMMario Adam
05/22/2023, 2:05 PMcollect
things first to trigger the flow