1
即使添加了包,我仍然收到空。我查看了源代碼,結果發現StubPackageManager總是返回null,並且沒有辦法覆蓋整個PackageManager類。Robolectric包管理器不會爲getNameForUid返回正確的值嗎?
即使添加了包,我仍然收到空。我查看了源代碼,結果發現StubPackageManager總是返回null,並且沒有辦法覆蓋整個PackageManager類。Robolectric包管理器不會爲getNameForUid返回正確的值嗎?
在設置:
MockPackageManager mockPackageManager = new MockPackageManager(
Robolectric.getShadowsAdapter());
RuntimeEnvironment.setRobolectricPackageManager(mockPackageManager);
子類:
class MockPackageManager extends DefaultPackageManager {
public MockPackageManager(ShadowsAdapter shadowsAdapter) {
super(shadowsAdapter);
}
@Override
public String getNameForUid(int uid) {
switch (uid) {
case UID_A:
return NAME_A;
case UID_B:
return NAME_B;
default:
return null;
}
}
@Override
public boolean isPermissionRevokedByPolicy(String s, String s1) {
return false;
}
}
酷!你還可以在Robolectric github上創建一個問題嗎? –