Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


setPackageManager doesn't work for an activity. #351

nstoertz opened this Issue · 3 comments

4 participants


Code like this fails:
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.

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


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.




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


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

@xian 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.