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

fix(Android): failure when faking sealed classes #92

Merged

Conversation

vitorhugods
Copy link
Contributor

Fixes:

Issue

When running Android Instrumented tests with parameters that are sealed classes on Android or in older JVMs, a NullPointerException is thrown.

How to reproduce

  1. Run an Android emulator or connect a physical Android device
  2. ./gradlew :shared:connectedDebugAndroidTest

Cause

When running on Android or in older JVMs, the JVM functions Class$isSealed and Class$getPermittedSubclasses do not exist, so the sealed class will fall onto the abstract case in makeValueOf.

Solution

Use Kotlin Reflect to read the Kotlin metadata from the class instead of trying to just use these functions that may not exist during runtime.


Known issue

While investigating this, I also noticed that the test ValueOfTests.makeValueOfReturnsOtherStuff fails when trying to get valueOf<AbstractParameter>(). I've created #91 to handle the abstract class case.

Co-authored-by: Alexandre Ferris <ferris.alexandre@gmail.com>
mockative/build.gradle.kts Outdated Show resolved Hide resolved
@Nillerr Nillerr merged commit 8a8cefb into mockative:main Apr 14, 2024
1 check passed
@vitorhugods vitorhugods deleted the fix/sealed-class-faking-on-android branch April 14, 2024 10:28
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

Successfully merging this pull request may close these issues.

None yet

2 participants