I'm trying to test the method getSongsList
class SongsRemoteDataSource @Inject constructor(
private val resultParser: ResultParser,
private val songsService: SongsService
) {
suspend fun getSongsList(query: String): Result<SongsResponse> =
resultParser.parse { songsService.getSongsList(query) }
}
Basically I'm trying to test that the mock was called with the correct lambda as argument
class SongsRemoteDataSourceTest {
@RelaxedMockK
private lateinit var resultParser: ResultParser
@RelaxedMockK
private lateinit var songsService: SongsService
private lateinit var songsRemoteDataSource: SongsRemoteDataSource
@Before
fun setUp() {
MockKAnnotations.init(this)
songsRemoteDataSource = SongsRemoteDataSource(resultParser, songsService)
}
@Test
fun getSongsList() = runBlockingTest {
val query = "query"
songsRemoteDataSource.getSongsList(query)
coVerify { resultParser.parse { songsService.getSongsList(query) } }
}
}
But the test fails
java.lang.AssertionError: Verification failed: call 1 of 1: ResultParser(resultParser#1).parse(eq(continuation {}), any())). Only one matching call to ResultParser(resultParser#1)/parse(Function1, Continuation) happened, but arguments are not matching:
[0]: argument: continuation {}, matcher: eq(continuation {}), result: -
[1]: argument: continuation {}, matcher: any(), result: +
ResultParser
class ResultParser @Inject constructor() {
suspend fun <T> parse(call: suspend () -> Response<T>): Result<T> {
...
}
}
SongsService
interface SongsService {
@GET("search")
suspend fun getSongsList(
@Query("term") query: String,
@Query("mediaType") mediaType: String = "music"
): Response<SongsResponse>
}
I can't understand why it fails. What am I doing wrong?