Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

setPackageManager doesn't work for an activity. #351

Closed
nstoertz opened this Issue · 3 comments

4 participants

nstoertz Advait Shinde Herval Freire Christian Williams
nstoertz

Code like this fails:
Robolectric.shadowOf(activity).setPackageManager(mockManager);
assertEquals(mockManager, activity.getPackageManager())

It looks like this is because ShadowContextWrapper#getPackageManager doesn't return the overridden package manager unless the context is the application context.

@Implementation
public PackageManager getPackageManager() {
    return realContextWrapper == getApplicationContext() ? packageManager getApplicationContext().getPackageManager();
}

d5a92b7

A workaround is to set the package manager on the application, but it seems like getPackageManager should always return the packageManager if it has been set. If that isn't possible, maybe ShadowActivity should override setPackageManager and warn that setPackageManager should be called on the application.

Advait Shinde

+1

Herval Freire

I've fixed this here: herval@b9b1e6f
making a pull request...

Christian Williams
Owner

Things have changed pretty significantly with 2.0, this may no longer be relevant. Please reopen if it is, though. Thanks!

Christian Williams xian closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.