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

unitTesting navDirections with an Uri parameter throws NullPointerException #712

Open
tonela10 opened this issue Jan 8, 2025 · 0 comments

Comments

@tonela10
Copy link

tonela10 commented Jan 8, 2025

I am testing a class that generates destinations and return me an internal NullPointerExpection:

obtain(...) must not be null java.lang.NullPointerException: obtain(...) must not be null at com.ramcosta.composedestinations.navargs.parcelable.DefaultParcelableNavTypeSerializer.toBase64(DefaultParcelableNavTypeSerializer.kt:48) at com.ramcosta.composedestinations.navargs.parcelable.DefaultParcelableNavTypeSerializer.toRouteString(DefaultParcelableNavTypeSerializer.kt:24) at com.ramcosta.composedestinations.navargs.parcelable.DefaultParcelableNavTypeSerializer.toRouteString(DefaultParcelableNavTypeSerializer.kt:19) at com.ramcosta.composedestinations.generated.app.navtype.UriNavType.serializeValue(UriNavType.kt:41) at com.ramcosta.composedestinations.generated.app.destinations.HttpDeeplinkRedirectionScreenDestination.invoke(HttpDeeplinkRedirectionScreenDestination.kt:38) at com.ramcosta.composedestinations.generated.app.destinations.HttpDeeplinkRedirectionScreenDestination.invoke$default(HttpDeeplinkRedirectionScreenDestination.kt:32) at com.adidas.app.deeplink.Issue.test1(Issue.kt:11) at java.base/java.lang.reflect.Method.invoke(Unknown Source)

How to reproduce the error:

@Test
    fun test1() {
        val myDestination = MyScreenDestination(myUriParameter = "uri".toUri())
        myDestination.route
    }

As a workaround I have mocked the destination class as follows:

mockkObject(MyScreenDestination)
        every {
            MyScreenDestination.invoke(any(),any())
        }returns Direction("")
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