JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

Robolectric test application setup throws IllegalArgumentException, loading same font twice #114

Closed andrewsardone closed 9 years ago

andrewsardone commented 9 years ago

This is more of a question / out-loud-thinking to see if anyone has come across this issue, or if anyone sees any obvious mistakes I have made.

I have a simple android.app.Application subclass which registers my Iconify modules within the onCreate() implementation (per the README instructions). Everything works and runs fine in a normal context, but all of my JUnit tests (ran with Robolectric) are throwing exceptions:

Caused by: java.lang.IllegalArgumentException: Can't add twice the same font "iconify/android-iconify-fontawesome.ttf"
    at com.joanzapata.iconify.Iconify.addIconFontDescriptor(Iconify.java:45)
    at com.joanzapata.iconify.Iconify.access$000(Iconify.java:11)
    at com.joanzapata.iconify.Iconify$IconifyInitializer.<init>(Iconify.java:68)
    at com.joanzapata.iconify.Iconify.with(Iconify.java:22)
    at com.example.FooApplication.onCreate(FooApplication.java:51)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    ... 35 more

Has anyone come across this? Any ideas on how to fix the issue? Apologies for the lack of details; just not sure where to go next. Thanks!

andrewsardone commented 9 years ago

It's far from a solution, but my current hack is to key off of a static flag for whether or not we've loaded the module :shame:

JoanZapata commented 9 years ago

Oh.

I throw this exception to prevent people from initializing Iconify in every activity instead of just once in the application. I didn't think about tests instantiating multiple applications. I'll change this behavior in the next release, adding twice the same font would do.. well, nothing.

JoanZapata commented 9 years ago

Fixed in 2.0.9 released just now.