MenuItemCompat.getActionView (itemId) returns null in Robolectric

We know that Robolectric will simply keep silent, indicating zero values ​​of 0 for a call that are not implemented. And it seems that it does not handle the call method MenuItemCompat.getActionView()well. See the following snippet that is not executed using Robolectric.

SearchView searchView = (SearchView) MenuItemCompat.getActionView(
    menu.findItem(R.id.action_search));

Robolectric was unable to retrieve the SearchView object in this snippet, making the searchView variable null. Perhaps Robolectric is missing some shadow implementations here?

After debugging, I found that before the call, the android.support.v7.internal.view.menu.MenuItemImpl.getActionView()instance MenuItemImplno longer has mActionView(mActionView = null), where it is not supported.

The more I debug, the more I understand the problem. The problem is this lineShadowMenuInflater.addActionViewToItem()

String actionViewClassName = 
    attributes.getAttributeValue(ANDROID_NS, "actionViewClass");

ANDROID_NS, APP_NS, AppCompat APP_NS.

, , Robolectric , , .

GitHub

+4

Source: https://habr.com/ru/post/1545411/


All Articles