moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

ResourceFormatted cause unit tests failure

Open ptsiogas opened this issue 3 years ago • 2 comments

Let's say we have a method (lets call it "A") that calls the StringDesc.ResourceFormatted(stringRes, *args) method inside. If I write a unit test for this method ("A") it is passing with success when running it from Android Studio but it fails when I run it from terminal. If I change the call to StringDesc.Resource(stringRes) it succeeds everywhere. I am referring to common unit test.

Example method that fails:

fun getKmmString(stringRes: StringResource, vararg args: Any): StringDesc {
        return StringDesc.ResourceFormatted(stringRes, *args)
}

Example method that succeeds:

fun getKmmString(stringRes: StringResource, vararg args: Any): StringDesc {
    return StringDesc.Resource(stringRes)
}

ptsiogas avatar Feb 07 '22 09:02 ptsiogas

@Alex009 hi there, in order to help, I have noticed that the difference between the StringDesc.Resource (that works fine) and the StringDesc.ResourceFormatted is that it's root class is Parcelize and implements Parcelable. I am not sure if this is the root cause though.

ptsiogas avatar Feb 08 '22 10:02 ptsiogas

@ptsiogas good point. i think it make sense. maybe we should extract parcelable logic in separated holder. it's not widely used feature as i think

Alex009 avatar Feb 08 '22 13:02 Alex009

I would like to have ResourceFormattedStringDesc available for @Parcelize. Currently it inherits only from StringDesc and not Parcelable. There is a diference ResourceStringDesc that inherits from Parcelable and is ready for @Parcelize

We are using this to pass ResourceFormattedStringDesc between navigation destinations and it requires us to make a workaround. Just leaving this here. :) Let me know if I should create another issue, or not. Thanks

amirplaza avatar Dec 08 '22 20:12 amirplaza