Teimatini Marin
07/29/2022, 4:27 PMChris Lee
07/29/2022, 4:28 PMval cwLogsClient = mockk<CloudWatchLogsClient>(relaxed = true)
val putLogEventsRequestSlot = slot<PutLogEventsRequest>()
every {
cwLogsClient.putLogEvents(capture(putLogEventsRequestSlot))
} answers {
PutLogEventsResponse.builder()
.nextSequenceToken(sequenceToken)
.build()
}
Teimatini Marin
08/02/2022, 3:35 PMcoEvery {
val getObjectResponseSlot = slot<GetObjectResponse>()
// s3Client.getObject(any<GetObjectRequest>(), any<suspend (GetObjectResponse) -> Unit>()) // this compiles
s3Client.getObject(any<GetObjectRequest>(), any<suspend (capture(getObjectResponseSlot)) -> Unit>()) // this does not compile
} answers {
GetObjectResponse {
eTag = "e4f682d7-eb9b-4a7c-9348-84a2704e3f86"
}
}
Thanks in advance for your help.Ondřej Šimon
08/02/2022, 6:31 PMclass TestableLambda : (GetObjectResponse) -> String {
override fun invoke(p1: GetObjectResponse): String {
TODO()
}
}
and add a unit test for this lambda class alone.
Then rewrite your additional code to use the TestableLambda
class instead of actually producing the lambda yourself when testing the read
method, while only verifying that an expected instance (using refEq
verify clause) is passed to the getObject
method.
I have not thought of any better solution.Teimatini Marin
08/03/2022, 7:47 PMOndřej Šimon
08/04/2022, 5:18 AM