If one does an assertEquals() for drawables, an assertion failure, drawables don't match is returned.
This is working in 3.8, but 4.0 onwards has stopped working.
Write a robolectric test, and test drawables like this:
assertEquals(activity.findViewById<ImageView>(R.id.imageOne).background, ContextCompat.getDrawable(mainActivity.baseContext,
R.drawable.ic_launcher_foreground))
Robolectric version: 4.0-beta-1, 4.0-beta-2-SNAPSHOT
Android version: 28
Older versions of Robolectric modified the behavior of Drawable.equals() (which Android leaves undefined, so it returns true only for identity-equal objects). In Robolectric 4.0, we try to match real Android behavior as closely as possible, so this special case has been removed.
Equivalent code that should work:
assertThat(shadowOf(drawable).getCreatedFromResId())
.isEqualTo(shadowOf(expectedDrawable).getCreatedFromResId());
Older versions of Robolectric modified the behavior of
Drawable.equals()(which Android leaves undefined, so it returns true only for identity-equal objects). In Robolectric 4.0, we try to match real Android behavior as closely as possible, so this special case has been removed.Equivalent code that should work:
assertThat(shadowOf(drawable).getCreatedFromResId()) .isEqualTo(shadowOf(expectedDrawable).getCreatedFromResId());
Thanks! Exactly what I needed!
Most helpful comment
Older versions of Robolectric modified the behavior of
Drawable.equals()(which Android leaves undefined, so it returns true only for identity-equal objects). In Robolectric 4.0, we try to match real Android behavior as closely as possible, so this special case has been removed.Equivalent code that should work: