This is a Kotlin-Mockk based testcase, where I am trying to get the static class "UUID" to be mocked.
this works when used to get random string but not UUID
mockkStatic(UUID::class) every { UUID.randomUUID().toString() } returnsMany uuidSource
//This is the uuid source
val uuidSource = listOf(
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString()
)
In the below case it works
@Test
fun x1() {
mockkStatic(UUID::class)
every { UUID.randomUUID().toString() } returnsMany uuidSource
listOf(1, 2, 3). forEach { _ ->
println(UUID.randomUUID().toString())
}
}
//But in the below case it does give error
Unable to make private static long java.util.UUID.parse4Nibbles(java.lang.String,int) accessible: module java.base does not "opens java.util" to unnamed module @2aae9190
@Test fun x1() {
mockkStatic(UUID::class) every { UUID.randomUUID().toString() } returnsMany uuidSource
listOf(1, 2, 3). forEach { _ ->
println(UUID.randomUUID())
}
}
Any solution for the second case to work, or any workaround?