0

android project, having some unit test working fine until updated to java 17. Here is a simplified test to show that the spyk(HashMap()) gets error

@Test
fun test_() {
        val metaMapSpy: MutableMap<String, String> = spyk(HashMap())
        every { metaMapSpy[any()] } returns null
        val ret = metaMapSpy["mLS"];
        assertEquals("should return null", null, ret)

}


class io.mockk.impl.InternalPlatform cannot access a member of class java.util.HashMap (in module java.base) with modifiers "transient"
java.lang.IllegalAccessException: class io.mockk.impl.InternalPlatform cannot access a member of class java.util.HashMap (in module java.base) with modifiers "transient"
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Field.checkAccess(Field.java:1102)
    at java.base/java.lang.reflect.Field.get(Field.java:423)
    at io.mockk.impl.InternalPlatform.copyFields$copy(InternalPlatform.kt:114)
    at io.mockk.impl.InternalPlatform.copyFields(InternalPlatform.kt:121)
    at io.mockk.impl.instantiation.AbstractMockFactory.spyk(AbstractMockFactory.kt:107)

with java 17, how to use mockk.spyK to mock a map?

lannyf
  • 9,865
  • 12
  • 70
  • 152

0 Answers0