Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java 17, the spyK(map) does not work. #1126

Open
lannyf77 opened this issue Jul 28, 2023 · 0 comments
Open

java 17, the spyK(map) does not work. #1126

lannyf77 opened this issue Jul 28, 2023 · 0 comments

Comments

@lannyf77
Copy link

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)

}
using 
mockk 1.13.5
robolectric 4.10.2
java 17

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant